From 3e78ffe4e0ae2194e4f1bb5d0a3cd4ae17f2b63b Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Fri, 27 Oct 2023 15:23:31 +0100 Subject: [PATCH] wip --- .../docs/03-resources/07-relation-managers.md | 17 ++++----------- .../resources/relation-managers.blade.php | 6 +++--- .../RelationManagers/RelationManager.php | 21 +++++++++++++++++++ .../views/components/widgets.blade.php | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/panels/docs/03-resources/07-relation-managers.md b/packages/panels/docs/03-resources/07-relation-managers.md index acb7c192de..7f01ad0c3d 100644 --- a/packages/panels/docs/03-resources/07-relation-managers.md +++ b/packages/panels/docs/03-resources/07-relation-managers.md @@ -778,19 +778,10 @@ Now, you can access the `status` in the relation manager class using `$this->sta ## Disabling lazy loading -By default, relation managers are lazy-loaded. This means that they will only be loaded when they are visible on the page. +By default, relation managers are lazy-loaded. This means that they will only be loaded when they are visible on the page. -You can disable this behavior, using the `make()` method: +To disable this behavior, you may override the `$isLazy` property on the relation manager class: ```php -use App\Filament\Resources\Blog\PostResource\RelationManagers\CommentsRelationManager; - -public static function getRelations(): array -{ - return [ - CommentsRelationManager::make([ - 'lazy' => false, - ]), - ]; -} -``` \ No newline at end of file +protected static bool $isLazy = false; +``` diff --git a/packages/panels/resources/views/components/resources/relation-managers.blade.php b/packages/panels/resources/views/components/resources/relation-managers.blade.php index b45f4299ea..77dbbdbad4 100644 --- a/packages/panels/resources/views/components/resources/relation-managers.blade.php +++ b/packages/panels/resources/views/components/resources/relation-managers.blade.php @@ -71,7 +71,7 @@ class="flex flex-col gap-y-4" > @php - $managerLivewireProperties = ['lazy' => true, 'ownerRecord' => $ownerRecord, 'pageClass' => $pageClass]; + $managerLivewireProperties = ['ownerRecord' => $ownerRecord, 'pageClass' => $pageClass]; if (filled($activeLocale)) { $managerLivewireProperties['activeLocale'] = $activeLocale; @@ -86,7 +86,7 @@ @livewire( $normalizedGroupedManagerClass, - [...$managerLivewireProperties, ...(($groupedManager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? $groupedManager->properties : [])], + [...$managerLivewireProperties, ...(($groupedManager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? [...$groupedManager->relationManager::getDefaultProperties(), ...$groupedManager->properties] : $groupedManager::getDefaultProperties())], key($normalizedGroupedManagerClass), ) @endforeach @@ -98,7 +98,7 @@ @livewire( $normalizedManagerClass, - [...$managerLivewireProperties, ...(($manager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? $manager->properties : [])], + [...$managerLivewireProperties, ...(($manager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? [...$manager->relationManager::getDefaultProperties(), ...$manager->properties] : $manager::getDefaultProperties())], key($normalizedManagerClass), ) @endif diff --git a/packages/panels/src/Resources/RelationManagers/RelationManager.php b/packages/panels/src/Resources/RelationManagers/RelationManager.php index f58b528c18..29a154f880 100644 --- a/packages/panels/src/Resources/RelationManagers/RelationManager.php +++ b/packages/panels/src/Resources/RelationManagers/RelationManager.php @@ -82,6 +82,8 @@ class RelationManager extends Component implements Actions\Contracts\HasActions, protected static ?string $badge = null; + protected static bool $isLazy = true; + public function mount(): void { $this->loadDefaultActiveTab(); @@ -504,4 +506,23 @@ class RelationManager extends Component implements Actions\Contracts\HasActions, fn (Table $table, ?Closure $using) => $table->recordUrl($using), ); } + + /** + * @return array + */ + public static function getDefaultProperties(): array + { + $properties = []; + + if (static::isLazy()) { + $properties['lazy'] = true; + } + + return $properties; + } + + public static function isLazy(): bool + { + return static::$isLazy; + } } diff --git a/packages/widgets/resources/views/components/widgets.blade.php b/packages/widgets/resources/views/components/widgets.blade.php index 1eefdec50d..5d0b25af3f 100644 --- a/packages/widgets/resources/views/components/widgets.blade.php +++ b/packages/widgets/resources/views/components/widgets.blade.php @@ -28,7 +28,7 @@ @foreach ($widgets as $key => $widget) @livewire( $normalizeWidgetClass($widget), - [...(($widget instanceof \Filament\Widgets\WidgetConfiguration) ? $widget->properties : $widget::getDefaultProperties()), ...$data], + [...(($widget instanceof \Filament\Widgets\WidgetConfiguration) ? [...$widget->widget::getDefaultProperties(), ...$widget->properties] : $widget::getDefaultProperties()), ...$data], key($key), ) @endforeach