import { useState, type ReactNode } from 'react'; import { Dialog } from '../../components/Dialog/Dialog'; import './compliance.css'; import type { RegulatoryMappingCandidate, RegulatoryMappingDecision, RegulatoryMappingProposal, RegulatoryMappingResponse } from '../regulatory-mapping'; interface Props { response?: RegulatoryMappingResponse; loading: boolean; error: string; onStart(): void; onDecision(control: Pick, decision: 'accepted' | 'rejected', comment?: string): void; /** Inside the window the dialog title already names the mapping. */ embedded?: boolean; } /** Finding Reader `Map ISO controls` window, opened like `Accepted Risk`. */ export function RegulatoryMappingDialog({ onClose, ...props }: Omit & { onClose(): void }) { return ; } export function RegulatoryMappingPanel({ response, loading, error, onStart, onDecision, embedded = false }: Props) { const run = response?.run; const proposals = run?.result?.mappings ?? []; const proposalIds = new Set(proposals.map(item => item.controlId)); const proposedCandidates = proposals.flatMap(proposal => { const candidate = run?.candidates.find(item => item.controlId === proposal.controlId); return candidate ? [{ candidate, proposal }] : []; }); const otherCandidates = run?.candidates.filter(item => !proposalIds.has(item.controlId)) ?? []; const earlierControls = response?.earlierControls ?? []; return
{!embedded &&

ISO control mapping

}

Proposals indicate relevance to this finding, not proof of compliance.

{response?.generationEnabled && !['queued', 'running'].includes(response.state) && }
{loading && !response &&

Loading mapping state…

} {error &&

{error}

} {response && !response.generationEnabled &&

{response.disabledReason ?? 'Regulatory mapping is unavailable.'}

} {response && ['queued', 'running'].includes(response.state) &&

{response.state === 'queued' ? 'Mapping queued…' : 'Retrieving and evaluating ISO controls…'}

} {run?.status === 'failed' &&

Mapping stopped safely ({run.errorCode ?? 'unknown error'}). You can start a new run.{run.errorDetail ? <>
{run.errorDetail} : null}

} {run?.status === 'succeeded' && run.result?.outcome !== 'mapped' &&

{run.result?.reason ?? (run.result?.outcome === 'insufficient_context' ? 'Insufficient public context.' : 'No relevant control was proposed.')}

} {proposedCandidates.length > 0 &&
{proposedCandidates.map(item => ) }
} {otherCandidates.length > 0 &&
Other retrieved controls ({otherCandidates.length})
{otherCandidates.map(candidate => )}
} {earlierControls.length > 0 &&

Earlier decisions

Decided in an earlier mapping run of this rule and not retrieved by the current run.

{earlierControls.map(control => )}
}
; } function ControlCandidate({ candidate, proposal, decisions, loading, onDecision }: { candidate: RegulatoryMappingCandidate; proposal?: RegulatoryMappingProposal; decisions: RegulatoryMappingDecision[]; loading: boolean; onDecision: Props['onDecision']; }) { return {proposal ? <>{proposal.relationship} · {proposal.confidence} confidence : 'Retrieved candidate'} · score {candidate.score.toFixed(3)}}> {proposal?.rationale &&

{proposal.rationale}

}
Evidence ({candidate.evidence.length})
    {candidate.evidence.map(item =>
  • {item.sourceStandard} · {item.sectionKind} · {item.pageStart === item.pageEnd ? `page ${item.pageStart}` : `pages ${item.pageStart}–${item.pageEnd}`}
  • )}
; } /** One control with its latest decision, an optional comment and Accept/Reject. */ function ControlDecision({ control, heading, meta, children, decisions, loading, onDecision }: { control: Pick; heading: string; meta?: ReactNode; children?: ReactNode; decisions: RegulatoryMappingDecision[]; loading: boolean; onDecision: Props['onDecision']; }) { const [comment, setComment] = useState(''); const current = decisions.find(item => item.controlId === control.controlId); return

{heading}

{meta &&

{meta}

}
{current && {current.decision}}
{children}
; }