From 007d15fcaeba062524d28c82c0789c9b5d81ad34 Mon Sep 17 00:00:00 2001 From: Bezhan Salleh Date: Sun, 24 Sep 2023 22:29:40 +0430 Subject: [PATCH 1/5] column grid customization --- src/Concerns/CanCustomizeColumns.php | 116 +++++++++++++++++++++++++++ src/FilamentShieldPlugin.php | 9 ++- src/Resources/RoleResource.php | 72 +++++++++-------- 3 files changed, 159 insertions(+), 38 deletions(-) create mode 100644 src/Concerns/CanCustomizeColumns.php diff --git a/src/Concerns/CanCustomizeColumns.php b/src/Concerns/CanCustomizeColumns.php new file mode 100644 index 0000000..10a0624 --- /dev/null +++ b/src/Concerns/CanCustomizeColumns.php @@ -0,0 +1,116 @@ + 2, + 'lg' => 4, + ]; + + protected int | string | array $gridColumns = 1; + + protected int | string | array $resourceCheckboxListColumnSpan = 'full'; + + protected int | string | array $resourceCheckboxListColumns = [ + 'sm' => 2, + 'lg' => 4, + ]; + + protected int | string | array $sectionColumnSpan = 'full'; + + protected int | string | array $sectionColumns = [ + 'sm' => 2, + 'lg' => 4, + ]; + + public function checkboxListColumns(int | string | array $columns): static + { + $this->checkboxListColumns = $columns; + + return $this; + } + + public function checkboxListColumnSpan(int | string | array $columnSpan): static + { + $this->checkboxListColumnSpan = $columnSpan; + + return $this; + } + + public function gridColumns(int | string | array $columns): static + { + $this->gridColumns = $columns; + + return $this; + } + + public function resourceCheckboxListColumns(int | string | array $columns): static + { + $this->resourceCheckboxListColumns = $columns; + + return $this; + } + + public function resourceCheckboxListColumnSpan(int | string | array $columnSpan): static + { + $this->resourceCheckboxListColumnSpan = $columnSpan; + + return $this; + } + + public function sectionColumns(int | string | array $columns): static + { + $this->sectionColumns = $columns; + + return $this; + } + + public function sectionColumnSpan(int | string | array $columnSpan): static + { + $this->sectionColumnSpan = $columnSpan; + + return $this; + } + + public function getCheckboxListColumns(): int | string | array + { + return $this->checkboxListColumns; + } + + public function getCheckboxListColumnSpan(): int | string | array + { + return $this->checkboxListColumnSpan; + } + + public function getGridColumns(): int | string | array + { + return $this->gridColumns; + } + + public function getResourceCheckboxListColumns(): int | string | array + { + return $this->resourceCheckboxListColumns; + } + + public function getResourceCheckboxListColumnSpan(): int | string | array + { + return $this->resourceCheckboxListColumnSpan; + } + + public function getSectionColumns(): int | string | array + { + return $this->sectionColumns; + } + + public function getSectionColumnSpan(): int | string | array + { + return $this->sectionColumnSpan; + } +} diff --git a/src/FilamentShieldPlugin.php b/src/FilamentShieldPlugin.php index 682c6f4..fd73cef 100644 --- a/src/FilamentShieldPlugin.php +++ b/src/FilamentShieldPlugin.php @@ -4,13 +4,16 @@ namespace BezhanSalleh\FilamentShield; -use BezhanSalleh\FilamentShield\Support\Utils; -use Filament\Contracts\Plugin; -use Filament\FilamentManager; use Filament\Panel; +use Filament\FilamentManager; +use Filament\Contracts\Plugin; +use BezhanSalleh\FilamentShield\Support\Utils; +use BezhanSalleh\FilamentShield\Concerns; class FilamentShieldPlugin implements Plugin { + use Concerns\CanCustomizeColumns; + public static function make(): static { return app(static::class); diff --git a/src/Resources/RoleResource.php b/src/Resources/RoleResource.php index 163f06d..1e87de4 100644 --- a/src/Resources/RoleResource.php +++ b/src/Resources/RoleResource.php @@ -2,21 +2,22 @@ namespace BezhanSalleh\FilamentShield\Resources; -use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions; -use BezhanSalleh\FilamentShield\Facades\FilamentShield; -use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages; -use BezhanSalleh\FilamentShield\Support\Utils; use Filament\Forms; -use Filament\Forms\Components\Actions\Action as FormAction; -use Filament\Forms\Components\Component; -use Filament\Forms\Form; -use Filament\Resources\Resource; use Filament\Tables; +use Filament\Forms\Form; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; +use Filament\Resources\Resource; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; -use Illuminate\Support\Str; +use Illuminate\Database\Eloquent\Model; +use Filament\Forms\Components\Component; +use BezhanSalleh\FilamentShield\Support\Utils; +use BezhanSalleh\FilamentShield\FilamentShieldPlugin; +use BezhanSalleh\FilamentShield\Facades\FilamentShield; +use Filament\Forms\Components\Actions\Action as FormAction; +use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages; +use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions; class RoleResource extends Resource implements HasShieldPermissions { @@ -78,10 +79,7 @@ public static function form(Form $form): Form ->schema([ Forms\Components\Grid::make() ->schema(static::getResourceEntitiesSchema()) - ->columns([ - 'sm' => 1, - 'lg' => 1, - ]), + ->columns(FilamentShieldPlugin::get()->getGridColumns()), ]), Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.pages')) ->visible(fn (): bool => (bool) Utils::isPageEntityEnabled() && (count(FilamentShield::getPages()) > 0 ? true : false)) @@ -118,11 +116,8 @@ public static function form(Form $form): Form ->dehydrated(fn ($state) => blank($state) ? false : true) ->bulkToggleable() ->gridDirection('row') - ->columns([ - 'sm' => 2, - 'lg' => 4, - ]) - ->columnSpanFull(), + ->columns(FilamentShieldPlugin::get()->getCheckboxListColumns()) + ->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()), ]), Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.widgets')) ->visible(fn (): bool => (bool) Utils::isWidgetEntityEnabled() && (count(FilamentShield::getWidgets()) > 0 ? true : false)) @@ -160,11 +155,8 @@ public static function form(Form $form): Form ->dehydrated(fn ($state) => blank($state) ? false : true) ->bulkToggleable() ->gridDirection('row') - ->columns([ - 'sm' => 2, - 'lg' => 4, - ]) - ->columnSpanFull(), + ->columns(FilamentShieldPlugin::get()->getCheckboxListColumns()) + ->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()), ]), Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.custom')) ->visible(fn (): bool => (bool) Utils::isCustomPermissionEntityEnabled() && (count(static::getCustomEntities()) > 0 ? true : false)) @@ -201,11 +193,8 @@ public static function form(Form $form): Form ->dehydrated(fn ($state) => blank($state) ? false : true) ->bulkToggleable() ->gridDirection('row') - ->columns([ - 'sm' => 2, - 'lg' => 4, - ]) - ->columnSpanFull(), + ->columns(FilamentShieldPlugin::get()->getCheckboxListColumns()) + ->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()), ]), ]) ->columnSpan('full'), @@ -237,6 +226,23 @@ public static function table(Table $table): Table ->filters([ // ]) + ->headerActions([ + Tables\Actions\Action::make('new_permission') + ->label('New Permission') + ->form([ + Forms\Components\TextInput::make('name') + ->required() + ->unique('permissions', 'name'), + Forms\Components\TextInput::make('guard_name') + ->default(Utils::getFilamentAuthGuard()), + ]) + ->modalHeading('Delete post') + ->action(function (array $data): void { + Utils::getPermissionModel()::create($data); + }) + ->modalWidth('2xl') + ->slideOver(), + ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), @@ -365,13 +371,9 @@ public static function getResourceEntitiesSchema(): ?array ->dehydrated(fn ($state) => blank($state) ? false : true) ->bulkToggleable() ->gridDirection('row') - ->columns([ - 'default' => 2, - 'sm' => 3, - 'lg' => 4, - ]), + ->columns(FilamentShieldPlugin::get()->getResourceCheckboxListColumns()), ]) - ->columnSpanFull() + ->columnSpan(FilamentShieldPlugin::get()->getSectionColumnSpan()) ->collapsible(); return $entities; From 640860c8a4bb4835609731e4da27a40563fcc655 Mon Sep 17 00:00:00 2001 From: bezhanSalleh Date: Sun, 24 Sep 2023 18:00:31 +0000 Subject: [PATCH 2/5] Fix styling --- src/Concerns/CanCustomizeColumns.php | 1 - src/FilamentShieldPlugin.php | 7 +++---- src/Resources/RoleResource.php | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Concerns/CanCustomizeColumns.php b/src/Concerns/CanCustomizeColumns.php index 10a0624..713d6cf 100644 --- a/src/Concerns/CanCustomizeColumns.php +++ b/src/Concerns/CanCustomizeColumns.php @@ -4,7 +4,6 @@ namespace BezhanSalleh\FilamentShield\Concerns; - trait CanCustomizeColumns { protected int | string | array $checkboxListColumnSpan = 'full'; diff --git a/src/FilamentShieldPlugin.php b/src/FilamentShieldPlugin.php index fd73cef..e2e9531 100644 --- a/src/FilamentShieldPlugin.php +++ b/src/FilamentShieldPlugin.php @@ -4,11 +4,10 @@ namespace BezhanSalleh\FilamentShield; -use Filament\Panel; -use Filament\FilamentManager; -use Filament\Contracts\Plugin; use BezhanSalleh\FilamentShield\Support\Utils; -use BezhanSalleh\FilamentShield\Concerns; +use Filament\Contracts\Plugin; +use Filament\FilamentManager; +use Filament\Panel; class FilamentShieldPlugin implements Plugin { diff --git a/src/Resources/RoleResource.php b/src/Resources/RoleResource.php index 1e87de4..bbec551 100644 --- a/src/Resources/RoleResource.php +++ b/src/Resources/RoleResource.php @@ -2,22 +2,22 @@ namespace BezhanSalleh\FilamentShield\Resources; +use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions; +use BezhanSalleh\FilamentShield\Facades\FilamentShield; +use BezhanSalleh\FilamentShield\FilamentShieldPlugin; +use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages; +use BezhanSalleh\FilamentShield\Support\Utils; use Filament\Forms; -use Filament\Tables; +use Filament\Forms\Components\Actions\Action as FormAction; +use Filament\Forms\Components\Component; use Filament\Forms\Form; -use Filament\Tables\Table; -use Illuminate\Support\Str; use Filament\Resources\Resource; +use Filament\Tables; +use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; -use Illuminate\Database\Eloquent\Model; -use Filament\Forms\Components\Component; -use BezhanSalleh\FilamentShield\Support\Utils; -use BezhanSalleh\FilamentShield\FilamentShieldPlugin; -use BezhanSalleh\FilamentShield\Facades\FilamentShield; -use Filament\Forms\Components\Actions\Action as FormAction; -use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages; -use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions; +use Illuminate\Support\Str; class RoleResource extends Resource implements HasShieldPermissions { From 8e153ca59ce5c8b7f217e3e474917b4559acc002 Mon Sep 17 00:00:00 2001 From: Bezhan Salleh Date: Sun, 24 Sep 2023 22:45:10 +0430 Subject: [PATCH 3/5] headeractions experiment removed for now --- src/Resources/RoleResource.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Resources/RoleResource.php b/src/Resources/RoleResource.php index bbec551..462d286 100644 --- a/src/Resources/RoleResource.php +++ b/src/Resources/RoleResource.php @@ -226,23 +226,6 @@ public static function table(Table $table): Table ->filters([ // ]) - ->headerActions([ - Tables\Actions\Action::make('new_permission') - ->label('New Permission') - ->form([ - Forms\Components\TextInput::make('name') - ->required() - ->unique('permissions', 'name'), - Forms\Components\TextInput::make('guard_name') - ->default(Utils::getFilamentAuthGuard()), - ]) - ->modalHeading('Delete post') - ->action(function (array $data): void { - Utils::getPermissionModel()::create($data); - }) - ->modalWidth('2xl') - ->slideOver(), - ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), From c04cd7f8b8a469765ccc46a45e13e829fbec4573 Mon Sep 17 00:00:00 2001 From: Bezhan Salleh Date: Sun, 24 Sep 2023 23:18:05 +0430 Subject: [PATCH 4/5] fix phpstan errors --- src/FilamentShieldPlugin.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/FilamentShieldPlugin.php b/src/FilamentShieldPlugin.php index e2e9531..026d410 100644 --- a/src/FilamentShieldPlugin.php +++ b/src/FilamentShieldPlugin.php @@ -8,6 +8,7 @@ use Filament\Contracts\Plugin; use Filament\FilamentManager; use Filament\Panel; +use Illuminate\Foundation\Mix; class FilamentShieldPlugin implements Plugin { @@ -37,12 +38,11 @@ public function boot(Panel $panel): void // } - /** - * Class MyClass overrides inline block form. - * - * @phpstan-ignore-next-line */ - public static function get(): Plugin | FilamentManager + public static function get(): static { - return filament(app(static::class)->getId()); + /** @var static $plugin */ + $plugin = filament(app(static::class)->getId()); + + return $plugin; } } From 2ad22eca4bee17efa63be4beb64d56ad306dd14e Mon Sep 17 00:00:00 2001 From: bezhanSalleh Date: Sun, 24 Sep 2023 18:48:41 +0000 Subject: [PATCH 5/5] Fix styling --- src/FilamentShieldPlugin.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/FilamentShieldPlugin.php b/src/FilamentShieldPlugin.php index 026d410..7c904b2 100644 --- a/src/FilamentShieldPlugin.php +++ b/src/FilamentShieldPlugin.php @@ -6,9 +6,7 @@ use BezhanSalleh\FilamentShield\Support\Utils; use Filament\Contracts\Plugin; -use Filament\FilamentManager; use Filament\Panel; -use Illuminate\Foundation\Mix; class FilamentShieldPlugin implements Plugin {