Skip to content

Commit

Permalink
Bug fix/translation labels undetected (#36)
Browse files Browse the repository at this point in the history
* Translation labels bug fix for teams

* refactor

---------

Co-authored-by: Tharinda Rodrigo <[email protected]>
  • Loading branch information
tharindarodrigo and Tharinda Rodrigo authored Mar 4, 2023
1 parent df02a7d commit 8d04361
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion resources/lang/en/filament-spatie.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'field.name' => 'Name',
'field.permissions' => 'Permissions',
'field.roles' => 'Roles',
'field.team' => 'Team',

/*
|--------------------------------------------------------------------------
Expand All @@ -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'
];
29 changes: 14 additions & 15 deletions src/Resources/PermissionResource/Pages/ListPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
];

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
//
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
])
])
]);
Expand Down Expand Up @@ -94,7 +94,7 @@ public static function table(Table $table): Table
public static function getRelations(): array
{
return [
PermissionRelationManager::class
PermissionRelationManager::class,
];
}

Expand Down

0 comments on commit 8d04361

Please sign in to comment.