89 lines
3.3 KiB
PHP
89 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Workspaces\Tables;
|
|
|
|
use App\Models\Workspace;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\Rbac\UiEnforcement;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class WorkspacesTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('name')
|
|
->searchable(),
|
|
TextColumn::make('slug')
|
|
->searchable(),
|
|
TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
EditAction::make(),
|
|
UiEnforcement::forAction(
|
|
Action::make('archive')
|
|
->label('Archive')
|
|
->color('danger')
|
|
->icon('heroicon-o-archive-box')
|
|
->visible(fn (Workspace $record): bool => empty($record->archived_at))
|
|
->action(function (Workspace $record): void {
|
|
$record->forceFill(['archived_at' => now()])->save();
|
|
|
|
Notification::make()
|
|
->title('Workspace archived')
|
|
->success()
|
|
->send();
|
|
})
|
|
)
|
|
->preserveVisibility()
|
|
->requireCapability(Capabilities::WORKSPACE_MANAGE)
|
|
->destructive()
|
|
->tooltip('You do not have permission to archive this workspace.')
|
|
->apply(),
|
|
UiEnforcement::forAction(
|
|
Action::make('unarchive')
|
|
->label('Unarchive')
|
|
->color('success')
|
|
->icon('heroicon-o-arrow-uturn-left')
|
|
->visible(fn (Workspace $record): bool => ! empty($record->archived_at))
|
|
->action(function (Workspace $record): void {
|
|
$record->forceFill(['archived_at' => null])->save();
|
|
|
|
Notification::make()
|
|
->title('Workspace unarchived')
|
|
->success()
|
|
->send();
|
|
})
|
|
)
|
|
->preserveVisibility()
|
|
->requireCapability(Capabilities::WORKSPACE_MANAGE)
|
|
->tooltip('You do not have permission to unarchive this workspace.')
|
|
->apply(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|