From 5a19ae1f32c15505c83d835f23cda9b2332a2203 Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Sat, 23 May 2026 22:18:25 +0200 Subject: [PATCH] feat(editor): integrate LateralityPicker in zone click flow Insert bilateral check in onZoneClick between vertebral-precision and unpaired toggle logic. Both-sides-present clears all matching zones; otherwise opens LateralityPicker to let user pick L/R/both. Co-Authored-By: Claude --- src/app/routes/EditorRoute.tsx | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/app/routes/EditorRoute.tsx b/src/app/routes/EditorRoute.tsx index 85211ed7..00de8133 100644 --- a/src/app/routes/EditorRoute.tsx +++ b/src/app/routes/EditorRoute.tsx @@ -6,6 +6,8 @@ import ObservationList from '@/components/observation/ObservationList' import VertebraPicker, { regionFromLabel, } from '@/components/observation/VertebraPicker' +import LateralityPicker from '@/components/observation/LateralityPicker' +import type { LateralSide } from '@/domain/schema/observation' import ConclusionPanel from '@/components/report/ConclusionPanel' import ReportHeader from '@/components/report/ReportHeader' import PractitionerForm from '@/components/report/PractitionerForm' @@ -58,6 +60,10 @@ export default function EditorRoute() { title: string } | null>(null) const [vertebraTarget, setVertebraTarget] = useState(null) + const [lateralTarget, setLateralTarget] = useState<{ + boneId: string + detailSourceId?: string + } | null>(null) const [exporting, setExporting] = useState(false) const [editOpen, setEditOpen] = useState(false) const [editDraft, setEditDraft] = useState<{ @@ -240,6 +246,32 @@ export default function EditorRoute() { return } + if (bone.lateral === 'bilateral') { + const sidesPresent = activeObs.zones + .filter( + (z) => + z.boneId === boneId && + z.detailSourceId === detailSourceId, + ) + .map((z) => z.side) + .filter(Boolean) as LateralSide[] + + if (sidesPresent.includes('left') && sidesPresent.includes('right')) { + const nextZones = activeObs.zones.filter( + (z) => + !(z.boneId === boneId && z.detailSourceId === detailSourceId), + ) + updateObservation(activeIndex, { ...activeObs, zones: nextZones }) + return + } + + setLateralTarget({ + boneId, + ...(detailSourceId ? { detailSourceId } : {}), + }) + return + } + const newZone: ObservationZone = { boneId, ...(detailSourceId ? { detailSourceId } : {}), @@ -424,6 +456,56 @@ export default function EditorRoute() { })()} /> )} + + {lateralTarget && activeObs && ( + setLateralTarget(null)} + title={boneLabel( + allBones.get(lateralTarget.boneId), + locale, + lateralTarget.boneId, + )} + existingSides={ + activeObs.zones + .filter( + (z) => + z.boneId === lateralTarget.boneId && + z.detailSourceId === lateralTarget.detailSourceId && + z.side, + ) + .map((z) => z.side!) as LateralSide[] + } + onSelect={(sides) => { + const fresh = + useReportStore.getState().report?.observations[activeIndex] + if (!fresh) { + setLateralTarget(null) + return + } + let nextZones = [...fresh.zones] + for (const side of sides) { + const exists = nextZones.some( + (z) => + z.boneId === lateralTarget.boneId && + z.detailSourceId === lateralTarget.detailSourceId && + z.side === side, + ) + if (!exists) { + nextZones.push({ + boneId: lateralTarget.boneId, + ...(lateralTarget.detailSourceId + ? { detailSourceId: lateralTarget.detailSourceId } + : {}), + side, + }) + } + } + updateObservation(activeIndex, { ...fresh, zones: nextZones }) + setLateralTarget(null) + }} + /> + )} ) }