Skip to content

Commit 0dd7791

Browse files
authored
Merge pull request #4 from invaders-xx/add-more-plugin-options
Add more plugin options
2 parents 1600415 + 11e97db commit 0dd7791

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ php artisan vendor:publish --tag="filament-gridstack-dashboard-views"
7070

7171
## Usage
7272

73+
All functions used to configure the plugin can have a closure as argument.
74+
7375
```php
7476
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;
7577

@@ -189,7 +191,8 @@ public function panel(Panel $panel): Panel
189191
}
190192
```
191193

192-
You can configure the navigationIcon, the navigationGroup and the navigationSort
194+
You can configure the navigationIcon, the navigationGroup, the navigationLabel, the navigationSort, canAccess and
195+
shouldRegisterNavigation
193196

194197
```php
195198
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;
@@ -201,6 +204,9 @@ public function panel(Panel $panel): Panel
201204
GridstackDashboardPlugin::make()
202205
->navigationIcon('heroicon-o-chart-bar')
203206
->navigationGroup('Admin')
207+
->shouldRegisterNavigation(false)
208+
->canAccess(fn() => auth()->id()===1)
209+
->navigationLabel('Dashboard')
204210
->navigationSort(1),
205211
])
206212
}

src/Filament/Pages/Dashboard.php

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ class Dashboard extends BaseDashboard
1818

1919
protected static string $view = 'filament-gridstack-dashboard::pages.dashboard';
2020

21+
public static function canAccess(): bool
22+
{
23+
return GridstackDashboardPlugin::get()->getCanAccess() ?? parent::canAccess();
24+
}
25+
26+
public static function getNavigationLabel(): string
27+
{
28+
return GridstackDashboardPlugin::get()->getNavigationLabel() ?? parent::getNavigationLabel();
29+
}
30+
31+
public static function shouldRegisterNavigation(): bool
32+
{
33+
return GridstackDashboardPlugin::get()->getShouldRegisterNavigation() ?? parent::$shouldRegisterNavigation;
34+
}
35+
2136
public static function getNavigationGroup(): ?string
2237
{
2338
return GridstackDashboardPlugin::get()->getNavigationGroup() ?? parent::getNavigationGroup();

src/GridstackDashboardPlugin.php

+42
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ class GridstackDashboardPlugin implements Plugin
3333

3434
protected bool|Closure $disableResize = false;
3535

36+
protected bool|Closure $canAccess = true;
37+
38+
protected bool|Closure $shouldRegisterNavigation = true;
39+
3640
protected string|Closure $resizable = 'se';
3741

42+
protected string|Closure|null $navigationLabel = null;
43+
3844
public static function make(): static
3945
{
4046
return app(static::class);
@@ -117,6 +123,27 @@ public function resizable(string|Closure $resizable): static
117123
return $this;
118124
}
119125

126+
public function canAccess(bool|Closure $canAccess = true): static
127+
{
128+
$this->canAccess = $canAccess;
129+
130+
return $this;
131+
}
132+
133+
public function shouldRegisterNavigation(bool|Closure $shouldRegisterNavigation = true): static
134+
{
135+
$this->shouldRegisterNavigation = $shouldRegisterNavigation;
136+
137+
return $this;
138+
}
139+
140+
public function navigationLabel(string|Closure $navigationLabel): static
141+
{
142+
$this->navigationLabel = $navigationLabel;
143+
144+
return $this;
145+
}
146+
120147
public function navigationSort(int|Closure $navigationSort): static
121148
{
122149
$this->navigationSort = $navigationSort;
@@ -148,6 +175,11 @@ public function getDefaultGrid(): array
148175
return $this->evaluate($this->defaultGrid);
149176
}
150177

178+
public function getNavigationLabel(): ?string
179+
{
180+
return $this->evaluate($this->navigationLabel);
181+
}
182+
151183
public function getNavigationSort(): int
152184
{
153185
return $this->evaluate($this->navigationSort);
@@ -188,6 +220,16 @@ public function getDisableDrag(): ?bool
188220
return $this->evaluate($this->disableDrag);
189221
}
190222

223+
public function getCanAccess(): ?bool
224+
{
225+
return $this->evaluate($this->canAccess);
226+
}
227+
228+
public function getShouldRegisterNavigation(): ?bool
229+
{
230+
return $this->evaluate($this->shouldRegisterNavigation);
231+
}
232+
191233
public function getDisableResize(): ?bool
192234
{
193235
return $this->evaluate($this->disableResize);

0 commit comments

Comments
 (0)