*/ protected function getViewData(): array { $tenant = Filament::getTenant(); $empty = [ 'hasAssignment' => false, 'profileName' => null, 'findingsCount' => 0, 'highCount' => 0, 'mediumCount' => 0, 'lowCount' => 0, 'lastComparedAt' => null, 'landingUrl' => null, ]; if (! $tenant instanceof Tenant) { return $empty; } $assignment = BaselineTenantAssignment::query() ->where('tenant_id', $tenant->getKey()) ->with('baselineProfile') ->first(); if (! $assignment instanceof BaselineTenantAssignment || $assignment->baselineProfile === null) { return $empty; } $profile = $assignment->baselineProfile; $scopeKey = 'baseline_profile:'.$profile->getKey(); $findingsQuery = Finding::query() ->where('tenant_id', $tenant->getKey()) ->where('finding_type', Finding::FINDING_TYPE_DRIFT) ->where('source', 'baseline.compare') ->where('scope_key', $scopeKey) ->where('status', Finding::STATUS_NEW); $findingsCount = (int) (clone $findingsQuery)->count(); $highCount = (int) (clone $findingsQuery) ->where('severity', Finding::SEVERITY_HIGH) ->count(); $mediumCount = (int) (clone $findingsQuery) ->where('severity', Finding::SEVERITY_MEDIUM) ->count(); $lowCount = (int) (clone $findingsQuery) ->where('severity', Finding::SEVERITY_LOW) ->count(); $latestRun = OperationRun::query() ->where('tenant_id', $tenant->getKey()) ->where('type', 'baseline_compare') ->where('context->baseline_profile_id', (string) $profile->getKey()) ->whereNotNull('completed_at') ->latest('completed_at') ->first(); return [ 'hasAssignment' => true, 'profileName' => (string) $profile->name, 'findingsCount' => $findingsCount, 'highCount' => $highCount, 'mediumCount' => $mediumCount, 'lowCount' => $lowCount, 'lastComparedAt' => $latestRun?->finished_at?->diffForHumans(), 'landingUrl' => \App\Filament\Pages\BaselineCompareLanding::getUrl(tenant: $tenant), ]; } }