import { useMemo, useState } from 'react'; import { Link } from 'wouter'; import { RELAY_MAPPINGS, RELAY_MODELS, RELAY_DESTINATIONS, RELAY_SOURCES, RELAY_POLICIES } from '@/data/fabric'; import { scoreMappingCompatibility, deriveApprovalRequirement, buildDryRunSummary, classifyPiiRisk } from '@/lib/agentic'; import { FabricHeader, FabricStat, FabricToolbar, FabricDrawer, GovernanceDot, MicroBar, SeverityChip } from '@/components/fabric/primitives'; import { Input, Select, Badge } from '@/components/ui'; import { ScanLine, GitBranch as DriftIcon } from 'lucide-react'; import { useInnovationStore, applyMappingOverrides } from '@/lib/innovation-store'; export default function MappingsPage() { const { driftDecisions, mappingOverrides } = useInnovationStore(); const [q, setQ] = useState(''); const [vertical, setVertical] = useState(''); const [needsApproval, setNeedsApproval] = useState(false); const [drawerId, setDrawerId] = useState(null); const driftByMappingId = useMemo(() => { const map = new Map(); for (const d of driftDecisions) { for (const mid of d.mappingIds) { const arr = map.get(mid) ?? []; arr.push(d); map.set(mid, arr); } } return map; }, [driftDecisions]); const approvedDriftCount = driftDecisions.filter((d) => d.status === 'approved').length; const effectiveMappings = useMemo( () => RELAY_MAPPINGS.map((m) => applyMappingOverrides(m, mappingOverrides)), [mappingOverrides], ); const rows = useMemo(() => { return effectiveMappings .filter((m) => { if (q && !m.name.toLowerCase().includes(q.toLowerCase())) return false; if (vertical && m.verticalId !== vertical) return false; if (needsApproval && !m.approvalRequired) return false; return true; }) .sort((a, b) => scoreMappingCompatibility(b) - scoreMappingCompatibility(a)); }, [effectiveMappings, q, vertical, needsApproval]); const drawer = drawerId ? effectiveMappings.find((m) => m.id === drawerId) ?? null : null; const drawerModel = drawer ? RELAY_MODELS.find((mo) => mo.id === drawer.modelId) ?? null : null; const drawerDest = drawer ? RELAY_DESTINATIONS.find((d) => d.id === drawer.destinationId) ?? null : null; const drawerSource = drawerModel ? RELAY_SOURCES.find((s) => s.id === drawerModel.sourceId) ?? null : null; const dryRun = drawer && drawerModel && drawerSource ? buildDryRunSummary(drawer, drawerSource, RELAY_POLICIES) : null; const risk = drawer && drawerModel && drawerDest ? classifyPiiRisk(drawerModel, drawerDest) : null; const appr = drawer && drawerDest ? deriveApprovalRequirement(drawer, drawerDest) : null; return (
Lineage → Drift Repair →
} />
m.approvalRequired).length} tone="warn" /> s + m.compatibilityScore, 0) / RELAY_MAPPINGS.length)} tone="good" /> m.piiWarnings.length > 0).length} /> 0 ? 'good' : 'neutral'} sub={driftDecisions.length > 0 ? `${driftDecisions.length} decisions` : undefined} />
setQ(e.target.value)} className="max-w-xs" />
{rows.map((m) => ( setDrawerId(m.id)}> ))}
Mapping Vertical Compat Confidence Fields Proposed State
{m.name} {(() => { const decisions = driftByMappingId.get(m.id) ?? []; const approved = decisions.filter((d) => d.status === 'approved').length; if (approved > 0) return {approved} drift fix{approved !== 1 ? 'es' : ''}; if (decisions.length > 0) return drift; return null; })()}
{m.approvalRequired &&
approval: {m.approvalReason}
}
{m.verticalId} = 80 ? 'good' : 'warn'} /> {(m.confidence * 100).toFixed(0)}% {m.mappedFieldCount} {m.proposedBy.replace(/-/g, ' ')}
setDrawerId(null)} title={drawer?.name ?? ''} subtitle={drawer ? `compat ${drawer.compatibilityScore} · conf ${(drawer.confidence * 100).toFixed(0)}%` : ''} > {drawer && drawerModel && drawerDest && dryRun && risk && appr && ( <>
DRY RUN
extracted{dryRun.recordsExtracted.toLocaleString()}
filtered{dryRun.recordsFiltered.toLocaleString()}
redacted{dryRun.recordsRedacted.toLocaleString()}
to deliver{dryRun.recordsToDeliver.toLocaleString()}
est latency{dryRun.estimatedLatencyMs}ms
FIELD MAPPINGS
{drawer.transformations.map((t) => (
{t.sourceField} {t.destinationField}
{t.transform} {t.piiHandling !== 'pass' && }
))}
{(drawer.qualityWarnings.length > 0 || drawer.piiWarnings.length > 0) && (
WARNINGS
    {[...drawer.qualityWarnings, ...drawer.piiWarnings].map((w, i) => (
  • · {w}
  • ))}
)} )}
); }