fix: ComplianceAlerts API-Format Mapping

API liefert verschachteltes Format (trigger.regulation),
Frontend erwartete flaches Format. Mapping eingefuegt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-07 15:41:25 +02:00
parent 4f29e5ff3c
commit 6e71996733
@@ -86,8 +86,25 @@ export function ComplianceAlerts({ projectId }: { projectId: string }) {
fetch(`/api/sdk/v1/iace/projects/${projectId}/compliance-triggers`)
.then((r) => (r.ok ? r.json() : null))
.then((json) => {
if (json?.triggers) setData(json)
else if (Array.isArray(json)) setData({ triggers: json, total: json.length })
if (!json) return
// Map API format (nested trigger object) to flat frontend format
const raw = json.triggers || []
const mapped: ComplianceTrigger[] = raw.map((t: Record<string, unknown>, i: number) => {
const inner = (t.trigger || t) as Record<string, unknown>
const reg = (inner.regulation || '') as string
return {
id: (t.hazard_id as string) || `trigger-${i}`,
regulation: reg.split(' ')[0] || reg,
article: reg.includes(' ') ? reg.split(' ').slice(1).join(' ') : '',
title: (inner.action_de || inner.trigger_cond_de || '') as string,
severity: ((inner.severity || 'medium') as string) as 'high' | 'medium' | 'low',
reason: (inner.trigger_cond_de || '') as string,
affected_hazard_count: 1,
module_path: (inner.module_link || '/sdk') as string,
module_label: ((inner.module || 'Modul') as string).toUpperCase(),
}
})
setData({ triggers: mapped, total: mapped.length })
})
.catch(() => {})
.finally(() => setLoading(false))