Consumers now fed by the core (crates/core through @faunosteo/core-wasm):
- the sheet: the bundled payload is parsed and indexed by the core
(SheetHandle, SheetIndexData); SheetIndex reads precomputed tables only;
- the store: new report, add / remove / move observation, draft restore
(v2 migration + rebase) through the core, actions answering { ok };
- the editor click chain (zone.click), laterality and vertebra pickers
(zone.add_sides, vertebra.initial / sync / select), the findings picker
(finding.toggle by clicked leaf position), zone removal;
- the import: engine byte scan (TypeScript until R4), then the core's
layered reading and rebase in one call; the export: the core builds the
sheet snapshot, the frozen TypeScript engine writes the PDF (R4).
Lazy core: Home and the new-report form read the sheet availability from
the bundle and load the module on import / submit only; the auth shell
never references it. Degraded states (core_unavailable, invalid_sheet)
show the validated notice with a retry and never redirect or touch the
draft; an unreadable draft or archive is set aside under
osteo:quarantine:* (only content kinds; a failed write keeps it in place
and the editor stays), a rebase that flags items keeps the raw pre-rebase
draft. Four strings, wording validated by the owner.
Deleted: services/zoneInteraction.ts and its suite (13 cases ported to
cargo), the TypeScript Finding builder and vertebra selection rules of the
pickers, store rules, persistence parsing, hydrateReport. ESLint forbids
@faunosteo/domain in apps/app/src; the report:compare CLI keeps the frozen
domain until R4 (scripts/compare/sheet.ts). App suite 313/313 on the real
core (24 new tests: quarantine, degraded editor, core failures, N-1
reader); step6 goldens and the frozen envelopes unchanged.
110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import type {
|
|
LateralSide,
|
|
Observation,
|
|
Vertebra,
|
|
} from '@faunosteo/core-wasm/types'
|
|
import VertebraPicker from '@/components/observation/VertebraPicker'
|
|
import LateralityPicker from '@/components/observation/LateralityPicker'
|
|
import { useReportStore } from '@/state/reportStore'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import { isObservable, type SheetIndex } from '@/services/sheetIndex'
|
|
import { pickLabel } from '@/i18n/pickLocaleLabel'
|
|
import { useT } from '@/i18n/useT'
|
|
|
|
/** The zone the vertebra picker edits, with its initial selection (computed on open). */
|
|
export interface VertebraTarget {
|
|
zoneIndex: number
|
|
initial: Vertebra[]
|
|
}
|
|
|
|
/** The bilateral annotation the laterality picker records sides for. */
|
|
export interface LateralTarget {
|
|
annotationId: string
|
|
sidesPresent: LateralSide[]
|
|
}
|
|
|
|
export interface ObservationPickersProps {
|
|
sheet: SheetIndex
|
|
activeIndex: number
|
|
activeObs: Observation | undefined
|
|
vertebraTarget: VertebraTarget | null
|
|
lateralTarget: LateralTarget | null
|
|
onCloseVertebra: () => void
|
|
onCloseLateral: () => void
|
|
}
|
|
|
|
/** Vertebra and laterality pickers of the active observation; the core applies the result. */
|
|
export default function ObservationPickers({
|
|
sheet,
|
|
activeIndex,
|
|
activeObs,
|
|
vertebraTarget,
|
|
lateralTarget,
|
|
onCloseVertebra,
|
|
onCloseLateral,
|
|
}: ObservationPickersProps) {
|
|
const t = useT()
|
|
const locale = useLocaleStore((s) => s.locale)
|
|
const updateObservation = useReportStore((s) => s.updateObservation)
|
|
const vertebraZone =
|
|
vertebraTarget !== null
|
|
? activeObs?.zones[vertebraTarget.zoneIndex]
|
|
: undefined
|
|
const vertebraAnnotation =
|
|
vertebraZone && sheet.annotation(vertebraZone.annotationId)
|
|
const lateralAnnotation =
|
|
lateralTarget && sheet.annotation(lateralTarget.annotationId)
|
|
|
|
/** Applies a core-built observation to the fresh active one; alerts on failure. */
|
|
function apply(
|
|
run: (fresh: Observation) => ReturnType<SheetIndex['ops']['addSides']>,
|
|
) {
|
|
const fresh = useReportStore.getState().report?.observations[activeIndex]
|
|
if (!fresh) return
|
|
const outcome = run(fresh)
|
|
if (outcome.ok) updateObservation(activeIndex, outcome.value)
|
|
else window.alert(t('core.action_failed'))
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{vertebraTarget !== null &&
|
|
activeObs &&
|
|
vertebraZone &&
|
|
isObservable(vertebraAnnotation) && (
|
|
<VertebraPicker
|
|
open
|
|
onClose={onCloseVertebra}
|
|
onConfirm={(vertebrae) => {
|
|
apply((fresh) =>
|
|
sheet.ops.syncVertebrae(fresh, vertebrae, vertebraZone.viewId),
|
|
)
|
|
onCloseVertebra()
|
|
}}
|
|
initial={vertebraTarget.initial}
|
|
regions={sheet.regions()}
|
|
title={`${t('vertebra.title_prefix')}${pickLabel(vertebraAnnotation.name, locale)}`}
|
|
initialRegion={
|
|
vertebraAnnotation.vertebral_region_code ?? undefined
|
|
}
|
|
/>
|
|
)}
|
|
|
|
{lateralTarget && activeObs && lateralAnnotation && (
|
|
<LateralityPicker
|
|
open
|
|
onClose={onCloseLateral}
|
|
title={pickLabel(sheet.name(lateralAnnotation), locale)}
|
|
existingSides={lateralTarget.sidesPresent}
|
|
onSelect={(sides: LateralSide[]) => {
|
|
apply((fresh) =>
|
|
sheet.ops.addSides(fresh, lateralTarget.annotationId, sides),
|
|
)
|
|
onCloseLateral()
|
|
}}
|
|
/>
|
|
)}
|
|
</>
|
|
)
|
|
}
|