Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Option to Set default layout from Config #457

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function panel(Panel $panel): Panel
->navigationSort(3)
->navigationCountBadge()
->registerNavigation(false)
->defaultView('grid' || 'list')
->resource(\App\Filament\Resources\CustomMediaResource::class)
]);
}
Expand Down
3 changes: 3 additions & 0 deletions config/curator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
'display_upload_new' => true,
],
'multi_select_key' => 'metaKey',
'table' => [
'layout' => 'grid',
]
];
16 changes: 15 additions & 1 deletion src/CuratorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CuratorPlugin implements Plugin

protected ?bool $shouldRegisterNavigation = null;

protected ?string $getDefaultListView = null;

protected string | Closure | null $pluralLabel = null;

protected ?string $resource = null;
Expand All @@ -40,7 +42,7 @@ public function register(Panel $panel): void
$this->getResource(),
]);

if (! is_panel_auth_route()) {
if (!is_panel_auth_route()) {
$panel
->renderHook(
'panels::body.end',
Expand Down Expand Up @@ -103,6 +105,11 @@ public function shouldRegisterNavigation(): ?bool
return $this->shouldRegisterNavigation ?? config('curator.should_register_navigation');
}

public function getDefaultListView(): ?string
{
return $this->getDefaultListView ?? config('curator.table.layout');
}

public function navigationGroup(string | Closure | null $group = null): static
{
$this->navigationGroup = $group;
Expand Down Expand Up @@ -138,6 +145,13 @@ public function registerNavigation(bool $show = true): static
return $this;
}

public function defaultView(string $view): static
{
$this->getDefaultListView = $view;

return $this;
}

public function pluralLabel(string | Closure $label): static
{
$this->pluralLabel = $label;
Expand Down
7 changes: 6 additions & 1 deletion src/Resources/MediaResource/ListMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

class ListMedia extends ListRecords
{
public string $layoutView = 'grid';
public string $layoutView;

public function boot()
{
$this->layoutView = CuratorPlugin::get()->getDefaultListView();
}

protected $listeners = [
'changeLayoutView' => 'changeLayoutView',
Expand Down