## Summary - implement the Action Surface Contract v1.1 runtime changes for Spec 169 - add the new explicit ActionSurfaceType contract, validator/discovery updates, and enrolled surface declarations - update Filament action-surface documentation, focused guard tests, and spec artifacts for the completed feature ## Included - clickable-row vs explicit-inspect enforcement across monitoring, reporting, CRUD, and system reference surfaces - helper-first, workflow-next, destructive-last overflow ordering checks - system panel list discovery in the primary action-surface validator - Spec 169 artifacts: spec, plan, tasks, research, data model, quickstart, and logical contract ## Verification - focused Pest verification pack completed for: - tests/Feature/Guards/ActionSurfaceValidatorTest.php - tests/Feature/Guards/ActionSurfaceContractTest.php - tests/Feature/Rbac/TenantActionSurfaceConsistencyTest.php - integrated browser smoke test completed for admin-side reference surfaces: - /admin/operations - /admin/audit-log - /admin/finding-exceptions/queue - /admin/reviews - /admin/tenants ## Notes - system panel browser smoke coverage could not be exercised in the same session because /system routes require platform authentication in the integrated browser - Livewire target remains v4-compliant and no provider registration or asset strategy changes are introduced by this PR Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #200
133 lines
5.5 KiB
PHP
133 lines
5.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\System\Pages\Directory;
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\PlatformUser;
|
|
use App\Models\Tenant;
|
|
use App\Models\Workspace;
|
|
use App\Support\Auth\PlatformCapabilities;
|
|
use App\Support\Badges\BadgeDomain;
|
|
use App\Support\Badges\BadgeRenderer;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\System\SystemDirectoryLinks;
|
|
use App\Support\Ui\ActionSurface\ActionSurfaceDeclaration;
|
|
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceInspectAffordance;
|
|
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceProfile;
|
|
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceSlot;
|
|
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceType;
|
|
use Filament\Pages\Page;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class Workspaces extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static ?string $navigationLabel = 'Workspaces';
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-building-office-2';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Directory';
|
|
|
|
protected static ?string $slug = 'directory/workspaces';
|
|
|
|
protected string $view = 'filament.system.pages.directory.workspaces';
|
|
|
|
public static function actionSurfaceDeclaration(): ActionSurfaceDeclaration
|
|
{
|
|
return ActionSurfaceDeclaration::forPage(ActionSurfaceProfile::ListOnlyReadOnly, ActionSurfaceType::ReadOnlyRegistryReport)
|
|
->exempt(ActionSurfaceSlot::ListHeader, 'System workspace directory stays scan-first and does not expose page header actions.')
|
|
->satisfy(ActionSurfaceSlot::InspectAffordance, ActionSurfaceInspectAffordance::ClickableRow->value)
|
|
->exempt(ActionSurfaceSlot::ListRowMoreMenu, 'Workspace directory rows navigate directly to the detail page and have no secondary actions.')
|
|
->exempt(ActionSurfaceSlot::ListBulkMoreGroup, 'System workspace directory does not expose bulk actions.')
|
|
->satisfy(ActionSurfaceSlot::ListEmptyState, 'The empty state explains that workspaces appear here once the platform inventory is seeded.');
|
|
}
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = auth('platform')->user();
|
|
|
|
return $user instanceof PlatformUser
|
|
&& $user->hasCapability(PlatformCapabilities::DIRECTORY_VIEW);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mountInteractsWithTable();
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('name')
|
|
->paginated(\App\Support\Filament\TablePaginationProfiles::customPage())
|
|
->query(function (): Builder {
|
|
return Workspace::query()
|
|
->withCount([
|
|
'tenants',
|
|
'tenants as onboarding_tenants_count' => fn (Builder $query): Builder => $query->where('status', Tenant::STATUS_ONBOARDING),
|
|
]);
|
|
})
|
|
->columns([
|
|
TextColumn::make('name')
|
|
->label('Workspace')
|
|
->searchable(),
|
|
TextColumn::make('tenants_count')
|
|
->label('Tenants'),
|
|
TextColumn::make('health')
|
|
->label('Health')
|
|
->state(fn (Workspace $record): string => $this->healthForWorkspace($record))
|
|
->badge()
|
|
->formatStateUsing(BadgeRenderer::label(BadgeDomain::SystemHealth))
|
|
->color(BadgeRenderer::color(BadgeDomain::SystemHealth))
|
|
->icon(BadgeRenderer::icon(BadgeDomain::SystemHealth))
|
|
->iconColor(BadgeRenderer::iconColor(BadgeDomain::SystemHealth)),
|
|
TextColumn::make('failed_runs_24h')
|
|
->label('Failed (24h)')
|
|
->state(fn (Workspace $record): int => (int) OperationRun::query()
|
|
->where('workspace_id', (int) $record->getKey())
|
|
->where('created_at', '>=', now()->subDay())
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->where('outcome', OperationRunOutcome::Failed->value)
|
|
->count()),
|
|
])
|
|
->recordUrl(fn (Workspace $record): string => SystemDirectoryLinks::workspaceDetail($record))
|
|
->emptyStateHeading('No workspaces found')
|
|
->emptyStateDescription('Workspace inventory will appear here once workspaces are created.');
|
|
}
|
|
|
|
private function healthForWorkspace(Workspace $workspace): string
|
|
{
|
|
$tenantsCount = (int) ($workspace->getAttribute('tenants_count') ?? 0);
|
|
$onboardingTenantsCount = (int) ($workspace->getAttribute('onboarding_tenants_count') ?? 0);
|
|
|
|
if ($tenantsCount === 0) {
|
|
return 'unknown';
|
|
}
|
|
|
|
$hasRecentFailures = OperationRun::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->where('created_at', '>=', now()->subDay())
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->where('outcome', OperationRunOutcome::Failed->value)
|
|
->exists();
|
|
|
|
if ($hasRecentFailures) {
|
|
return 'critical';
|
|
}
|
|
|
|
if ($onboardingTenantsCount > 0) {
|
|
return 'warn';
|
|
}
|
|
|
|
return 'ok';
|
|
}
|
|
}
|