## Summary - amend the operator UI constitution and related SpecKit templates for the new UI/UX governance rules - add Spec 168 artifacts plus the tenant governance aggregate implementation used by the tenant dashboard, banner, and baseline compare landing surfaces - normalize Filament action surfaces around clickable-row inspection, grouped secondary actions, and explicit action-surface declarations across enrolled resources and pages - fix post-suite regressions in membership cache priming, finding workflow state refresh, tenant review derived-state invalidation, and tenant-bound backup-set related navigation ## Commit Series - `docs: amend operator UI constitution` - `spec: add tenant governance aggregate contract` - `feat: add tenant governance aggregate contract` - `refactor: normalize filament action surfaces` - `fix: resolve post-suite state regressions` ## Testing - `vendor/bin/sail artisan test --compact` - Result: `3176 passed, 8 skipped (17384 assertions)` ## Notes - Livewire v4 / Filament v5 stack remains unchanged - no provider registration changes; `bootstrap/providers.php` remains the relevant location - no new global-search resources or asset-registration changes in this branch Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #199
125 lines
5.1 KiB
PHP
125 lines
5.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\System\Pages\Directory;
|
|
|
|
use App\Models\PlatformUser;
|
|
use App\Models\Tenant;
|
|
use App\Support\Auth\PlatformCapabilities;
|
|
use App\Support\Badges\BadgeDomain;
|
|
use App\Support\Badges\BadgeRenderer;
|
|
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 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 Tenants extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static ?string $navigationLabel = 'Tenants';
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-users';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Directory';
|
|
|
|
protected static ?string $slug = 'directory/tenants';
|
|
|
|
protected string $view = 'filament.system.pages.directory.tenants';
|
|
|
|
public static function actionSurfaceDeclaration(): ActionSurfaceDeclaration
|
|
{
|
|
return ActionSurfaceDeclaration::forPage(ActionSurfaceProfile::ListOnlyReadOnly)
|
|
->exempt(ActionSurfaceSlot::ListHeader, 'System tenant directory stays scan-first and does not expose page header actions.')
|
|
->satisfy(ActionSurfaceSlot::InspectAffordance, ActionSurfaceInspectAffordance::ClickableRow->value)
|
|
->exempt(ActionSurfaceSlot::ListRowMoreMenu, 'Tenant directory rows navigate directly to the detail page and have no secondary actions.')
|
|
->exempt(ActionSurfaceSlot::ListBulkMoreGroup, 'System tenant directory does not expose bulk actions.')
|
|
->satisfy(ActionSurfaceSlot::ListEmptyState, 'The empty state explains that tenants appear here after onboarding and inventory sync.');
|
|
}
|
|
|
|
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 Tenant::query()
|
|
->with('workspace')
|
|
->withCount([
|
|
'providerConnections',
|
|
'providerConnections as unhealthy_connections_count' => fn (Builder $query): Builder => $query->where('health_status', 'unhealthy'),
|
|
'permissions as missing_permissions_count' => fn (Builder $query): Builder => $query->where('status', '!=', 'granted'),
|
|
]);
|
|
})
|
|
->columns([
|
|
TextColumn::make('name')
|
|
->label('Tenant')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('workspace.name')
|
|
->label('Workspace')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('status')
|
|
->badge()
|
|
->formatStateUsing(BadgeRenderer::label(BadgeDomain::TenantStatus))
|
|
->color(BadgeRenderer::color(BadgeDomain::TenantStatus))
|
|
->icon(BadgeRenderer::icon(BadgeDomain::TenantStatus))
|
|
->iconColor(BadgeRenderer::iconColor(BadgeDomain::TenantStatus)),
|
|
TextColumn::make('health')
|
|
->label('Health')
|
|
->state(fn (Tenant $record): string => $this->healthForTenant($record))
|
|
->badge()
|
|
->formatStateUsing(BadgeRenderer::label(BadgeDomain::SystemHealth))
|
|
->color(BadgeRenderer::color(BadgeDomain::SystemHealth))
|
|
->icon(BadgeRenderer::icon(BadgeDomain::SystemHealth))
|
|
->iconColor(BadgeRenderer::iconColor(BadgeDomain::SystemHealth)),
|
|
])
|
|
->recordUrl(fn (Tenant $record): string => SystemDirectoryLinks::tenantDetail($record))
|
|
->emptyStateHeading('No tenants found')
|
|
->emptyStateDescription('Tenants will appear here as inventory is onboarded.');
|
|
}
|
|
|
|
private function healthForTenant(Tenant $tenant): string
|
|
{
|
|
if ((string) $tenant->status === Tenant::STATUS_ARCHIVED) {
|
|
return 'unknown';
|
|
}
|
|
|
|
if ((int) ($tenant->getAttribute('unhealthy_connections_count') ?? 0) > 0) {
|
|
return 'critical';
|
|
}
|
|
|
|
if ((int) ($tenant->getAttribute('missing_permissions_count') ?? 0) > 0) {
|
|
return 'warn';
|
|
}
|
|
|
|
if ((string) $tenant->status === Tenant::STATUS_ONBOARDING) {
|
|
return 'warn';
|
|
}
|
|
|
|
return 'ok';
|
|
}
|
|
}
|