// CIL[BEGIN chunk_id="useActiveSev1_module_header_1784761401" type="module_header" identity="module_header" parent="none"] // CIL[DOC-MACRO purpose="Detect whether there is an active SEV1 incident in Workbench"] // CIL[DOC-RESPONSIBILITY responsibility="Fetch workbench_work_item records and return true if any unresolved SEV1 exists"] // CIL[DOC-CONTEXT module="workbench.hooks.useActiveSev1" layer="frontend-hook" related_files="[\"custom/apps/workbench/components/Sev1Banner.tsx\",\"custom/apps/workbench/components/WorkbenchSidebar.tsx\",\"custom/apps/workbench/pages/WorkbenchDashboard.tsx\",\"custom/apps/workbench/pages/work/WorkBoardPage.tsx\"]"] // CIL[DOC-CONTRACT inputs="none" outputs="boolean indicating active SEV1" errors="fetch failures return false" side_effects="calls /api/admin-data endpoint on mount"] // CIL[DOC-MICRO logic_summary="Queries workbench_work_item items and checks for severity=sev1 with a non-resolved incident status" notable_decisions="[]"] // CIL[DOC-CONFIDENCE pass="first" score="0.9" flags="none"] // CIL[DOC-STABILITY stability="experimental"] // CIL[DOC-AUDIENCE audience="developer"] import { useEffect, useState } from 'react' import { apiFetch } from '@core/lib/api' // CIL[END chunk_id="useActiveSev1_module_header_1784761401"] // CIL[BEGIN chunk_id="useActiveSev1_useActiveSev1_1784761401" type="function" identity="useActiveSev1" parent="none"] const RESOLVED_INCIDENT_STATUSES = ['resolved', 'postmortem_complete'] function isActiveIncident(item: any): boolean { return item.data?.work_type === 'incident_followup' && !RESOLVED_INCIDENT_STATUSES.includes(item.data?.incident_status) } export function useActiveSev1(): boolean { const [active, setActive] = useState(false) useEffect(() => { let cancelled = false apiFetch('/api/admin-data?entity=items&type_slug=workbench_work_item&limit=200') .then(r => r.json()) .then(json => { if (cancelled) return const items = Array.isArray(json?.data) ? json.data : Array.isArray(json) ? json : [] const hasActiveSev1 = items.some((item: any) => item.data?.severity === 'sev1' && isActiveIncident(item) ) setActive(hasActiveSev1) }) .catch(() => setActive(false)) return () => { cancelled = true } }, []) return active } // CIL[END chunk_id="useActiveSev1_useActiveSev1_1784761401"]