From 2ade65431ac7af61b0b8c4f32b3d9054e825f1f7 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 16 Apr 2026 17:10:14 +0200 Subject: [PATCH] refactor(admin): split compliance-hub, obligations, document-generator pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each page.tsx was >1000 LOC; extract components to _components/ and hooks to _hooks/ so page files stay under 500 LOC (164 / 255 / 243 respectively). Zero behavior changes β€” logic relocated verbatim. Co-Authored-By: Claude Sonnet 4.6 --- .../compliance-hub/_components/ModulesTab.tsx | 70 + .../_components/OverviewTab.tsx | 388 ++++++ .../compliance-hub/_components/RoadmapTab.tsx | 60 + .../_components/TraceabilityTab.tsx | 253 ++++ .../compliance-hub/_components/TrendTab.tsx | 104 ++ .../sdk/compliance-hub/_components/types.ts | 169 +++ .../compliance-hub/_hooks/useComplianceHub.ts | 169 ++- .../app/sdk/compliance-hub/page.tsx | 1208 +---------------- .../app/sdk/document-generator/page.tsx | 807 +---------- .../_components/ObligationDetail.tsx | 13 + .../_components/ObligationModal.tsx | 12 + .../sdk/obligations/_components/StatsGrid.tsx | 19 +- .../sdk/obligations/_hooks/useObligations.ts | 222 +++ .../app/sdk/obligations/_types.ts | 3 + admin-compliance/app/sdk/obligations/page.tsx | 1058 ++------------- 15 files changed, 1607 insertions(+), 2948 deletions(-) create mode 100644 admin-compliance/app/sdk/compliance-hub/_components/ModulesTab.tsx create mode 100644 admin-compliance/app/sdk/compliance-hub/_components/OverviewTab.tsx create mode 100644 admin-compliance/app/sdk/compliance-hub/_components/RoadmapTab.tsx create mode 100644 admin-compliance/app/sdk/compliance-hub/_components/TraceabilityTab.tsx create mode 100644 admin-compliance/app/sdk/compliance-hub/_components/TrendTab.tsx create mode 100644 admin-compliance/app/sdk/compliance-hub/_components/types.ts create mode 100644 admin-compliance/app/sdk/obligations/_hooks/useObligations.ts diff --git a/admin-compliance/app/sdk/compliance-hub/_components/ModulesTab.tsx b/admin-compliance/app/sdk/compliance-hub/_components/ModulesTab.tsx new file mode 100644 index 0000000..60374cc --- /dev/null +++ b/admin-compliance/app/sdk/compliance-hub/_components/ModulesTab.tsx @@ -0,0 +1,70 @@ +'use client' + +import type { ModuleStatusData } from './types' +import { MODULE_ICONS } from './types' + +interface ModulesTabProps { + moduleStatus: ModuleStatusData | null +} + +export function ModulesTab({ moduleStatus }: ModulesTabProps) { + if (!moduleStatus) { + return ( +
+
+
+ ) + } + + return ( + <> + {/* Summary */} +
+
+

Gesamt-Fortschritt

+

{moduleStatus.overall_progress.toFixed(0)}%

+
+
+

Module gestartet

+

{moduleStatus.started}/{moduleStatus.total}

+
+
+

Module abgeschlossen

+

{moduleStatus.complete}/{moduleStatus.total}

+
+
+ + {/* Module Grid */} +
+ {moduleStatus.modules.map(mod => ( +
+
+ {MODULE_ICONS[mod.key] || 'πŸ“¦'} +
+

{mod.label}

+

{mod.count} Eintraege

+
+ + {mod.status === 'complete' ? 'Fertig' : + mod.status === 'in_progress' ? 'In Arbeit' : 'Offen'} + +
+
+
+
+
+ ))} +
+ + ) +} diff --git a/admin-compliance/app/sdk/compliance-hub/_components/OverviewTab.tsx b/admin-compliance/app/sdk/compliance-hub/_components/OverviewTab.tsx new file mode 100644 index 0000000..402ac8e --- /dev/null +++ b/admin-compliance/app/sdk/compliance-hub/_components/OverviewTab.tsx @@ -0,0 +1,388 @@ +'use client' + +import Link from 'next/link' +import type { DashboardData, MappingsData, FindingsData, NextAction } from './types' +import { DOMAIN_LABELS } from './types' + +interface OverviewTabProps { + dashboard: DashboardData | null + mappings: MappingsData | null + findings: FindingsData | null + nextActions: NextAction[] + evidenceDistribution: { + by_confidence: Record + four_eyes_pending: number + total: number + } | null + score: number + scoreColor: string + scoreBgColor: string + loadData: () => void + regulations: Array<{ id: string; code: string; name: string; regulation_type: string; requirement_count: number }> +} + +export function OverviewTab({ + dashboard, mappings, findings, nextActions, evidenceDistribution, + score, scoreColor, scoreBgColor, loadData, regulations, +}: OverviewTabProps) { + return ( + <> + {/* Quick Actions */} +
+

Schnellzugriff

+
+ {[ + { href: '/sdk/audit-checklist', icon: 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01', label: 'Audit Checkliste', sub: `${dashboard?.total_requirements || '...'} Anforderungen`, color: 'purple' }, + { href: '/sdk/controls', icon: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z', label: 'Controls', sub: `${dashboard?.total_controls || '...'} Massnahmen`, color: 'green' }, + { href: '/sdk/evidence', icon: 'M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z', label: 'Evidence', sub: 'Nachweise', color: 'blue' }, + { href: '/sdk/risks', icon: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z', label: 'Risk Matrix', sub: '5x5 Risiken', color: 'red' }, + { href: '/sdk/process-tasks', icon: 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4', label: 'Prozesse', sub: 'Aufgaben', color: 'indigo' }, + { href: '/sdk/audit-report', icon: 'M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z', label: 'Audit Report', sub: 'PDF Export', color: 'orange' }, + ].map(item => ( + +
+ + + +
+

{item.label}

+

{item.sub}

+ + ))} +
+
+ + {/* Score and Stats Row */} +
+
+

Compliance Score

+
+ {score.toFixed(0)}% +
+
+
+
+

+ {dashboard?.controls_by_status?.pass || 0} von {dashboard?.total_controls || 0} Controls bestanden +

+
+ + {[ + { label: 'Verordnungen', value: dashboard?.total_regulations || 0, sub: `${dashboard?.total_requirements || 0} Anforderungen`, iconColor: 'blue', icon: 'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z' }, + { label: 'Controls', value: dashboard?.total_controls || 0, sub: `${dashboard?.controls_by_status?.pass || 0} bestanden`, iconColor: 'green', icon: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z' }, + { label: 'Nachweise', value: dashboard?.total_evidence || 0, sub: `${dashboard?.evidence_by_status?.valid || 0} aktiv`, iconColor: 'purple', icon: 'M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z' }, + { label: 'Risiken', value: dashboard?.total_risks || 0, sub: `${(dashboard?.risks_by_level?.high || 0) + (dashboard?.risks_by_level?.critical || 0)} kritisch`, iconColor: 'red', icon: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z' }, + ].map(stat => ( +
+
+
+

{stat.label}

+

{stat.value}

+
+
+ + + +
+
+

{stat.sub}

+
+ ))} +
+ + {/* Anti-Fake-Evidence Section (Phase 3) */} + {dashboard && ( +
+

Anti-Fake-Evidence Status

+ + {/* Confidence Distribution Bar */} + {evidenceDistribution && evidenceDistribution.total > 0 && ( +
+

Confidence-Verteilung ({evidenceDistribution.total} Nachweise)

+
+ {(['E0', 'E1', 'E2', 'E3', 'E4'] as const).map(level => { + const count = evidenceDistribution.by_confidence[level] || 0 + const pct = (count / evidenceDistribution.total) * 100 + if (pct === 0) return null + const colors: Record = { + E0: 'bg-red-400', E1: 'bg-yellow-400', E2: 'bg-blue-400', E3: 'bg-green-400', E4: 'bg-emerald-400' + } + return ( +
+ {pct >= 10 ? `${level} (${count})` : ''} +
+ ) + })} +
+
+ {(['E0', 'E1', 'E2', 'E3', 'E4'] as const).map(level => { + const count = evidenceDistribution.by_confidence[level] || 0 + const dotColors: Record = { + E0: 'bg-red-400', E1: 'bg-yellow-400', E2: 'bg-blue-400', E3: 'bg-green-400', E4: 'bg-emerald-400' + } + return ( + + + {level}: {count} + + ) + })} +
+
+ )} + + {/* Multi-Score Dimensions */} + {dashboard.multi_score && ( +
+

Multi-dimensionaler Score

+
+ {([ + { key: 'requirement_coverage', label: 'Anforderungsabdeckung', color: 'bg-blue-500' }, + { key: 'evidence_strength', label: 'Evidence-Staerke', color: 'bg-green-500' }, + { key: 'validation_quality', label: 'Validierungsqualitaet', color: 'bg-purple-500' }, + { key: 'evidence_freshness', label: 'Aktualitaet', color: 'bg-yellow-500' }, + { key: 'control_effectiveness', label: 'Control-Wirksamkeit', color: 'bg-indigo-500' }, + ] as const).map(dim => { + const value = (dashboard.multi_score as Record)[dim.key] || 0 + return ( +
+ {dim.label} +
+
+
+ {typeof value === 'number' ? value.toFixed(0) : value}% +
+ ) + })} +
+ Audit-Readiness +
+
= 80 ? 'bg-green-500' : + (dashboard.multi_score.overall_readiness || 0) >= 60 ? 'bg-yellow-500' : 'bg-red-500' + }`} style={{ width: `${dashboard.multi_score.overall_readiness || 0}%` }} /> +
+ + {typeof dashboard.multi_score.overall_readiness === 'number' ? dashboard.multi_score.overall_readiness.toFixed(0) : 0}% + +
+
+
+ )} + + {/* Bottom row: Four-Eyes + Hard Blocks */} +
+
+
{evidenceDistribution?.four_eyes_pending || 0}
+
Four-Eyes Reviews ausstehend
+
+ {dashboard.multi_score?.hard_blocks && dashboard.multi_score.hard_blocks.length > 0 ? ( +
+
Hard Blocks ({dashboard.multi_score.hard_blocks.length})
+
    + {dashboard.multi_score.hard_blocks.slice(0, 3).map((block: string, i: number) => ( +
  • + + {block} +
  • + ))} +
+
+ ) : ( +
+
0
+
Keine Hard Blocks
+
+ )} +
+
+ )} + + {/* Next Actions + Findings */} +
+ {/* Next Actions */} +
+

Naechste Aktionen

+ {nextActions.length === 0 ? ( +

Keine offenen Aktionen.

+ ) : ( +
+ {nextActions.map(action => ( +
+
0 ? 'bg-red-500' : 'bg-yellow-500' + }`} /> +
+

{action.title}

+

+ {action.control_id} Β· {DOMAIN_LABELS[action.domain] || action.domain} + {action.days_overdue > 0 && {action.days_overdue}d ueberfaellig} +

+
+ + {action.status} + +
+ ))} +
+ )} +
+ + {/* Audit Findings */} +
+
+

