resetWorkspaceHubEnvironmentFilterStateForCleanEntry(request()); $this->environmentFilter(); } public static function actionSurfaceDeclaration(): ActionSurfaceDeclaration { return ActionSurfaceDeclaration::forPage(ActionSurfaceProfile::ListOnlyReadOnly, ActionSurfaceType::ReadOnlyRegistryReport) ->satisfy(ActionSurfaceSlot::ListHeader, 'Header keeps alerts scope and origin navigation quiet on the page-level overview.') ->exempt(ActionSurfaceSlot::InspectAffordance, 'The alerts overview is a page-level monitoring summary and does not inspect records inline.') ->exempt(ActionSurfaceSlot::ListRowMoreMenu, 'The alerts overview does not render row-level secondary actions.') ->exempt(ActionSurfaceSlot::ListBulkMoreGroup, 'The alerts overview does not expose bulk actions.') ->exempt(ActionSurfaceSlot::ListEmptyState, 'The overview always renders KPI widgets and downstream drilldown navigation instead of a list-style empty state.'); } public static function canAccess(): bool { if (Filament::getCurrentPanel()?->getId() !== 'admin') { return false; } $user = auth()->user(); if (! $user instanceof User) { return false; } $workspaceId = app(WorkspaceContext::class)->currentWorkspaceId(request()); if (! is_int($workspaceId)) { return false; } $workspace = Workspace::query()->whereKey($workspaceId)->first(); if (! $workspace instanceof Workspace) { return false; } /** @var WorkspaceCapabilityResolver $resolver */ $resolver = app(WorkspaceCapabilityResolver::class); return $resolver->isMember($user, $workspace) && $resolver->can($user, $workspace, Capabilities::ALERTS_VIEW); } protected function getHeaderWidgets(): array { return [ AlertsKpiHeader::class, ]; } /** * @return array{label: string, clear_url: string, description: string}|null */ public function environmentFilterChip(): ?array { $filter = $this->environmentFilter(); if (! $filter instanceof WorkspaceHubEnvironmentFilter) { return null; } return [ 'label' => $filter->displayName(), 'clear_url' => $this->cleanWorkspaceHubUrl(route('filament.admin.alerts')), 'description' => 'Delivery signal is filtered. Rules and targets remain workspace configuration.', ]; } public function alertDeliveriesUrl(): string { return AlertDeliveryResource::getUrl('index', $this->filteredNavigationParameters(), panel: 'admin'); } public function alertRulesUrl(): string { return $this->cleanWorkspaceHubUrl(AlertRuleResource::getUrl(panel: 'admin')); } public function alertDestinationsUrl(): string { return $this->cleanWorkspaceHubUrl(AlertDestinationResource::getUrl(panel: 'admin')); } public function auditLogUrl(): string { return route('admin.monitoring.audit-log', $this->filteredNavigationParameters()); } /** * @return array */ protected function getHeaderActions(): array { $actions = app(OperateHubShell::class)->headerActions( scopeActionName: 'operate_hub_scope_alerts', returnActionName: 'operate_hub_return_alerts', ); $navigationContext = CanonicalNavigationContext::fromRequest(request()); if ($navigationContext?->backLinkLabel !== null && $navigationContext->backLinkUrl !== null) { array_splice($actions, 1, 0, [ Action::make('operate_hub_back_to_origin_alerts') ->label($navigationContext->backLinkLabel) ->icon('heroicon-o-arrow-left') ->color('gray') ->url($navigationContext->backLinkUrl), ]); } return $actions; } /** * @return array */ private function filteredNavigationParameters(): array { return array_filter( array_merge( $this->navigationContext()?->toQuery() ?? [], $this->environmentFilter()?->queryParameters() ?? [], ), static fn (mixed $value): bool => $value !== null && $value !== '' && $value !== [], ); } private function navigationContext(): ?CanonicalNavigationContext { return CanonicalNavigationContext::fromRequest(request()); } private function environmentFilter(): ?WorkspaceHubEnvironmentFilter { $workspace = app(WorkspaceContext::class)->currentWorkspace(request()); if (! $workspace instanceof Workspace) { return null; } return WorkspaceHubEnvironmentFilter::fromRequest(request(), $workspace); } }