heading('Recent Operations') ->query($this->getQuery()) ->poll(fn (): ?string => ($tenant instanceof Tenant) && ActiveRuns::existForTenant($tenant) ? '10s' : null) ->paginated([10]) ->columns([ TextColumn::make('short_id') ->label('Run') ->state(fn (OperationRun $record): string => '#'.$record->getKey()) ->copyable() ->copyableState(fn (OperationRun $record): string => (string) $record->getKey()), TextColumn::make('type') ->label('Operation') ->formatStateUsing(fn (?string $state): string => OperationCatalog::label((string) $state)) ->limit(40) ->tooltip(fn (OperationRun $record): string => OperationCatalog::label((string) $record->type)), TextColumn::make('status') ->badge() ->color(fn (OperationRun $record): string => $this->statusColor($record->status)), TextColumn::make('outcome') ->badge() ->color(fn (OperationRun $record): string => $this->outcomeColor($record->outcome)), TextColumn::make('created_at') ->label('Started') ->since(), ]) ->recordUrl(fn (OperationRun $record): ?string => $tenant instanceof Tenant ? OperationRunLinks::view($record, $tenant) : null) ->emptyStateHeading('No operations yet') ->emptyStateDescription('Once you run inventory sync, drift generation, or restores, they\'ll show up here.'); } /** * @return Builder */ private function getQuery(): Builder { $tenant = Filament::getTenant(); $tenantId = $tenant instanceof Tenant ? $tenant->getKey() : null; return OperationRun::query() ->when($tenantId, fn (Builder $query) => $query->where('tenant_id', $tenantId)) ->latest('created_at'); } private function statusColor(?string $status): string { return match ($status) { 'queued' => 'secondary', 'running' => 'warning', 'completed' => 'success', default => 'gray', }; } private function outcomeColor(?string $outcome): string { return match ($outcome) { 'succeeded' => 'success', 'partially_succeeded' => 'warning', 'failed' => 'danger', 'cancelled' => 'gray', default => 'gray', }; } }