Audit Findings

+ + Audit Checkliste β†’ + +
+
+
+
+
+ Hauptabweichungen +
+

{findings?.open_majors || 0}

+

offen (blockiert Zertifizierung)

+
+
+
+
+ Nebenabweichungen +
+

{findings?.open_minors || 0}

+

offen (erfordert CAPA)

+
+
+
+ + Gesamt: {findings?.total || 0} Findings ({findings?.major_count || 0} Major, {findings?.minor_count || 0} Minor, {findings?.ofi_count || 0} OFI) + + {(findings?.open_majors || 0) === 0 ? ( + + Zertifizierung moeglich + + ) : ( + + Zertifizierung blockiert + + )} +
+
+
+ + {/* Control-Mappings & Domain Chart */} +
+
+
+

Control-Mappings

+ + Alle anzeigen β†’ + +
+
+
+

{mappings?.total || 0}

+

Mappings gesamt

+
+
+

Nach Verordnung

+
+ {mappings?.by_regulation && Object.entries(mappings.by_regulation).slice(0, 5).map(([reg, count]) => ( + + {reg}: {count} + + ))} + {!mappings?.by_regulation && ( + Keine Mappings vorhanden + )} +
+
+
+
+ +
+

Controls nach Domain

+
+ {Object.entries(dashboard?.controls_by_domain || {}).slice(0, 6).map(([domain, stats]) => { + const total = stats.total || 0 + const pass = stats.pass || 0 + const partial = stats.partial || 0 + const passPercent = total > 0 ? ((pass + partial * 0.5) / total) * 100 : 0 + + return ( +
+ + {DOMAIN_LABELS[domain] || domain} + +
+
+
+
+ {passPercent.toFixed(0)}% +
+ ) + })} +
+
+
+ + {/* Regulations Table */} +
+
+

Verordnungen & Standards ({regulations.length})

+ +
+
+ + + + + + + + + + + {regulations.slice(0, 15).map((reg) => ( + + + + + + + ))} + +
CodeNameTypAnforderungen
+ {reg.code} + +

{reg.name}

