## Summary - standardize Filament table defaults across resources, relation managers, widgets, custom pages, and picker tables - add shared pagination profiles, calm default column visibility, explicit empty states, and session persistence on designated critical resource lists - complete Spec 125 artifacts, regression tests, and dashboard widget follow-up for lazy loading, sortable columns, and toggleable detail columns ## Verification - `docker exec tenantatlas-laravel.test-1 php artisan test --compact --filter=BaselineCompareNow` - `docker exec tenantatlas-laravel.test-1 php artisan test --compact --filter=TableStandardsBaseline` - `docker exec tenantatlas-laravel.test-1 php artisan test --compact --filter=TableDetailVisibility` - `docker exec tenantatlas-laravel.test-1 php artisan test --compact --filter=FilamentTableRiskExceptions` - full suite run completed: `2017 passed, 10 failed, 8 skipped` - manual browser QA completed on the tenant dashboard for lazy loading, sortable widget columns, toggleable hidden status columns, badges, and pagination ## Known Failures The full suite still has 10 pre-existing failures unrelated to this branch: - `Tests\\Unit\\OpsUx\\SummaryCountsNormalizerTest` - `Tests\\Feature\\BackupWithAssignmentsConsistencyTest` (2 tests) - `Tests\\Feature\\BaselineDriftEngine\\CaptureBaselineContentTest` - `Tests\\Feature\\BaselineDriftEngine\\CompareContentEvidenceTest` - `Tests\\Feature\\BaselineDriftEngine\\ResolverTest` - `Tests\\Feature\\Filament\\TenantDashboardDbOnlyTest` - `Tests\\Feature\\Operations\\ReconcileAdapterRunsJobTrackingTest` - `Tests\\Feature\\ReviewPack\\ReviewPackRbacTest` - `Tests\\Feature\\Verification\\VerificationReportRedactionTest` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #152
118 lines
4.3 KiB
PHP
118 lines
4.3 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 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 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';
|
|
}
|
|
}
|