Skip to content

Commit

Permalink
Fix Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-layson committed Apr 11, 2024
1 parent b1e1c18 commit 51878d3
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/Filament/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Portable\FilaCms\Filament\Resources\RoleResource\Pages;
use Portable\FilaCms\Filament\Traits\IsProtectedResource;
use Spatie\Permission\Models\Role;
use Portable\FilaCms\Filament\Resources\RoleResource\RelationManagers;

class RoleResource extends AbstractResource
{
Expand Down Expand Up @@ -55,19 +56,19 @@ public static function table(Table $table): Table
]);
}

public static function getRelations(): array
public static function getPages(): array
{
return [
//
'index' => Pages\ListRoles::route('/'),
'create' => Pages\CreateRole::route('/create'),
'edit' => Pages\EditRole::route('/{record}/edit'),
];
}

public static function getPages(): array
public static function getRelations(): array
{
return [
'index' => Pages\ListRoles::route('/'),
'create' => Pages\CreateRole::route('/create'),
'edit' => Pages\EditRole::route('/{record}/edit'),
RelationManagers\UsersRelationManager::class,
];
}
}
14 changes: 13 additions & 1 deletion src/Filament/Resources/RoleResource/Pages/EditRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Portable\FilaCms\Filament\Resources\RoleResource;
use Filament\Notifications\Notification;
use Spatie\Permission\Models\Role;

class EditRole extends EditRecord
{
Expand All @@ -13,7 +15,17 @@ class EditRole extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\DeleteAction::make()
->before(function (Actions\DeleteAction $action, Role $role) {
if ($role->users->count() > 0) {
Notification::make()
->title('Unable to perform action')
->body('You cannot delete a role that are assigned to user(s)')
->status('warning')
->send();
$action->cancel();
}
}),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Portable\FilaCms\Filament\Resources\RoleResource\RelationManagers;

use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Columns\ViewColumn;
use Filament\Tables\Table;

class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';

public function form(Form $form): Form
{
return $form
->schema([]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('Users')
->columns([
ViewColumn::make('name')
->view('fila-cms::tables.columns.roles-user'),
ViewColumn::make('created_at')
->label('Creation Date')
->view('fila-cms::tables.columns.created_at'),
]);
}
}
2 changes: 1 addition & 1 deletion tests/Filament/PageResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function test_can_save_form(): void
$this->assertEquals($data->title, $new->title);
$this->assertEquals($data->author_id, $new->author_id);
$this->assertEquals($data->is_draft, $new->is_draft);
$this->assertGreaterThanOrEqual($data->updated_at->format('U'), $updatedTime->format('U'));
$this->assertGreaterThanOrEqual($updatedTime->format('U'), $data->updated_at->format('U'));
}

public function test_can_create_page_with_taxonomies(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Filament/PermissionResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public function test_can_save_form(): void

$data->refresh();
$this->assertEquals($data->name, $new->name);
$this->assertGreaterThanOrEqual($data->updated_at->format('U'), $updatedTime->format('U'));
$this->assertGreaterThanOrEqual($updatedTime->format('U'), $data->updated_at->format('U'));
}
}
9 changes: 9 additions & 0 deletions views/tables/columns/created_at.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="fi-ta-text grid w-full gap-y-1 px-3 py-4">
<div class="flex">
<div class="fi-ta-text-item inline-flex items-center gap-1.5 ">
<span class="fi-ta-text-item-label text-sm leading-6 text-gray-950 dark:text-white">
{{ $getRecord()->created_at }}
</span>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions views/tables/columns/roles-user.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="fi-ta-text grid w-full gap-y-1 px-3 py-4">
<div class="flex">
<div class="fi-ta-text-item inline-flex items-center gap-1.5 ">
<span class="fi-ta-text-item-label text-sm leading-6 text-gray-950 dark:text-white">
{{ $getRecord()->name ?? $getRecord()->first_name }}
</span>
</div>
</div>
</div>

0 comments on commit 51878d3

Please sign in to comment.