-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - Add support of extendsInfolist hook (#1531)
This PR add support of extendsInfolist hook and fix headerWidget / FooterWidget not triggered on abstract BaseViewRecord --------- Co-authored-by: Glenn Jacobs <[email protected]>
- Loading branch information
1 parent
e34842d
commit 73ec6f9
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/admin/src/Support/Pages/Concerns/ExtendsInfolist.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Lunar\Admin\Support\Pages\Concerns; | ||
|
||
use Filament\Infolists\Infolist; | ||
|
||
trait ExtendsInfolist | ||
{ | ||
public function infolist(Infolist $infolist): Infolist | ||
{ | ||
return self::callLunarHook('extendsInfolist', $this->getDefaultInfolist($infolist)); | ||
} | ||
|
||
protected function getDefaultInfolist(Infolist $infolist): Infolist | ||
{ | ||
return $infolist; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
tests/admin/Feature/Support/Extending/ViewPageExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
use Filament\Infolists\Infolist; | ||
use Illuminate\Support\Str; | ||
use Lunar\Admin\Filament\Resources\OrderResource\Pages\ManageOrder; | ||
use Lunar\Admin\Support\Facades\LunarPanel; | ||
|
||
uses(\Lunar\Tests\Admin\Feature\Filament\TestCase::class) | ||
->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'); | ||
}); |