+
+ + {reg.regulation_type === 'eu_regulation' ? 'EU-VO' : + reg.regulation_type === 'eu_directive' ? 'EU-RL' : + reg.regulation_type === 'bsi_standard' ? 'BSI' : + reg.regulation_type === 'de_law' ? 'DE' : reg.regulation_type} + + + {reg.requirement_count} +
+
+
+ + ) +} diff --git a/admin-compliance/app/sdk/compliance-hub/_components/RoadmapTab.tsx b/admin-compliance/app/sdk/compliance-hub/_components/RoadmapTab.tsx new file mode 100644 index 0000000..cd94274 --- /dev/null +++ b/admin-compliance/app/sdk/compliance-hub/_components/RoadmapTab.tsx @@ -0,0 +1,60 @@ +'use client' + +import type { RoadmapData } from './types' +import { BUCKET_LABELS, DOMAIN_LABELS } from './types' + +interface RoadmapTabProps { + roadmap: RoadmapData | null +} + +export function RoadmapTab({ roadmap }: RoadmapTabProps) { + if (!roadmap) { + return ( +
+
+
+ ) + } + + return ( +
+ {(['quick_wins', 'must_have', 'should_have', 'nice_to_have'] as const).map(bucketKey => { + const meta = BUCKET_LABELS[bucketKey] + const items = roadmap.buckets[bucketKey] || [] + + return ( +
+
+

{meta.label}

+ + {items.length} + +
+
+ {items.length === 0 ? ( +

Keine Eintraege

+ ) : ( + items.map(item => ( +
+

{item.title}

+
+ {item.control_id} + Β· + {DOMAIN_LABELS[item.domain] || item.domain} +
+ {item.days_overdue > 0 && ( +

{item.days_overdue}d ueberfaellig

+ )} + {item.owner && ( +

{item.owner}

+ )} +
+ )) + )} +
+
+ ) + })} +
+ ) +} diff --git a/admin-compliance/app/sdk/compliance-hub/_components/TraceabilityTab.tsx b/admin-compliance/app/sdk/compliance-hub/_components/TraceabilityTab.tsx new file mode 100644 index 0000000..b85dd7f --- /dev/null +++ b/admin-compliance/app/sdk/compliance-hub/_components/TraceabilityTab.tsx @@ -0,0 +1,253 @@ +'use client' + +import { ConfidenceLevelBadge } from '../../evidence/components/anti-fake-badges' +import type { TraceabilityMatrixData } from './types' +import { DOMAIN_LABELS } from './types' + +interface TraceabilityTabProps { + traceabilityMatrix: TraceabilityMatrixData | null + traceabilityLoading: boolean + traceabilityFilter: 'all' | 'covered' | 'uncovered' | 'fully_verified' + setTraceabilityFilter: (f: 'all' | 'covered' | 'uncovered' | 'fully_verified') => void + traceabilityDomainFilter: string + setTraceabilityDomainFilter: (d: string) => void + expandedControls: Set + expandedEvidence: Set + toggleControlExpanded: (id: string) => void + toggleEvidenceExpanded: (id: string) => void +} + +export function TraceabilityTab({ + traceabilityMatrix, traceabilityLoading, + traceabilityFilter, setTraceabilityFilter, + traceabilityDomainFilter, setTraceabilityDomainFilter, + expandedControls, expandedEvidence, + toggleControlExpanded, toggleEvidenceExpanded, +}: TraceabilityTabProps) { + if (traceabilityLoading) { + return ( +
+
+ Traceability Matrix wird geladen... +
+ ) + } + + if (!traceabilityMatrix) { + return ( +
+ Keine Daten verfuegbar. Stellen Sie sicher, dass Controls und Evidence vorhanden sind. +
+ ) + } + + const summary = traceabilityMatrix.summary + const totalControls = summary.total_controls || 0 + const covered = summary.covered || 0 + const fullyVerified = summary.fully_verified || 0 + const uncovered = summary.uncovered || 0 + + const filteredControls = (traceabilityMatrix.controls || []).filter(ctrl => { + if (traceabilityFilter === 'covered' && !ctrl.coverage.has_evidence) return false + if (traceabilityFilter === 'uncovered' && ctrl.coverage.has_evidence) return false + if (traceabilityFilter === 'fully_verified' && !ctrl.coverage.all_assertions_verified) return false + if (traceabilityDomainFilter !== 'all' && ctrl.domain !== traceabilityDomainFilter) return false + return true + }) + + const domains = [...new Set(traceabilityMatrix.controls.map(c => c.domain))].sort() + + return ( +
+ {/* Summary Cards */} +
+
+
{totalControls}
+
Total Controls
+
+
+
{covered}
+
Abgedeckt
+
+
+
{fullyVerified}
+
Vollst. verifiziert
+
+
+
{uncovered}
+
Unabgedeckt
+
+
+ + {/* Filter Bar */} +
+
+ {([ + { key: 'all', label: 'Alle' }, + { key: 'covered', label: 'Abgedeckt' }, + { key: 'uncovered', label: 'Nicht abgedeckt' }, + { key: 'fully_verified', label: 'Vollst. verifiziert' }, + ] as const).map(f => ( + + ))} +
+
+
+ + {domains.map(d => ( + + ))} +
+
+ + {/* Controls List */} +
+ {filteredControls.length === 0 ? ( +
+ Keine Controls fuer diesen Filter gefunden. +
+ ) : filteredControls.map(ctrl => { + const isExpanded = expandedControls.has(ctrl.id) + const coverageIcon = ctrl.coverage.all_assertions_verified + ? { symbol: '\u2713', color: 'text-green-600 bg-green-50' } + : ctrl.coverage.has_evidence + ? { symbol: '\u25D0', color: 'text-yellow-600 bg-yellow-50' } + : { symbol: '\u2717', color: 'text-red-600 bg-red-50' } + + return ( +
+ {/* Control Row */} + + + {/* Expanded: Evidence list */} + {isExpanded && ( +
+ {ctrl.evidence.length === 0 ? ( +
+ Kein Evidence verknuepft. +
+ ) : ctrl.evidence.map(ev => { + const evExpanded = expandedEvidence.has(ev.id) + return ( +
+ + + {/* Expanded: Assertions list */} + {evExpanded && ev.assertions.length > 0 && ( +
+ + + + + + + + + + + {ev.assertions.map(a => ( + + + + + + + ))} + +
AussageTypKonfidenzStatus
{a.sentence_text}{a.assertion_type} + = 0.8 ? 'text-green-600' + : a.confidence >= 0.5 ? 'text-yellow-600' + : 'text-red-600' + }`}> + {(a.confidence * 100).toFixed(0)}% + + + {a.verified + ? {'\u2713'} + : {'\u2717'} + } +
+
+ )} +
+ ) + })} +
+ )} +
+ ) + })} +
+
+ ) +} diff --git a/admin-compliance/app/sdk/compliance-hub/_components/TrendTab.tsx b/admin-compliance/app/sdk/compliance-hub/_components/TrendTab.tsx new file mode 100644 index 0000000..e35d3c7 --- /dev/null +++ b/admin-compliance/app/sdk/compliance-hub/_components/TrendTab.tsx @@ -0,0 +1,104 @@ +'use client' + +import type { ScoreSnapshot } from './types' + +interface TrendTabProps { + scoreHistory: ScoreSnapshot[] + savingSnapshot: boolean + saveSnapshot: () => Promise +} + +export function TrendTab({ scoreHistory, savingSnapshot, saveSnapshot }: TrendTabProps) { + return ( +
+
+

Score-Verlauf

+ +
+ + {scoreHistory.length === 0 ? ( +
+

Noch keine Score-Snapshots vorhanden.

+

Klicken Sie auf "Aktuellen Score speichern", um den ersten Datenpunkt zu erstellen.

+
+ ) : ( + <> + {/* Simple SVG Line Chart */} +
+ + {/* Grid lines */} + {[0, 25, 50, 75, 100].map(pct => ( + + ))} + {/* Score line */} + { + const x = scoreHistory.length === 1 ? 400 : (i / (scoreHistory.length - 1)) * 780 + 10 + const y = 200 - (s.score / 100) * 200 + return `${x},${y}` + }).join(' ')} + /> + {/* Points */} + {scoreHistory.map((s, i) => { + const x = scoreHistory.length === 1 ? 400 : (i / (scoreHistory.length - 1)) * 780 + 10 + const y = 200 - (s.score / 100) * 200 + return ( + + ) + })} + + {/* Y-axis labels */} +
+ 100% + 75% + 50% + 25% + 0% +
+
+ + {/* Snapshot Table */} +
+ + + + + + + + + + + {scoreHistory.slice().reverse().map(snap => ( + + + + + + + ))} + +
DatumScoreControlsBestanden
{new Date(snap.snapshot_date).toLocaleDateString('de-DE')} + = 80 ? 'text-green-600' : snap.score >= 60 ? 'text-yellow-600' : 'text-red-600' + }`}> + {typeof snap.score === 'number' ? snap.score.toFixed(1) : snap.score}% + + {snap.controls_total}{snap.controls_pass}
+
+ + )} +
+ ) +} diff --git a/admin-compliance/app/sdk/compliance-hub/_components/types.ts b/admin-compliance/app/sdk/compliance-hub/_components/types.ts new file mode 100644 index 0000000..8b11ccb --- /dev/null +++ b/admin-compliance/app/sdk/compliance-hub/_components/types.ts @@ -0,0 +1,169 @@ +// Shared types for Compliance Hub + +export interface DashboardData { + compliance_score: number + total_regulations: number + total_requirements: number + total_controls: number + controls_by_status: Record + controls_by_domain: Record> + total_evidence: number + evidence_by_status: Record + total_risks: number + risks_by_level: Record + multi_score?: { + requirement_coverage: number + evidence_strength: number + validation_quality: number + evidence_freshness: number + control_effectiveness: number + overall_readiness: number + hard_blocks: string[] + } | null +} + +export interface Regulation { + id: string + code: string + name: string + full_name: string + regulation_type: string + effective_date: string | null + description: string + requirement_count: number +} + +export interface MappingsData { + total: number + by_regulation: Record +} + +export interface FindingsData { + major_count: number + minor_count: number + ofi_count: number + total: number + open_majors: number + open_minors: number +} + +export interface RoadmapItem { + id: string + control_id: string + title: string + status: string + domain: string + owner: string | null + next_review_at: string | null + days_overdue: number + weight: number +} + +export interface RoadmapData { + buckets: Record + counts: Record +} + +export interface ModuleInfo { + key: string + label: string + count: number + status: string + progress: number +} + +export interface ModuleStatusData { + modules: ModuleInfo[] + total: number + started: number + complete: number + overall_progress: number +} + +export interface NextAction { + id: string + control_id: string + title: string + status: string + domain: string + owner: string | null + days_overdue: number + urgency_score: number + reason: string +} + +export interface ScoreSnapshot { + id: string + score: number + controls_total: number + controls_pass: number + snapshot_date: string + created_at: string +} + +export interface TraceabilityAssertion { + id: string + sentence_text: string + assertion_type: string + confidence: number + verified: boolean +} + +export interface TraceabilityEvidence { + id: string + title: string + evidence_type: string + confidence_level: string + status: string + assertions: TraceabilityAssertion[] +} + +export interface TraceabilityCoverage { + has_evidence: boolean + has_assertions: boolean + all_assertions_verified: boolean + min_confidence_level: string | null +} + +export interface TraceabilityControl { + id: string + control_id: string + title: string + status: string + domain: string + evidence: TraceabilityEvidence[] + coverage: TraceabilityCoverage +} + +export interface TraceabilityMatrixData { + controls: TraceabilityControl[] + summary: Record +} + +export type TabKey = 'overview' | 'roadmap' | 'modules' | 'trend' | 'traceability' + +export const DOMAIN_LABELS: Record = { + gov: 'Governance', + priv: 'Datenschutz', + iam: 'Identity & Access', + crypto: 'Kryptografie', + sdlc: 'Secure Dev', + ops: 'Operations', + ai: 'KI-spezifisch', + cra: 'Supply Chain', + aud: 'Audit', +} + +export const BUCKET_LABELS: Record = { + quick_wins: { label: 'Quick Wins', color: 'text-green-700', bg: 'bg-green-50 border-green-200' }, + must_have: { label: 'Must Have', color: 'text-red-700', bg: 'bg-red-50 border-red-200' }, + should_have: { label: 'Should Have', color: 'text-yellow-700', bg: 'bg-yellow-50 border-yellow-200' }, + nice_to_have: { label: 'Nice to Have', color: 'text-slate-700', bg: 'bg-slate-50 border-slate-200' }, +} + +export const MODULE_ICONS: Record = { + vvt: 'πŸ“‹', tom: 'πŸ”’', dsfa: '⚠️', loeschfristen: 'πŸ—‘οΈ', risks: '🎯', + controls: 'βœ…', evidence: 'πŸ“Ž', obligations: 'πŸ“œ', incidents: '🚨', + vendor: '🀝', legal_templates: 'πŸ“„', training: 'πŸŽ“', audit: 'πŸ”', + security_backlog: 'πŸ›‘οΈ', quality: '⭐', +} diff --git a/admin-compliance/app/sdk/compliance-hub/_hooks/useComplianceHub.ts b/admin-compliance/app/sdk/compliance-hub/_hooks/useComplianceHub.ts index 5e347ef..2525072 100644 --- a/admin-compliance/app/sdk/compliance-hub/_hooks/useComplianceHub.ts +++ b/admin-compliance/app/sdk/compliance-hub/_hooks/useComplianceHub.ts @@ -1,84 +1,78 @@ 'use client' import { useState, useEffect } from 'react' - -export interface DashboardData { - compliance_score: number - total_regulations: number - total_requirements: number - total_controls: number - controls_by_status: Record - controls_by_domain: Record> - total_evidence: number - evidence_by_status: Record - total_risks: number - risks_by_level: Record -} - -export interface Regulation { - id: string - code: string - name: string - full_name: string - regulation_type: string - effective_date: string | null - description: string - requirement_count: number -} - -export interface MappingsData { - total: number - by_regulation: Record -} - -export interface FindingsData { - major_count: number - minor_count: number - ofi_count: number - total: number - open_majors: number - open_minors: number -} +import type { + DashboardData, Regulation, MappingsData, FindingsData, + RoadmapData, ModuleStatusData, NextAction, ScoreSnapshot, + TraceabilityMatrixData, TabKey, +} from '../_components/types' export function useComplianceHub() { + const [activeTab, setActiveTab] = useState('overview') const [dashboard, setDashboard] = useState(null) const [regulations, setRegulations] = useState([]) const [mappings, setMappings] = useState(null) const [findings, setFindings] = useState(null) + const [roadmap, setRoadmap] = useState(null) + const [moduleStatus, setModuleStatus] = useState(null) + const [nextActions, setNextActions] = useState([]) + const [scoreHistory, setScoreHistory] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [seeding, setSeeding] = useState(false) + const [savingSnapshot, setSavingSnapshot] = useState(false) + const [evidenceDistribution, setEvidenceDistribution] = useState<{ + by_confidence: Record + four_eyes_pending: number + total: number + } | null>(null) + const [traceabilityMatrix, setTraceabilityMatrix] = useState(null) + const [traceabilityLoading, setTraceabilityLoading] = useState(false) + const [traceabilityFilter, setTraceabilityFilter] = useState<'all' | 'covered' | 'uncovered' | 'fully_verified'>('all') + const [traceabilityDomainFilter, setTraceabilityDomainFilter] = useState('all') + const [expandedControls, setExpandedControls] = useState>(new Set()) + const [expandedEvidence, setExpandedEvidence] = useState>(new Set()) useEffect(() => { loadData() }, []) + useEffect(() => { + if (activeTab === 'roadmap' && !roadmap) loadRoadmap() + if (activeTab === 'modules' && !moduleStatus) loadModuleStatus() + if (activeTab === 'trend' && scoreHistory.length === 0) loadScoreHistory() + if (activeTab === 'traceability' && !traceabilityMatrix) loadTraceabilityMatrix() + }, [activeTab]) // eslint-disable-line react-hooks/exhaustive-deps + const loadData = async () => { setLoading(true) setError(null) try { - const [dashboardRes, regulationsRes, mappingsRes, findingsRes] = await Promise.all([ + const [dashboardRes, regulationsRes, mappingsRes, findingsRes, actionsRes] = await Promise.all([ fetch('/api/sdk/v1/compliance/dashboard'), fetch('/api/sdk/v1/compliance/regulations'), fetch('/api/sdk/v1/compliance/mappings'), fetch('/api/sdk/v1/isms/findings?status=open'), + fetch('/api/sdk/v1/compliance/dashboard/next-actions?limit=5'), ]) - if (dashboardRes.ok) { - setDashboard(await dashboardRes.json()) - } + if (dashboardRes.ok) setDashboard(await dashboardRes.json()) if (regulationsRes.ok) { const data = await regulationsRes.json() setRegulations(data.regulations || []) } - if (mappingsRes.ok) { - const data = await mappingsRes.json() - setMappings(data) - } - if (findingsRes.ok) { - const data = await findingsRes.json() - setFindings(data) + if (mappingsRes.ok) setMappings(await mappingsRes.json()) + if (findingsRes.ok) setFindings(await findingsRes.json()) + if (actionsRes.ok) { + const data = await actionsRes.json() + setNextActions(data.actions || []) } + + // Evidence distribution (Anti-Fake-Evidence Phase 3) + try { + const evidenceDistRes = await fetch('/api/sdk/v1/compliance/dashboard/evidence-distribution') + if (evidenceDistRes.ok) setEvidenceDistribution(await evidenceDistRes.json()) + } catch { /* silent */ } } catch (err) { console.error('Failed to load compliance data:', err) setError('Verbindung zum Backend fehlgeschlagen') @@ -87,6 +81,66 @@ export function useComplianceHub() { } } + const loadRoadmap = async () => { + try { + const res = await fetch('/api/sdk/v1/compliance/dashboard/roadmap') + if (res.ok) setRoadmap(await res.json()) + } catch { /* silent */ } + } + + const loadModuleStatus = async () => { + try { + const res = await fetch('/api/sdk/v1/compliance/dashboard/module-status') + if (res.ok) setModuleStatus(await res.json()) + } catch { /* silent */ } + } + + const loadScoreHistory = async () => { + try { + const res = await fetch('/api/sdk/v1/compliance/dashboard/score-history?months=12') + if (res.ok) { + const data = await res.json() + setScoreHistory(data.snapshots || []) + } + } catch { /* silent */ } + } + + const loadTraceabilityMatrix = async () => { + setTraceabilityLoading(true) + try { + const res = await fetch('/api/sdk/v1/compliance/dashboard/traceability-matrix') + if (res.ok) setTraceabilityMatrix(await res.json()) + } catch { /* silent */ } + finally { setTraceabilityLoading(false) } + } + + const toggleControlExpanded = (id: string) => { + setExpandedControls(prev => { + const next = new Set(prev) + if (next.has(id)) next.delete(id); else next.add(id) + return next + }) + } + + const toggleEvidenceExpanded = (id: string) => { + setExpandedEvidence(prev => { + const next = new Set(prev) + if (next.has(id)) next.delete(id); else next.add(id) + return next + }) + } + + const saveSnapshot = async () => { + setSavingSnapshot(true) + try { + const res = await fetch('/api/sdk/v1/compliance/dashboard/snapshot', { method: 'POST' }) + if (res.ok) { + loadScoreHistory() + } + } catch { /* silent */ } + finally { setSavingSnapshot(false) } + } + const seedDatabase = async () => { setSeeding(true) try { @@ -101,8 +155,8 @@ export function useComplianceHub() { alert(`Datenbank erfolgreich initialisiert!\n\nRegulations: ${result.counts?.regulations || 0}\nControls: ${result.counts?.controls || 0}\nRequirements: ${result.counts?.requirements || 0}`) loadData() } else { - const errorText = await res.text() - alert(`Fehler beim Seeding: ${errorText}`) + const error = await res.text() + alert(`Fehler beim Seeding: ${error}`) } } catch (err) { console.error('Seeding failed:', err) @@ -112,5 +166,16 @@ export function useComplianceHub() { } } - return { dashboard, regulations, mappings, findings, loading, error, seeding, loadData, seedDatabase } + return { + activeTab, setActiveTab, + dashboard, regulations, mappings, findings, + roadmap, moduleStatus, nextActions, scoreHistory, + loading, error, seeding, savingSnapshot, + evidenceDistribution, traceabilityMatrix, traceabilityLoading, + traceabilityFilter, setTraceabilityFilter, + traceabilityDomainFilter, setTraceabilityDomainFilter, + expandedControls, expandedEvidence, + loadData, saveSnapshot, seedDatabase, + toggleControlExpanded, toggleEvidenceExpanded, + } } diff --git a/admin-compliance/app/sdk/compliance-hub/page.tsx b/admin-compliance/app/sdk/compliance-hub/page.tsx index e87e350..3b5dd62 100644 --- a/admin-compliance/app/sdk/compliance-hub/page.tsx +++ b/admin-compliance/app/sdk/compliance-hub/page.tsx @@ -8,352 +8,32 @@ * - Roadmap: 4-column Kanban (Quick Wins / Must Have / Should Have / Nice to Have) * - Module: Grid with module cards + progress bars * - Trend: Score history chart + * - Traceability: Evidence traceability matrix */ -import { useState, useEffect } from 'react' -import Link from 'next/link' -import { ConfidenceLevelBadge } from '../evidence/components/anti-fake-badges' +import { useComplianceHub } from './_hooks/useComplianceHub' +import { OverviewTab } from './_components/OverviewTab' +import { RoadmapTab } from './_components/RoadmapTab' +import { ModulesTab } from './_components/ModulesTab' +import { TrendTab } from './_components/TrendTab' +import { TraceabilityTab } from './_components/TraceabilityTab' +import type { TabKey } from './_components/types' -// Types -interface DashboardData { - compliance_score: number - total_regulations: number - total_requirements: number - total_controls: number - controls_by_status: Record - controls_by_domain: Record> - total_evidence: number - evidence_by_status: Record - total_risks: number - risks_by_level: Record - multi_score?: { - requirement_coverage: number - evidence_strength: number - validation_quality: number - evidence_freshness: number - control_effectiveness: number - overall_readiness: number - hard_blocks: string[] - } | null -} - -interface Regulation { - id: string - code: string - name: string - full_name: string - regulation_type: string - effective_date: string | null - description: string - requirement_count: number -} - -interface MappingsData { - total: number - by_regulation: Record -} - -interface FindingsData { - major_count: number - minor_count: number - ofi_count: number - total: number - open_majors: number - open_minors: number -} - -interface RoadmapItem { - id: string - control_id: string - title: string - status: string - domain: string - owner: string | null - next_review_at: string | null - days_overdue: number - weight: number -} - -interface RoadmapData { - buckets: Record - counts: Record -} - -interface ModuleInfo { - key: string - label: string - count: number - status: string - progress: number -} - -interface ModuleStatusData { - modules: ModuleInfo[] - total: number - started: number - complete: number - overall_progress: number -} - -interface NextAction { - id: string - control_id: string - title: string - status: string - domain: string - owner: string | null - days_overdue: number - urgency_score: number - reason: string -} - -interface ScoreSnapshot { - id: string - score: number - controls_total: number - controls_pass: number - snapshot_date: string - created_at: string -} - -interface TraceabilityAssertion { - id: string - sentence_text: string - assertion_type: string - confidence: number - verified: boolean -} - -interface TraceabilityEvidence { - id: string - title: string - evidence_type: string - confidence_level: string - status: string - assertions: TraceabilityAssertion[] -} - -interface TraceabilityCoverage { - has_evidence: boolean - has_assertions: boolean - all_assertions_verified: boolean - min_confidence_level: string | null -} - -interface TraceabilityControl { - id: string - control_id: string - title: string - status: string - domain: string - evidence: TraceabilityEvidence[] - coverage: TraceabilityCoverage -} - -interface TraceabilityMatrixData { - controls: TraceabilityControl[] - summary: Record -} - -type TabKey = 'overview' | 'roadmap' | 'modules' | 'trend' | 'traceability' - -const DOMAIN_LABELS: Record = { - gov: 'Governance', - priv: 'Datenschutz', - iam: 'Identity & Access', - crypto: 'Kryptografie', - sdlc: 'Secure Dev', - ops: 'Operations', - ai: 'KI-spezifisch', - cra: 'Supply Chain', - aud: 'Audit', -} - -const BUCKET_LABELS: Record = { - quick_wins: { label: 'Quick Wins', color: 'text-green-700', bg: 'bg-green-50 border-green-200' }, - must_have: { label: 'Must Have', color: 'text-red-700', bg: 'bg-red-50 border-red-200' }, - should_have: { label: 'Should Have', color: 'text-yellow-700', bg: 'bg-yellow-50 border-yellow-200' }, - nice_to_have: { label: 'Nice to Have', color: 'text-slate-700', bg: 'bg-slate-50 border-slate-200' }, -} - -const MODULE_ICONS: Record = { - vvt: 'πŸ“‹', tom: 'πŸ”’', dsfa: '⚠️', loeschfristen: 'πŸ—‘οΈ', risks: '🎯', - controls: 'βœ…', evidence: 'πŸ“Ž', obligations: 'πŸ“œ', incidents: '🚨', - vendor: '🀝', legal_templates: 'πŸ“„', training: 'πŸŽ“', audit: 'πŸ”', - security_backlog: 'πŸ›‘οΈ', quality: '⭐', -} +const tabs: { key: TabKey; label: string }[] = [ + { key: 'overview', label: 'Uebersicht' }, + { key: 'roadmap', label: 'Roadmap' }, + { key: 'modules', label: 'Module' }, + { key: 'trend', label: 'Trend' }, + { key: 'traceability', label: 'Traceability' }, +] export default function ComplianceHubPage() { - const [activeTab, setActiveTab] = useState('overview') - const [dashboard, setDashboard] = useState(null) - const [regulations, setRegulations] = useState([]) - const [mappings, setMappings] = useState(null) - const [findings, setFindings] = useState(null) - const [roadmap, setRoadmap] = useState(null) - const [moduleStatus, setModuleStatus] = useState(null) - const [nextActions, setNextActions] = useState([]) - const [scoreHistory, setScoreHistory] = useState([]) - const [loading, setLoading] = useState(true) - const [error, setError] = useState(null) - const [seeding, setSeeding] = useState(false) - const [savingSnapshot, setSavingSnapshot] = useState(false) - const [evidenceDistribution, setEvidenceDistribution] = useState<{ - by_confidence: Record - four_eyes_pending: number - total: number - } | null>(null) - const [traceabilityMatrix, setTraceabilityMatrix] = useState(null) - const [traceabilityLoading, setTraceabilityLoading] = useState(false) - const [traceabilityFilter, setTraceabilityFilter] = useState<'all' | 'covered' | 'uncovered' | 'fully_verified'>('all') - const [traceabilityDomainFilter, setTraceabilityDomainFilter] = useState('all') - const [expandedControls, setExpandedControls] = useState>(new Set()) - const [expandedEvidence, setExpandedEvidence] = useState>(new Set()) + const hub = useComplianceHub() - useEffect(() => { - loadData() - }, []) - - useEffect(() => { - if (activeTab === 'roadmap' && !roadmap) loadRoadmap() - if (activeTab === 'modules' && !moduleStatus) loadModuleStatus() - if (activeTab === 'trend' && scoreHistory.length === 0) loadScoreHistory() - if (activeTab === 'traceability' && !traceabilityMatrix) loadTraceabilityMatrix() - }, [activeTab]) // eslint-disable-line react-hooks/exhaustive-deps - - const loadData = async () => { - setLoading(true) - setError(null) - try { - const [dashboardRes, regulationsRes, mappingsRes, findingsRes, actionsRes] = await Promise.all([ - fetch('/api/sdk/v1/compliance/dashboard'), - fetch('/api/sdk/v1/compliance/regulations'), - fetch('/api/sdk/v1/compliance/mappings'), - fetch('/api/sdk/v1/isms/findings?status=open'), - fetch('/api/sdk/v1/compliance/dashboard/next-actions?limit=5'), - ]) - - if (dashboardRes.ok) setDashboard(await dashboardRes.json()) - if (regulationsRes.ok) { - const data = await regulationsRes.json() - setRegulations(data.regulations || []) - } - if (mappingsRes.ok) setMappings(await mappingsRes.json()) - if (findingsRes.ok) setFindings(await findingsRes.json()) - if (actionsRes.ok) { - const data = await actionsRes.json() - setNextActions(data.actions || []) - } - - // Evidence distribution (Anti-Fake-Evidence Phase 3) - try { - const evidenceDistRes = await fetch('/api/sdk/v1/compliance/dashboard/evidence-distribution') - if (evidenceDistRes.ok) setEvidenceDistribution(await evidenceDistRes.json()) - } catch { /* silent */ } - } catch (err) { - console.error('Failed to load compliance data:', err) - setError('Verbindung zum Backend fehlgeschlagen') - } finally { - setLoading(false) - } - } - - const loadRoadmap = async () => { - try { - const res = await fetch('/api/sdk/v1/compliance/dashboard/roadmap') - if (res.ok) setRoadmap(await res.json()) - } catch { /* silent */ } - } - - const loadModuleStatus = async () => { - try { - const res = await fetch('/api/sdk/v1/compliance/dashboard/module-status') - if (res.ok) setModuleStatus(await res.json()) - } catch { /* silent */ } - } - - const loadScoreHistory = async () => { - try { - const res = await fetch('/api/sdk/v1/compliance/dashboard/score-history?months=12') - if (res.ok) { - const data = await res.json() - setScoreHistory(data.snapshots || []) - } - } catch { /* silent */ } - } - - const loadTraceabilityMatrix = async () => { - setTraceabilityLoading(true) - try { - const res = await fetch('/api/sdk/v1/compliance/dashboard/traceability-matrix') - if (res.ok) setTraceabilityMatrix(await res.json()) - } catch { /* silent */ } - finally { setTraceabilityLoading(false) } - } - - const toggleControlExpanded = (id: string) => { - setExpandedControls(prev => { - const next = new Set(prev) - if (next.has(id)) next.delete(id); else next.add(id) - return next - }) - } - - const toggleEvidenceExpanded = (id: string) => { - setExpandedEvidence(prev => { - const next = new Set(prev) - if (next.has(id)) next.delete(id); else next.add(id) - return next - }) - } - - const saveSnapshot = async () => { - setSavingSnapshot(true) - try { - const res = await fetch('/api/sdk/v1/compliance/dashboard/snapshot', { method: 'POST' }) - if (res.ok) { - loadScoreHistory() - } - } catch { /* silent */ } - finally { setSavingSnapshot(false) } - } - - const seedDatabase = async () => { - setSeeding(true) - try { - const res = await fetch('/api/sdk/v1/compliance/seed', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ force: false }), - }) - - if (res.ok) { - const result = await res.json() - alert(`Datenbank erfolgreich initialisiert!\n\nRegulations: ${result.counts?.regulations || 0}\nControls: ${result.counts?.controls || 0}\nRequirements: ${result.counts?.requirements || 0}`) - loadData() - } else { - const error = await res.text() - alert(`Fehler beim Seeding: ${error}`) - } - } catch (err) { - console.error('Seeding failed:', err) - alert('Fehler beim Initialisieren der Datenbank') - } finally { - setSeeding(false) - } - } - - const score = dashboard?.compliance_score || 0 + const score = hub.dashboard?.compliance_score || 0 const scoreColor = score >= 80 ? 'text-green-600' : score >= 60 ? 'text-yellow-600' : 'text-red-600' const scoreBgColor = score >= 80 ? 'bg-green-500' : score >= 60 ? 'bg-yellow-500' : 'bg-red-500' - const tabs: { key: TabKey; label: string }[] = [ - { key: 'overview', label: 'Uebersicht' }, - { key: 'roadmap', label: 'Roadmap' }, - { key: 'modules', label: 'Module' }, - { key: 'trend', label: 'Trend' }, - { key: 'traceability', label: 'Traceability' }, - ] - return (
{/* Title Card */} @@ -366,11 +46,11 @@ export default function ComplianceHubPage() {

@@ -381,9 +61,9 @@ export default function ComplianceHubPage() { {tabs.map(tab => (
{/* Error Banner */} - {error && ( + {hub.error && (
- {error} -
)} {/* Seed Button if no data */} - {!loading && (dashboard?.total_controls || 0) === 0 && ( + {!hub.loading && (hub.dashboard?.total_controls || 0) === 0 && (
@@ -416,822 +96,66 @@ export default function ComplianceHubPage() {

Initialisieren Sie die Datenbank mit den Seed-Daten.

)} - {loading ? ( + {hub.loading ? (
) : ( <> - {/* ============================================================ */} - {/* TAB: Uebersicht */} - {/* ============================================================ */} - {activeTab === 'overview' && ( - <> - {/* Quick Actions */} -
-

Schnellzugriff

-
- {[ - { href: '/sdk/audit-checklist', icon: 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01', label: 'Audit Checkliste', sub: `${dashboard?.total_requirements || '...'} Anforderungen`, color: 'purple' }, - { href: '/sdk/controls', icon: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z', label: 'Controls', sub: `${dashboard?.total_controls || '...'} Massnahmen`, color: 'green' }, - { href: '/sdk/evidence', icon: 'M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z', label: 'Evidence', sub: 'Nachweise', color: 'blue' }, - { href: '/sdk/risks', icon: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z', label: 'Risk Matrix', sub: '5x5 Risiken', color: 'red' }, - { href: '/sdk/process-tasks', icon: 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4', label: 'Prozesse', sub: 'Aufgaben', color: 'indigo' }, - { href: '/sdk/audit-report', icon: 'M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z', label: 'Audit Report', sub: 'PDF Export', color: 'orange' }, - ].map(item => ( - -
- - - -
-

{item.label}

-

{item.sub}

- - ))} -
-
- - {/* Score and Stats Row */} -
-
-

Compliance Score

-
- {score.toFixed(0)}% -
-
-
-
-

- {dashboard?.controls_by_status?.pass || 0} von {dashboard?.total_controls || 0} Controls bestanden -

-
- - {[ - { label: 'Verordnungen', value: dashboard?.total_regulations || 0, sub: `${dashboard?.total_requirements || 0} Anforderungen`, iconColor: 'blue', icon: 'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z' }, - { label: 'Controls', value: dashboard?.total_controls || 0, sub: `${dashboard?.controls_by_status?.pass || 0} bestanden`, iconColor: 'green', icon: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z' }, - { label: 'Nachweise', value: dashboard?.total_evidence || 0, sub: `${dashboard?.evidence_by_status?.valid || 0} aktiv`, iconColor: 'purple', icon: 'M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z' }, - { label: 'Risiken', value: dashboard?.total_risks || 0, sub: `${(dashboard?.risks_by_level?.high || 0) + (dashboard?.risks_by_level?.critical || 0)} kritisch`, iconColor: 'red', icon: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z' }, - ].map(stat => ( -
-
-
-

{stat.label}

-

{stat.value}

-
-
- - - -
-
-

{stat.sub}

-
- ))} -
- - {/* Anti-Fake-Evidence Section (Phase 3) */} - {dashboard && ( -
-

Anti-Fake-Evidence Status

- - {/* Confidence Distribution Bar */} - {evidenceDistribution && evidenceDistribution.total > 0 && ( -
-

Confidence-Verteilung ({evidenceDistribution.total} Nachweise)

-
- {(['E0', 'E1', 'E2', 'E3', 'E4'] as const).map(level => { - const count = evidenceDistribution.by_confidence[level] || 0 - const pct = (count / evidenceDistribution.total) * 100 - if (pct === 0) return null - const colors: Record = { - E0: 'bg-red-400', E1: 'bg-yellow-400', E2: 'bg-blue-400', E3: 'bg-green-400', E4: 'bg-emerald-400' - } - return ( -
- {pct >= 10 ? `${level} (${count})` : ''} -
- ) - })} -
-
- {(['E0', 'E1', 'E2', 'E3', 'E4'] as const).map(level => { - const count = evidenceDistribution.by_confidence[level] || 0 - const dotColors: Record = { - E0: 'bg-red-400', E1: 'bg-yellow-400', E2: 'bg-blue-400', E3: 'bg-green-400', E4: 'bg-emerald-400' - } - return ( - - - {level}: {count} - - ) - })} -
-
- )} - - {/* Multi-Score Dimensions */} - {dashboard.multi_score && ( -
-

Multi-dimensionaler Score

-
- {([ - { key: 'requirement_coverage', label: 'Anforderungsabdeckung', color: 'bg-blue-500' }, - { key: 'evidence_strength', label: 'Evidence-Staerke', color: 'bg-green-500' }, - { key: 'validation_quality', label: 'Validierungsqualitaet', color: 'bg-purple-500' }, - { key: 'evidence_freshness', label: 'Aktualitaet', color: 'bg-yellow-500' }, - { key: 'control_effectiveness', label: 'Control-Wirksamkeit', color: 'bg-indigo-500' }, - ] as const).map(dim => { - const value = (dashboard.multi_score as Record)[dim.key] || 0 - return ( -
- {dim.label} -
-
-
- {typeof value === 'number' ? value.toFixed(0) : value}% -
- ) - })} -
- Audit-Readiness -
-
= 80 ? 'bg-green-500' : - (dashboard.multi_score.overall_readiness || 0) >= 60 ? 'bg-yellow-500' : 'bg-red-500' - }`} style={{ width: `${dashboard.multi_score.overall_readiness || 0}%` }} /> -
- - {typeof dashboard.multi_score.overall_readiness === 'number' ? dashboard.multi_score.overall_readiness.toFixed(0) : 0}% - -
-
-
- )} - - {/* Bottom row: Four-Eyes + Hard Blocks */} -
-
-
{evidenceDistribution?.four_eyes_pending || 0}
-
Four-Eyes Reviews ausstehend
-
- {dashboard.multi_score?.hard_blocks && dashboard.multi_score.hard_blocks.length > 0 ? ( -
-
Hard Blocks ({dashboard.multi_score.hard_blocks.length})
-
    - {dashboard.multi_score.hard_blocks.slice(0, 3).map((block: string, i: number) => ( -
  • - - {block} -
  • - ))} -
-
- ) : ( -
-
0
-
Keine Hard Blocks
-
- )} -
-
- )} - - {/* Next Actions + Findings */} -
- {/* Next Actions */} -
-

Naechste Aktionen

- {nextActions.length === 0 ? ( -

Keine offenen Aktionen.

- ) : ( -
- {nextActions.map(action => ( -
-
0 ? 'bg-red-500' : 'bg-yellow-500' - }`} /> -
-

{action.title}

-

- {action.control_id} Β· {DOMAIN_LABELS[action.domain] || action.domain} - {action.days_overdue > 0 && {action.days_overdue}d ueberfaellig} -

-
- - {action.status} - -
- ))} -
- )} -
- - {/* Audit Findings */} -
-
-

Audit Findings

- - Audit Checkliste β†’ - -
-
-
-
-
- Hauptabweichungen -
-

{findings?.open_majors || 0}

-

offen (blockiert Zertifizierung)

-
-
-
-
- Nebenabweichungen -
-

{findings?.open_minors || 0}

-

offen (erfordert CAPA)

-
-
-
- - Gesamt: {findings?.total || 0} Findings ({findings?.major_count || 0} Major, {findings?.minor_count || 0} Minor, {findings?.ofi_count || 0} OFI) - - {(findings?.open_majors || 0) === 0 ? ( - - Zertifizierung moeglich - - ) : ( - - Zertifizierung blockiert - - )} -
-
-
- - {/* Control-Mappings & Domain Chart */} -
-
-
-

Control-Mappings

- - Alle anzeigen β†’ - -
-
-
-

{mappings?.total || 0}

-

Mappings gesamt

-
-
-

Nach Verordnung

-
- {mappings?.by_regulation && Object.entries(mappings.by_regulation).slice(0, 5).map(([reg, count]) => ( - - {reg}: {count} - - ))} - {!mappings?.by_regulation && ( - Keine Mappings vorhanden - )} -
-
-
-
- -
-

Controls nach Domain

-
- {Object.entries(dashboard?.controls_by_domain || {}).slice(0, 6).map(([domain, stats]) => { - const total = stats.total || 0 - const pass = stats.pass || 0 - const partial = stats.partial || 0 - const passPercent = total > 0 ? ((pass + partial * 0.5) / total) * 100 : 0 - - return ( -
- - {DOMAIN_LABELS[domain] || domain} - -
-
-
-
- {passPercent.toFixed(0)}% -
- ) - })} -
-
-
- - {/* Regulations Table */} -
-
-

Verordnungen & Standards ({regulations.length})

- -
-
- - - - - - - - - - - {regulations.slice(0, 15).map((reg) => ( - - - - - - - ))} - -
CodeNameTypAnforderungen
- {reg.code} - -

{reg.name}

-
- - {reg.regulation_type === 'eu_regulation' ? 'EU-VO' : - reg.regulation_type === 'eu_directive' ? 'EU-RL' : - reg.regulation_type === 'bsi_standard' ? 'BSI' : - reg.regulation_type === 'de_law' ? 'DE' : reg.regulation_type} - - - {reg.requirement_count} -
-
-
- + {hub.activeTab === 'overview' && ( + )} - {/* ============================================================ */} - {/* TAB: Roadmap */} - {/* ============================================================ */} - {activeTab === 'roadmap' && ( -
- {!roadmap ? ( -
-
-
- ) : ( -
- {(['quick_wins', 'must_have', 'should_have', 'nice_to_have'] as const).map(bucketKey => { - const meta = BUCKET_LABELS[bucketKey] - const items = roadmap.buckets[bucketKey] || [] - - return ( -
-
-

{meta.label}

- - {items.length} - -
-
- {items.length === 0 ? ( -

Keine Eintraege

- ) : ( - items.map(item => ( -
-

{item.title}

-
- {item.control_id} - Β· - {DOMAIN_LABELS[item.domain] || item.domain} -
- {item.days_overdue > 0 && ( -

{item.days_overdue}d ueberfaellig

- )} - {item.owner && ( -

{item.owner}

- )} -
- )) - )} -
-
- ) - })} -
- )} -
+ {hub.activeTab === 'roadmap' && ( + )} - {/* ============================================================ */} - {/* TAB: Module */} - {/* ============================================================ */} - {activeTab === 'modules' && ( -
- {!moduleStatus ? ( -
-
-
- ) : ( - <> - {/* Summary */} -
-
-

Gesamt-Fortschritt

-

{moduleStatus.overall_progress.toFixed(0)}%

-
-
-

Module gestartet

-

{moduleStatus.started}/{moduleStatus.total}

-
-
-

Module abgeschlossen

-

{moduleStatus.complete}/{moduleStatus.total}

-
-
- - {/* Module Grid */} -
- {moduleStatus.modules.map(mod => ( -
-
- {MODULE_ICONS[mod.key] || 'πŸ“¦'} -
-

{mod.label}

-

{mod.count} Eintraege

-
- - {mod.status === 'complete' ? 'Fertig' : - mod.status === 'in_progress' ? 'In Arbeit' : 'Offen'} - -
-
-
-
-
- ))} -
- - )} -
+ {hub.activeTab === 'modules' && ( + )} - {/* ============================================================ */} - {/* TAB: Trend */} - {/* ============================================================ */} - {activeTab === 'trend' && ( -
-
-

Score-Verlauf

- -
- - {scoreHistory.length === 0 ? ( -
-

Noch keine Score-Snapshots vorhanden.

-

Klicken Sie auf "Aktuellen Score speichern", um den ersten Datenpunkt zu erstellen.

-
- ) : ( - <> - {/* Simple SVG Line Chart */} -
- - {/* Grid lines */} - {[0, 25, 50, 75, 100].map(pct => ( - - ))} - {/* Score line */} - { - const x = scoreHistory.length === 1 ? 400 : (i / (scoreHistory.length - 1)) * 780 + 10 - const y = 200 - (s.score / 100) * 200 - return `${x},${y}` - }).join(' ')} - /> - {/* Points */} - {scoreHistory.map((s, i) => { - const x = scoreHistory.length === 1 ? 400 : (i / (scoreHistory.length - 1)) * 780 + 10 - const y = 200 - (s.score / 100) * 200 - return ( - - ) - })} - - {/* Y-axis labels */} -
- 100% - 75% - 50% - 25% - 0% -
-
- - {/* Snapshot Table */} -
- - - - - - - - - - - {scoreHistory.slice().reverse().map(snap => ( - - - - - - - ))} - -
DatumScoreControlsBestanden
{new Date(snap.snapshot_date).toLocaleDateString('de-DE')} - = 80 ? 'text-green-600' : snap.score >= 60 ? 'text-yellow-600' : 'text-red-600' - }`}> - {typeof snap.score === 'number' ? snap.score.toFixed(1) : snap.score}% - - {snap.controls_total}{snap.controls_pass}
-
- - )} -
+ {hub.activeTab === 'trend' && ( + )} - {/* Traceability Tab */} - {activeTab === 'traceability' && ( -
- {traceabilityLoading ? ( -
-
- Traceability Matrix wird geladen... -
- ) : !traceabilityMatrix ? ( -
- Keine Daten verfuegbar. Stellen Sie sicher, dass Controls und Evidence vorhanden sind. -
- ) : (() => { - const summary = traceabilityMatrix.summary - const totalControls = summary.total_controls || 0 - const covered = summary.covered || 0 - const fullyVerified = summary.fully_verified || 0 - const uncovered = summary.uncovered || 0 - - const filteredControls = (traceabilityMatrix.controls || []).filter(ctrl => { - if (traceabilityFilter === 'covered' && !ctrl.coverage.has_evidence) return false - if (traceabilityFilter === 'uncovered' && ctrl.coverage.has_evidence) return false - if (traceabilityFilter === 'fully_verified' && !ctrl.coverage.all_assertions_verified) return false - if (traceabilityDomainFilter !== 'all' && ctrl.domain !== traceabilityDomainFilter) return false - return true - }) - - const domains = [...new Set(traceabilityMatrix.controls.map(c => c.domain))].sort() - - return ( - <> - {/* Summary Cards */} -
-
-
{totalControls}
-
Total Controls
-
-
-
{covered}
-
Abgedeckt
-
-
-
{fullyVerified}
-
Vollst. verifiziert
-
-
-
{uncovered}
-
Unabgedeckt
-
-
- - {/* Filter Bar */} -
-
- {([ - { key: 'all', label: 'Alle' }, - { key: 'covered', label: 'Abgedeckt' }, - { key: 'uncovered', label: 'Nicht abgedeckt' }, - { key: 'fully_verified', label: 'Vollst. verifiziert' }, - ] as const).map(f => ( - - ))} -
-
-
- - {domains.map(d => ( - - ))} -
-
- - {/* Controls List */} -
- {filteredControls.length === 0 ? ( -
- Keine Controls fuer diesen Filter gefunden. -
- ) : filteredControls.map(ctrl => { - const isExpanded = expandedControls.has(ctrl.id) - const coverageIcon = ctrl.coverage.all_assertions_verified - ? { symbol: '\u2713', color: 'text-green-600 bg-green-50' } - : ctrl.coverage.has_evidence - ? { symbol: '\u25D0', color: 'text-yellow-600 bg-yellow-50' } - : { symbol: '\u2717', color: 'text-red-600 bg-red-50' } - - return ( -
- {/* Control Row */} - - - {/* Expanded: Evidence list */} - {isExpanded && ( -
- {ctrl.evidence.length === 0 ? ( -
- Kein Evidence verknuepft. -
- ) : ctrl.evidence.map(ev => { - const evExpanded = expandedEvidence.has(ev.id) - return ( -
- - - {/* Expanded: Assertions list */} - {evExpanded && ev.assertions.length > 0 && ( -
- - - - - - - - - - - {ev.assertions.map(a => ( - - - - - - - ))} - -
AussageTypKonfidenzStatus
{a.sentence_text}{a.assertion_type} - = 0.8 ? 'text-green-600' - : a.confidence >= 0.5 ? 'text-yellow-600' - : 'text-red-600' - }`}> - {(a.confidence * 100).toFixed(0)}% - - - {a.verified - ? {'\u2713'} - : {'\u2717'} - } -
-
- )} -
- ) - })} -
- )} -
- ) - })} -
- - ) - })()} -
+ {hub.activeTab === 'traceability' && ( + )} )} diff --git a/admin-compliance/app/sdk/document-generator/page.tsx b/admin-compliance/app/sdk/document-generator/page.tsx index db306d0..4de3814 100644 --- a/admin-compliance/app/sdk/document-generator/page.tsx +++ b/admin-compliance/app/sdk/document-generator/page.tsx @@ -9,807 +9,10 @@ import { DataPointsPreview } from './components/DataPointsPreview' import { DocumentValidation } from './components/DocumentValidation' import { generateAllPlaceholders } from '@/lib/sdk/document-generator/datapoint-helpers' import { loadAllTemplates } from './searchTemplates' -import { - TemplateContext, EMPTY_CONTEXT, - contextToPlaceholders, getRelevantSections, - getUncoveredPlaceholders, getMissingRequired, -} from './contextBridge' -import { - runRuleset, getDocType, applyBlockRemoval, - buildBoolContext, applyConditionalBlocks, - type RuleInput, type RuleEngineResult, -} from './ruleEngine' - -// ============================================================================= -// CATEGORY CONFIG -// ============================================================================= - -const CATEGORIES: { key: string; label: string; types: string[] | null }[] = [ - { key: 'all', label: 'Alle', types: null }, - // Legal / Vertragsvorlagen - { key: 'privacy_policy', label: 'Datenschutz', types: ['privacy_policy'] }, - { key: 'terms', label: 'AGB', types: ['terms_of_service', 'agb', 'clause'] }, - { key: 'impressum', label: 'Impressum', types: ['impressum'] }, - { key: 'dpa', label: 'AVV/DPA', types: ['dpa'] }, - { key: 'nda', label: 'NDA', types: ['nda'] }, - { key: 'sla', label: 'SLA', types: ['sla'] }, - { key: 'widerruf', label: 'Widerruf', types: ['widerruf'] }, - { key: 'cookie', label: 'Cookie', types: ['cookie_policy', 'cookie_banner'] }, - { key: 'cloud', label: 'Cloud', types: ['cloud_service_agreement'] }, - { key: 'misc', label: 'Weitere', types: ['community_guidelines', 'copyright_policy', 'data_usage_clause'] }, - { key: 'dsfa', label: 'DSFA', types: ['dsfa'] }, - // Sicherheitskonzepte (Migration 051) - { key: 'security', label: 'Sicherheitskonzepte', types: ['it_security_concept', 'data_protection_concept', 'backup_recovery_concept', 'logging_concept', 'incident_response_plan', 'access_control_concept', 'risk_management_concept', 'cybersecurity_policy'] }, - // Policy-Bibliothek (Migration 071/072) - { key: 'it_security_policies', label: 'IT-Sicherheit Policies', types: ['information_security_policy', 'access_control_policy', 'password_policy', 'encryption_policy', 'logging_policy', 'backup_policy', 'incident_response_policy', 'change_management_policy', 'patch_management_policy', 'asset_management_policy', 'cloud_security_policy', 'devsecops_policy', 'secrets_management_policy', 'vulnerability_management_policy'] }, - { key: 'data_policies', label: 'Daten-Policies', types: ['data_protection_policy', 'data_classification_policy', 'data_retention_policy', 'data_transfer_policy', 'privacy_incident_policy'] }, - { key: 'hr_policies', label: 'Personal-Policies', types: ['employee_security_policy', 'security_awareness_policy', 'acceptable_use', 'remote_work_policy', 'offboarding_policy'] }, - { key: 'vendor_policies', label: 'Lieferanten-Policies', types: ['vendor_risk_management_policy', 'third_party_security_policy', 'supplier_security_policy'] }, - { key: 'bcm_policies', label: 'BCM/Notfall', types: ['business_continuity_policy', 'disaster_recovery_policy', 'crisis_management_policy'] }, - // Modul-Dokumente (Migration 073) - { key: 'module_docs', label: 'DSGVO-Dokumente', types: ['vvt_register', 'tom_documentation', 'loeschkonzept', 'pflichtenregister'] }, -] - -// ============================================================================= -// CONTEXT FORM CONFIG -// ============================================================================= - -const SECTION_LABELS: Record = { - PROVIDER: 'Anbieter', - CUSTOMER: 'Kunde / Gegenpartei', - SERVICE: 'Dienst / Produkt', - LEGAL: 'Rechtliches', - PRIVACY: 'Datenschutz', - SLA: 'Service Level (SLA)', - PAYMENTS: 'Zahlungskonditionen', - SECURITY: 'Sicherheit & Logs', - NDA: 'Geheimhaltung (NDA)', - CONSENT: 'Cookie / Einwilligung', - HOSTING: 'Hosting-Provider', - FEATURES: 'Dokument-Features & Textbausteine', -} - -type FieldType = 'text' | 'email' | 'number' | 'select' | 'textarea' | 'boolean' -interface FieldDef { - key: string - label: string - type?: FieldType - opts?: string[] - span?: boolean - nullable?: boolean -} - -const SECTION_FIELDS: Record = { - PROVIDER: [ - { key: 'LEGAL_NAME', label: 'Firmenname' }, - { key: 'EMAIL', label: 'Kontakt-E-Mail', type: 'email' }, - { key: 'LEGAL_FORM', label: 'Rechtsform' }, - { key: 'ADDRESS_LINE', label: 'Adresse' }, - { key: 'POSTAL_CODE', label: 'PLZ' }, - { key: 'CITY', label: 'Stadt' }, - { key: 'WEBSITE_URL', label: 'Website-URL' }, - { key: 'CEO_NAME', label: 'GeschΓ€ftsfΓΌhrer' }, - { key: 'REGISTER_COURT', label: 'Registergericht' }, - { key: 'REGISTER_NUMBER', label: 'HRB-Nummer' }, - { key: 'VAT_ID', label: 'USt-ID' }, - { key: 'PHONE', label: 'Telefon' }, - ], - CUSTOMER: [ - { key: 'LEGAL_NAME', label: 'Name / Firma' }, - { key: 'EMAIL', label: 'E-Mail', type: 'email' }, - { key: 'CONTACT_NAME', label: 'Ansprechpartner' }, - { key: 'ADDRESS_LINE', label: 'Adresse' }, - { key: 'POSTAL_CODE', label: 'PLZ' }, - { key: 'CITY', label: 'Stadt' }, - { key: 'COUNTRY', label: 'Land' }, - { key: 'IS_CONSUMER', label: 'Verbraucher (B2C)', type: 'boolean' }, - { key: 'IS_BUSINESS', label: 'Unternehmer (B2B)', type: 'boolean' }, - ], - SERVICE: [ - { key: 'NAME', label: 'Dienstname' }, - { key: 'DESCRIPTION', label: 'Beschreibung', type: 'textarea', span: true }, - { key: 'MODEL', label: 'Modell', type: 'select', opts: ['SaaS', 'PaaS', 'IaaS', 'OnPrem', 'Hybrid'] }, - { key: 'TIER', label: 'Plan / Tier' }, - { key: 'DATA_LOCATION', label: 'Datenspeicherort' }, - { key: 'EXPORT_WINDOW_DAYS', label: 'Export-Frist (Tage)', type: 'number' }, - { key: 'MIN_TERM_MONTHS', label: 'Mindestlaufzeit (Monate)', type: 'number' }, - { key: 'TERMINATION_NOTICE_DAYS', label: 'KΓΌndigungsfrist (Tage)', type: 'number' }, - ], - LEGAL: [ - { key: 'GOVERNING_LAW', label: 'Anwendbares Recht' }, - { key: 'JURISDICTION_CITY', label: 'Gerichtsstand (Stadt)' }, - { key: 'VERSION_DATE', label: 'Versionsstand (JJJJ-MM-TT)' }, - { key: 'EFFECTIVE_DATE', label: 'GΓΌltig ab (JJJJ-MM-TT)' }, - ], - PRIVACY: [ - { key: 'DPO_NAME', label: 'DSB-Name' }, - { key: 'DPO_EMAIL', label: 'DSB-E-Mail', type: 'email' }, - { key: 'CONTACT_EMAIL', label: 'Datenschutz-Kontakt', type: 'email' }, - { key: 'PRIVACY_POLICY_URL', label: 'Datenschutz-URL' }, - { key: 'COOKIE_POLICY_URL', label: 'Cookie-Policy-URL' }, - { key: 'ANALYTICS_RETENTION_MONTHS', label: 'Analytics-Aufbewahrung (Monate)', type: 'number' }, - { key: 'SUPERVISORY_AUTHORITY_NAME', label: 'AufsichtsbehΓΆrde' }, - ], - SLA: [ - { key: 'AVAILABILITY_PERCENT', label: 'VerfΓΌgbarkeit (%)', type: 'number' }, - { key: 'MAINTENANCE_NOTICE_HOURS', label: 'WartungsankΓΌndigung (h)', type: 'number' }, - { key: 'SUPPORT_EMAIL', label: 'Support-E-Mail', type: 'email' }, - { key: 'SUPPORT_HOURS', label: 'Support-Zeiten' }, - { key: 'RESPONSE_CRITICAL_H', label: 'Reaktion Kritisch (h)', type: 'number' }, - { key: 'RESOLUTION_CRITICAL_H', label: 'LΓΆsung Kritisch (h)', type: 'number' }, - { key: 'RESPONSE_HIGH_H', label: 'Reaktion Hoch (h)', type: 'number' }, - { key: 'RESOLUTION_HIGH_H', label: 'LΓΆsung Hoch (h)', type: 'number' }, - { key: 'RESPONSE_MEDIUM_H', label: 'Reaktion Mittel (h)', type: 'number' }, - { key: 'RESOLUTION_MEDIUM_H', label: 'LΓΆsung Mittel (h)', type: 'number' }, - { key: 'RESPONSE_LOW_H', label: 'Reaktion Niedrig (h)', type: 'number' }, - ], - PAYMENTS: [ - { key: 'MONTHLY_FEE_EUR', label: 'Monatl. GebΓΌhr (EUR)', type: 'number' }, - { key: 'PAYMENT_DUE_DAY', label: 'FΓ€lligkeitstag', type: 'number' }, - { key: 'PAYMENT_METHOD', label: 'Zahlungsmethode' }, - { key: 'PAYMENT_DAYS', label: 'Zahlungsziel (Tage)', type: 'number' }, - ], - SECURITY: [ - { key: 'INCIDENT_NOTICE_HOURS', label: 'Meldepflicht VorfΓ€lle (h)', type: 'number' }, - { key: 'LOG_RETENTION_DAYS', label: 'Log-Aufbewahrung (Tage)', type: 'number' }, - { key: 'SECURITY_LOG_RETENTION_DAYS', label: 'Sicherheits-Log (Tage)', type: 'number' }, - ], - NDA: [ - { key: 'PURPOSE', label: 'Zweck', type: 'textarea', span: true }, - { key: 'DURATION_YEARS', label: 'Laufzeit (Jahre)', type: 'number' }, - { key: 'PENALTY_AMOUNT_EUR', label: 'Vertragsstrafe EUR (leer = keine)', type: 'number', nullable: true }, - ], - CONSENT: [ - { key: 'WEBSITE_NAME', label: 'Website-Name' }, - { key: 'ANALYTICS_TOOLS', label: 'Analytics-Tools (leer = kein Block)', nullable: true }, - { key: 'MARKETING_PARTNERS', label: 'Marketing-Partner (leer = kein Block)', nullable: true }, - ], - HOSTING: [ - { key: 'PROVIDER_NAME', label: 'Hosting-Anbieter' }, - { key: 'COUNTRY', label: 'Hosting-Land' }, - { key: 'CONTRACT_TYPE', label: 'Vertragstyp (z. B. AVV nach Art. 28 DSGVO)' }, - ], - FEATURES: [ - // ── DSI / Cookie ───────────────────────────────────────────────────────── - { key: 'CONSENT_WITHDRAWAL_PATH', label: 'Einwilligungs-Widerrufspfad' }, - { key: 'SECURITY_MEASURES_SUMMARY', label: 'Sicherheitsmaßnahmen (kurz)' }, - { key: 'DATA_SUBJECT_REQUEST_CHANNEL', label: 'Kanal fΓΌr Betroffenenanfragen' }, - { key: 'HAS_THIRD_COUNTRY', label: 'DrittlandΓΌbermittlung mΓΆglich', type: 'boolean' }, - { key: 'TRANSFER_GUARDS', label: 'Garantien (z. B. SCC)' }, - // ── Cookie/Consent ─────────────────────────────────────────────────────── - { key: 'HAS_FUNCTIONAL_COOKIES', label: 'Funktionale Cookies aktiviert', type: 'boolean' }, - { key: 'CMP_NAME', label: 'Consent-Manager-Name (optional)' }, - { key: 'CMP_LOGS_CONSENTS', label: 'Consent-Protokollierung aktiv', type: 'boolean' }, - { key: 'ANALYTICS_TOOLS_DETAIL', label: 'Analyse-Tools (Detailtext)', type: 'textarea', span: true }, - { key: 'MARKETING_TOOLS_DETAIL', label: 'Marketing-Tools (Detailtext)', type: 'textarea', span: true }, - // ── Service-Features ───────────────────────────────────────────────────── - { key: 'HAS_ACCOUNT', label: 'Nutzerkonten vorhanden', type: 'boolean' }, - { key: 'HAS_PAYMENTS', label: 'Zahlungsabwicklung vorhanden', type: 'boolean' }, - { key: 'PAYMENT_PROVIDER_DETAIL', label: 'Zahlungsanbieter (Detailtext)', type: 'textarea', span: true }, - { key: 'HAS_SUPPORT', label: 'Support-Funktion vorhanden', type: 'boolean' }, - { key: 'SUPPORT_CHANNELS_TEXT', label: 'Support-KanΓ€le / Zeiten' }, - { key: 'HAS_NEWSLETTER', label: 'Newsletter vorhanden', type: 'boolean' }, - { key: 'NEWSLETTER_PROVIDER_DETAIL', label: 'Newsletter-Anbieter (Detailtext)', type: 'textarea', span: true }, - { key: 'HAS_SOCIAL_MEDIA', label: 'Social-Media-PrΓ€senz', type: 'boolean' }, - { key: 'SOCIAL_MEDIA_DETAIL', label: 'Social-Media-Details', type: 'textarea', span: true }, - // ── AGB ────────────────────────────────────────────────────────────────── - { key: 'HAS_PAID_PLANS', label: 'Kostenpflichtige PlΓ€ne', type: 'boolean' }, - { key: 'PRICES_TEXT', label: 'Preise (Text/Link)', type: 'textarea', span: true }, - { key: 'PAYMENT_TERMS_TEXT', label: 'Zahlungsbedingungen', type: 'textarea', span: true }, - { key: 'CONTRACT_TERM_TEXT', label: 'Laufzeit & KΓΌndigung', type: 'textarea', span: true }, - { key: 'HAS_SLA', label: 'SLA vorhanden', type: 'boolean' }, - { key: 'SLA_URL', label: 'SLA-URL' }, - { key: 'HAS_EXPORT_POLICY', label: 'Datenexport/LΓΆschung geregelt', type: 'boolean' }, - { key: 'EXPORT_POLICY_TEXT', label: 'Datenexport-Regelung (Text)', type: 'textarea', span: true }, - { key: 'HAS_WITHDRAWAL', label: 'Widerrufsrecht (B2C digital)', type: 'boolean' }, - { key: 'CONSUMER_WITHDRAWAL_TEXT', label: 'Widerrufsbelehrung (Text)', type: 'textarea', span: true }, - { key: 'LIMITATION_CAP_TEXT', label: 'Haftungsdeckel B2B (Text)' }, - // ── Impressum ──────────────────────────────────────────────────────────── - { key: 'HAS_REGULATED_PROFESSION', label: 'Reglementierter Beruf', type: 'boolean' }, - { key: 'REGULATED_PROFESSION_TEXT', label: 'Berufsrecht-Text', type: 'textarea', span: true }, - { key: 'HAS_EDITORIAL_RESPONSIBLE', label: 'V.i.S.d.P. (redaktionell)', type: 'boolean' }, - { key: 'EDITORIAL_RESPONSIBLE_NAME', label: 'V.i.S.d.P. Name' }, - { key: 'EDITORIAL_RESPONSIBLE_ADDRESS', label: 'V.i.S.d.P. Adresse' }, - { key: 'HAS_DISPUTE_RESOLUTION', label: 'Streitbeilegungshinweis', type: 'boolean' }, - { key: 'DISPUTE_RESOLUTION_TEXT', label: 'Streitbeilegungstext', type: 'textarea', span: true }, - ], -} - -// ============================================================================= -// SMALL COMPONENTS -// ============================================================================= - -function LicenseBadge({ licenseId, small = false }: { licenseId: LicenseType | null; small?: boolean }) { - if (!licenseId) return null - const colors: Partial> = { - public_domain: 'bg-green-100 text-green-700 border-green-200', - cc0: 'bg-green-100 text-green-700 border-green-200', - unlicense: 'bg-green-100 text-green-700 border-green-200', - mit: 'bg-blue-100 text-blue-700 border-blue-200', - cc_by_4: 'bg-purple-100 text-purple-700 border-purple-200', - reuse_notice: 'bg-orange-100 text-orange-700 border-orange-200', - } - return ( - - {LICENSE_TYPE_LABELS[licenseId] || licenseId} - - ) -} - -// ============================================================================= -// LIBRARY CARD -// ============================================================================= - -function LibraryCard({ - template, - expanded, - onTogglePreview, - onUse, -}: { - template: LegalTemplateResult - expanded: boolean - onTogglePreview: () => void - onUse: () => void -}) { - const typeLabel = template.templateType - ? (TEMPLATE_TYPE_LABELS[template.templateType as TemplateType] || template.templateType) - : null - const placeholderCount = template.placeholders?.length ?? 0 - - return ( -
-
-
-

- {template.documentTitle || 'Vorlage'} -

- {template.language} -
-
- {typeLabel && ( - - {typeLabel} - - )} - - {placeholderCount > 0 && ( - {placeholderCount} Platzh. - )} -
-
- - -
-
- - {expanded && ( -
-
-            {template.text}
-          
-
- )} -
- ) -} - -// ============================================================================= -// CONTEXT SECTION FORM -// ============================================================================= - -function ContextSectionForm({ - section, - context, - onChange, -}: { - section: keyof TemplateContext - context: TemplateContext - onChange: (section: keyof TemplateContext, key: string, value: unknown) => void -}) { - const fields = SECTION_FIELDS[section] - const sectionData = context[section] as unknown as Record - - return ( -
- {fields.map((field) => { - const rawValue = sectionData[field.key] - const inputCls = 'w-full px-3 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-purple-400' - - if (field.type === 'boolean') { - return ( -
- onChange(section, field.key, e.target.checked)} - className="w-4 h-4 accent-purple-600" - /> - -
- ) - } - - if (field.type === 'select' && field.opts) { - return ( -
- - -
- ) - } - - if (field.type === 'textarea') { - return ( -
- -