*/ protected function getViewData(): array { $tenant = Filament::getTenant(); if (! $tenant instanceof Tenant) { return [ 'pollingInterval' => null, 'items' => [], 'healthyChecks' => [], ]; } $tenantId = (int) $tenant->getKey(); $compareStats = BaselineCompareStats::forTenant($tenant); $compareAssessment = $compareStats->summaryAssessment(); $items = []; $overdueOpenCount = (int) Finding::query() ->where('tenant_id', $tenantId) ->whereIn('status', Finding::openStatusesForQuery()) ->whereNotNull('due_at') ->where('due_at', '<', now()) ->count(); $lapsedGovernanceCount = (int) Finding::query() ->where('tenant_id', $tenantId) ->where('status', Finding::STATUS_RISK_ACCEPTED) ->where(function ($query): void { $query ->whereDoesntHave('findingException') ->orWhereHas('findingException', function ($exceptionQuery): void { $exceptionQuery->whereIn('current_validity_state', [ \App\Models\FindingException::VALIDITY_EXPIRED, \App\Models\FindingException::VALIDITY_REVOKED, \App\Models\FindingException::VALIDITY_REJECTED, \App\Models\FindingException::VALIDITY_MISSING_SUPPORT, ]); }); }) ->count(); $expiringGovernanceCount = (int) Finding::query() ->where('tenant_id', $tenantId) ->where('status', Finding::STATUS_RISK_ACCEPTED) ->whereHas('findingException', function ($query): void { $query->where('current_validity_state', \App\Models\FindingException::VALIDITY_EXPIRING); }) ->count(); $highSeverityCount = (int) Finding::query() ->where('tenant_id', $tenantId) ->whereIn('status', Finding::openStatusesForQuery()) ->whereIn('severity', [ Finding::SEVERITY_HIGH, Finding::SEVERITY_CRITICAL, ]) ->count(); 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' => $compareAssessment->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' => $compareAssessment->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, ]; } }