Skip to content

Commit

Permalink
feat: Add config options for enabling simple modal resource and remov…
Browse files Browse the repository at this point in the history
…ing empty state actions (#194)
  • Loading branch information
misterneo authored Aug 7, 2024
1 parent 7c7a026 commit 0fb1a3e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
16 changes: 16 additions & 0 deletions config/filament-spatie-roles-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
'roles' => true,
],

/*
* Set as true to use simple modal resource.
*/
'should_use_simple_modal_resource' => [
'permissions' => false,
'roles' => false,
],

/*
* Set as true to remove empty state actions.
*/
'should_remove_empty_state_actions' => [
'permissions' => false,
'roles' => false,
],

/**
* Set to true to redirect to the resource index instead of the view
*/
Expand Down
15 changes: 12 additions & 3 deletions src/Resources/PermissionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ public static function table(Table $table): Table
->required(),
])->deselectRecordsAfterCompletion(),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
->emptyStateActions(
config('filament-spatie-roles-permissions.should_remove_empty_state_actions.permissions') ? [] :
[
Tables\Actions\CreateAction::make()
]
);
}

public static function getRelations(): array
Expand All @@ -197,6 +200,12 @@ public static function getRelations(): array

public static function getPages(): array
{
if (config('filament-spatie-roles-permissions.should_use_simple_modal_resource.permissions')) {
return [
'index' => ListPermissions::route('/'),
];
}

return [
'index' => ListPermissions::route('/'),
'create' => CreatePermission::route('/create'),
Expand Down
15 changes: 12 additions & 3 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ public static function table(Table $table): Table
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
->emptyStateActions(
config('filament-spatie-roles-permissions.should_remove_empty_state_actions.roles') ? [] :
[
Tables\Actions\CreateAction::make()
]
);
}

public static function getRelations(): array
Expand All @@ -171,6 +174,12 @@ public static function getRelations(): array

public static function getPages(): array
{
if (config('filament-spatie-roles-permissions.should_use_simple_modal_resource.roles')) {
return [
'index' => ListRoles::route('/'),
];
}

return [
'index' => ListRoles::route('/'),
'create' => CreateRole::route('/create'),
Expand Down

0 comments on commit 0fb1a3e

Please sign in to comment.