From 8d043614482c9a20f21a6659b14d8f0df94f2f11 Mon Sep 17 00:00:00 2001 From: tharindarodrigo Date: Sat, 4 Mar 2023 23:07:26 +0530 Subject: [PATCH] Bug fix/translation labels undetected (#36) * Translation labels bug fix for teams * refactor --------- Co-authored-by: Tharinda Rodrigo --- resources/lang/en/filament-spatie.php | 2 +- .../Pages/ListPermissions.php | 29 +++++++++---------- .../RelationManager/RoleRelationManager.php | 1 - src/Resources/RoleResource.php | 8 ++--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/resources/lang/en/filament-spatie.php b/resources/lang/en/filament-spatie.php index 9408df3..807fcc7 100644 --- a/resources/lang/en/filament-spatie.php +++ b/resources/lang/en/filament-spatie.php @@ -11,6 +11,7 @@ 'field.name' => 'Name', 'field.permissions' => 'Permissions', 'field.roles' => 'Roles', + 'field.team' => 'Team', /* |-------------------------------------------------------------------------- @@ -23,7 +24,6 @@ 'section.role' => 'Role', 'section.roles' => 'Roles', 'section.roles_and_permissions' => 'Roles and Permissions', - 'team' => 'Team', 'select-team' => 'Select a Team', 'select-team-hint' => 'Leave blank for a global role' ]; diff --git a/src/Resources/PermissionResource/Pages/ListPermissions.php b/src/Resources/PermissionResource/Pages/ListPermissions.php index aab32e0..f853bb6 100644 --- a/src/Resources/PermissionResource/Pages/ListPermissions.php +++ b/src/Resources/PermissionResource/Pages/ListPermissions.php @@ -2,8 +2,6 @@ namespace Althinect\FilamentSpatieRolesPermissions\Resources\PermissionResource\Pages; -// use Althinect\FilamentSpatieRolesPermissions\Resource\PermissionResource; - use Althinect\FilamentSpatieRolesPermissions\Resources\PermissionResource; use Filament\Forms\Components\Select; use Filament\Resources\Pages\ListRecords; @@ -15,23 +13,24 @@ class ListPermissions extends ListRecords { protected static string $resource = PermissionResource::class; - protected function getTableBulkActions() :array { + protected function getTableBulkActions(): array + { $roleModel = config('permission.models.role'); return [ BulkAction::make('Attach Role') - ->action(function (Collection $records, array $data): void { - foreach ($records as $record) { - $record->roles()->sync($data['role']); - $record->save(); - } - }) - ->form([ - Select::make('role') - ->label(__('filament-spatie-roles-permissions::filament-spatie.field.role')) - ->options($roleModel::query()->pluck('name', 'id')) - ->required(), - ])->deselectRecordsAfterCompletion() + ->action(function (Collection $records, array $data): void { + foreach ($records as $record) { + $record->roles()->sync($data['role']); + $record->save(); + } + }) + ->form([ + Select::make('role') + ->label(__('filament-spatie-roles-permissions::filament-spatie.field.role')) + ->options($roleModel::query()->pluck('name', 'id')) + ->required(), + ])->deselectRecordsAfterCompletion() ]; } diff --git a/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php b/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php index 8e8b102..7d1fabf 100644 --- a/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php +++ b/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php @@ -48,7 +48,6 @@ public static function table(Table $table): Table TextColumn::make('guard_name') ->searchable() ->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name')), - ]) ->filters([ // diff --git a/src/Resources/RoleResource.php b/src/Resources/RoleResource.php index db206c8..b4707d3 100644 --- a/src/Resources/RoleResource.php +++ b/src/Resources/RoleResource.php @@ -60,13 +60,13 @@ public static function form(Form $form): Form ->label(__('filament-spatie-roles-permissions::filament-spatie.field.permissions')) ->relationship('permissions', 'name') ->preload(config('filament-spatie-roles-permissions.preload_permissions')), - Select::make(config('permission.team_foreign_key', 'team_id'))->label(__('filament-spatie-roles-permissions::team')) + Select::make(config('permission.team_foreign_key', 'team_id'))->label(__('filament-spatie-roles-permissions::filament-spatie.field.team')) ->hidden(!config('permission.teams', false)) ->options( fn() => config('filament-spatie-roles-permissions.team_model', App\Models\Team::class)::pluck('name', 'id') ) - ->placeholder(__('filament-spatie-roles-permissions::select-team')) - ->hint(__('filament-spatie-roles-permissions::select-team-hint')), + ->placeholder(__('filament-spatie-roles-permissions::filament-spatie.select-team')) + ->hint(__('filament-spatie-roles-permissions::filament-spatie.select-team-hint')), ]) ]) ]); @@ -94,7 +94,7 @@ public static function table(Table $table): Table public static function getRelations(): array { return [ - PermissionRelationManager::class + PermissionRelationManager::class, ]; }