diff --git a/docs/admin/extending/pages.md b/docs/admin/extending/pages.md index 7cbf415194..d4ca2b7b4c 100644 --- a/docs/admin/extending/pages.md +++ b/docs/admin/extending/pages.md @@ -268,10 +268,26 @@ An example of extending a view page. ```php use Filament\Actions; + +use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Table; +use Filament\Infolists\Infolist; +use Filament\Infolists\Components\TextEntry; use Lunar\Admin\Support\Extending\ViewPageExtension; +use Lunar\Admin\Filament\Widgets; class MyViewExtension extends ViewPageExtension { + public function headerWidgets(array $widgets): array + { + $widgets = [ + ...$widgets, + Widgets\Dashboard\Orders\OrderStatsOverview::make(), + ]; + + return $widgets; + } + public function heading($title): string { return $title . ' - Example'; @@ -293,7 +309,24 @@ class MyViewExtension extends ViewPageExtension return $actions; } - + + public function extendsInfolist(Infolist $infolist): Infolist + { + return $infolist->schema([ + ...$infolist->getComponents(true), + TextEntry::make('custom_title'), + ]); + } + + public function footerWidgets(array $widgets): array + { + $widgets = [ + ...$widgets, + Widgets\Dashboard\Orders\LatestOrdersTable::make(), + ]; + + return $widgets; + } } // Typically placed in your AppServiceProvider file... diff --git a/packages/admin/src/Filament/Resources/OrderResource/Pages/ManageOrder.php b/packages/admin/src/Filament/Resources/OrderResource/Pages/ManageOrder.php index 71a05cd7b7..842ed18475 100644 --- a/packages/admin/src/Filament/Resources/OrderResource/Pages/ManageOrder.php +++ b/packages/admin/src/Filament/Resources/OrderResource/Pages/ManageOrder.php @@ -284,7 +284,7 @@ public static function getOrderSummaryInfolist(): Infolists\Components\Component ]); } - public function infolist(Infolist $infolist): Infolist + public function getDefaultInfolist(Infolist $infolist): Infolist { return $infolist ->schema([ diff --git a/packages/admin/src/Support/Pages/BaseViewRecord.php b/packages/admin/src/Support/Pages/BaseViewRecord.php index da805130aa..725ad6bbe8 100644 --- a/packages/admin/src/Support/Pages/BaseViewRecord.php +++ b/packages/admin/src/Support/Pages/BaseViewRecord.php @@ -6,8 +6,11 @@ abstract class BaseViewRecord extends ViewRecord { + use Concerns\ExtendsFooterWidgets; use Concerns\ExtendsHeaderActions; use Concerns\ExtendsHeaderWidgets; use Concerns\ExtendsHeadings; + use Concerns\ExtendsInfolist; + use \Lunar\Admin\Support\Concerns\CallsHooks; use \Lunar\Admin\Support\Concerns\CallsHooks; } diff --git a/packages/admin/src/Support/Pages/Concerns/ExtendsInfolist.php b/packages/admin/src/Support/Pages/Concerns/ExtendsInfolist.php new file mode 100644 index 0000000000..25d91e971e --- /dev/null +++ b/packages/admin/src/Support/Pages/Concerns/ExtendsInfolist.php @@ -0,0 +1,18 @@ +getDefaultInfolist($infolist)); + } + + protected function getDefaultInfolist(Infolist $infolist): Infolist + { + return $infolist; + } +} diff --git a/tests/admin/Feature/Support/Extending/ViewPageExtension.php b/tests/admin/Feature/Support/Extending/ViewPageExtension.php new file mode 100644 index 0000000000..4a531d9037 --- /dev/null +++ b/tests/admin/Feature/Support/Extending/ViewPageExtension.php @@ -0,0 +1,59 @@ +group('extending.view'); + +beforeEach(function () { + $this->asStaff(); + + $currency = \Lunar\Models\Currency::factory()->create([ + 'default' => true, + ]); + + $country = \Lunar\Models\Country::factory()->create(); + + $this->order = \Lunar\Models\Order::factory() + ->for(\Lunar\Models\Customer::factory()) + ->has(\Lunar\Models\OrderAddress::factory()->state([ + 'type' => 'shipping', + 'country_id' => $country->id, + ]), 'shippingAddress') + ->has(\Lunar\Models\OrderAddress::factory()->state([ + 'type' => 'billing', + 'country_id' => $country->id, + ]), 'billingAddress') + ->create([ + 'currency_code' => $currency->code, + 'meta' => [ + 'additional_info' => Str::random(), + ], + ]); + +}); + +it('can extend Infolist', function () { + $class = new class extends \Lunar\Admin\Support\Extending\ViewPageExtension + { + public function extendsInfolist(Infolist $infolist): Infolist + { + return $infolist->schema([ + ...$infolist->getComponents(true), + \Filament\Infolists\Components\TextEntry::make('custom_title') + ->label('custom_title'), + ]); + } + }; + + LunarPanel::registerExtension($class, ManageOrder::class); + + \Livewire\Livewire::test(ManageOrder::class, [ + 'record' => $this->order->getRouteKey(), + ]) + ->assertSee($this->order->reference) + ->assertSee('custom_title'); +});