*/ protected function getViewData(): array { $tenant = Filament::getTenant(); if (! $tenant instanceof Tenant) { return [ 'pollingInterval' => null, 'items' => [], 'healthyChecks' => [], ]; } $tenantId = (int) $tenant->getKey(); $aggregate = $this->governanceAggregate($tenant); $compareAssessment = $aggregate->summaryAssessment; $items = []; $overdueOpenCount = $aggregate->overdueOpenFindingsCount; $lapsedGovernanceCount = $aggregate->lapsedGovernanceCount; $expiringGovernanceCount = $aggregate->expiringGovernanceCount; $highSeverityCount = $aggregate->highSeverityActiveFindingsCount; if ($lapsedGovernanceCount > 0) { $items[] = [ 'title' => 'Lapsed accepted-risk governance', 'body' => "{$lapsedGovernanceCount} finding(s) need governance follow-up before accepted risk is safe to rely on.", 'badge' => 'Governance', 'badgeColor' => 'danger', ]; } if ($overdueOpenCount > 0) { $items[] = [ 'title' => 'Overdue findings', 'body' => "{$overdueOpenCount} open finding(s) are overdue and still need workflow follow-up.", 'badge' => 'Findings', 'badgeColor' => 'danger', ]; } if ($expiringGovernanceCount > 0) { $items[] = [ 'title' => 'Expiring accepted-risk governance', 'body' => "{$expiringGovernanceCount} finding(s) will need governance review soon.", 'badge' => 'Governance', 'badgeColor' => 'warning', ]; } if ($highSeverityCount > 0) { $items[] = [ 'title' => 'High severity active findings', 'body' => "{$highSeverityCount} active finding(s) need review.", 'badge' => 'Drift', 'badgeColor' => 'danger', ]; } if ($compareAssessment->stateFamily !== 'positive') { $items[] = [ 'title' => 'Baseline compare posture', 'body' => $compareAssessment->headline, 'supportingMessage' => $compareAssessment->supportingMessage, 'badge' => 'Baseline', 'badgeColor' => $compareAssessment->tone, 'nextStep' => $aggregate->nextActionLabel, ]; } $activeRuns = ActiveRuns::existForTenant($tenant) ? (int) \App\Models\OperationRun::query()->where('tenant_id', $tenantId)->active()->count() : 0; if ($activeRuns > 0) { $items[] = [ 'title' => 'Operations in progress', 'body' => "{$activeRuns} run(s) are active.", 'badge' => 'Operations', 'badgeColor' => 'warning', ]; } $items = array_slice($items, 0, 5); $healthyChecks = []; if ($items === []) { $healthyChecks = [ [ 'title' => 'Baseline compare looks trustworthy', 'body' => $aggregate->headline, ], [ 'title' => 'No overdue findings', 'body' => 'No open findings are currently overdue for this tenant.', ], [ 'title' => 'Accepted-risk governance is healthy', 'body' => 'No accepted-risk findings currently need governance follow-up.', ], [ 'title' => 'No high severity active findings', 'body' => 'No high severity findings are currently open for this tenant.', ], [ 'title' => 'No active operations', 'body' => 'Nothing is currently running for this tenant.', ], ]; } return [ 'pollingInterval' => ActiveRuns::existForTenant($tenant) ? '10s' : null, 'items' => $items, 'healthyChecks' => $healthyChecks, ]; } private function governanceAggregate(Tenant $tenant): TenantGovernanceAggregate { /** @var TenantGovernanceAggregateResolver $resolver */ $resolver = app(TenantGovernanceAggregateResolver::class); /** @var TenantGovernanceAggregate $aggregate */ $aggregate = $resolver->forTenant($tenant); return $aggregate; } }