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:
@@ -86,8 +86,25 @@ export function ComplianceAlerts({ projectId }: { projectId: string }) {
|
|||||||
fetch(`/api/sdk/v1/iace/projects/${projectId}/compliance-triggers`)
|
fetch(`/api/sdk/v1/iace/projects/${projectId}/compliance-triggers`)
|
||||||
.then((r) => (r.ok ? r.json() : null))
|
.then((r) => (r.ok ? r.json() : null))
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (json?.triggers) setData(json)
|
if (!json) return
|
||||||
else if (Array.isArray(json)) setData({ triggers: json, total: json.length })
|
// 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(() => {})
|
.catch(() => {})
|
||||||
.finally(() => setLoading(false))
|
.finally(() => setLoading(false))
|
||||||
|
|||||||
Reference in New Issue
Block a user