fix(editor,pdf): accordion observation cards + seed 1 obs + native SVG rasterization
Three issues from manual QA: 1. UX restructure — observations are now an accordion list. Each card has a header that's always visible (title + chips + chevron + action buttons) and a body that expands inline showing zones / pathologies / severity / comment. Click the header (or the chevron) to toggle. ObservationEditor has been merged into ObservationCard so each card owns its own details. Only one observation is expanded at a time; the chevron on the active card collapses everything. EditorRoute uses activeObservationIndex === -1 to represent "all collapsed". 2. App used to start with 2 observations instead of 1. Root cause: EditorRoute had a "seed first observation" useEffect that fired twice under React 19 StrictMode in dev, both invocations seeing length=0 and queueing addObservation(). Fixed by moving the seed into the store's initReport (synchronous, one-shot) and removing the useEffect entirely. Store tests updated to assert the seed behaviour (90/90 pass). 3. PDF export still failed with "The input is not a PNG file!" — canvg was returning bytes that pdf-lib rejected at embedPng(). Switched rasterizeSvg to the browser-native pipeline: serialize the SVG into a Blob URL, load it with an Image element, drawImage onto a 2D canvas, then toBlob → PNG bytes (with a toDataURL fallback). Validates the PNG signature before returning. Tree-shaking dropped canvg from the bundle (979 kB → 874 kB JS). Tests updated for the new initReport behaviour and the new svgToPng pipeline (Image mock + dataURL fallback case). lint + typecheck + build all clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bdf5e6475b
commit
e8c29c1fdf
7 files changed
+449
-113
No files matched your search
@@ -3,7 +3,6 @@ import { useNavigate } from 'react-router-dom'
|
||||
import AnatomyCanvas from '@/components/canvas/AnatomyCanvas'
|
||||
import DetailModal from '@/components/canvas/DetailModal'
|
||||
import ObservationList from '@/components/observation/ObservationList'
|
||||
import ObservationEditor from '@/components/observation/ObservationEditor'
|
||||
import VertebraPicker from '@/components/observation/VertebraPicker'
|
||||
import ConclusionPanel from '@/components/report/ConclusionPanel'
|
||||
import ReportHeader from '@/components/report/ReportHeader'
|
||||
@@ -33,7 +32,11 @@ export default function EditorRoute() {
|
||||
|
||||
const [bones, setBones] = useState<Map<string, Bone>>(new Map())
|
||||
const [pathologies, setPathologies] = useState<Pathology[]>([])
|
||||
const [detail, setDetail] = useState<{ id: string; src: string; title: string } | null>(null)
|
||||
const [detail, setDetail] = useState<{
|
||||
id: string
|
||||
src: string
|
||||
title: string
|
||||
} | null>(null)
|
||||
const [vertebraTarget, setVertebraTarget] = useState<number | null>(null)
|
||||
const [exporting, setExporting] = useState(false)
|
||||
|
||||
@@ -52,12 +55,8 @@ export default function EditorRoute() {
|
||||
species.pathologies().then((m) => setPathologies(m.default))
|
||||
}, [species])
|
||||
|
||||
const observationsCount = report?.observations.length ?? -1
|
||||
useEffect(() => {
|
||||
if (observationsCount === 0) addObservation()
|
||||
}, [observationsCount, addObservation])
|
||||
|
||||
const activeObs = report?.observations[activeIndex]
|
||||
const activeObs =
|
||||
activeIndex >= 0 ? report?.observations[activeIndex] : undefined
|
||||
|
||||
const boneStates = useMemo<Map<string, BoneState>>(() => {
|
||||
const map = new Map<string, BoneState>()
|
||||
@@ -77,8 +76,12 @@ export default function EditorRoute() {
|
||||
return map
|
||||
}, [report, activeIndex])
|
||||
|
||||
function onToggleCard(index: number) {
|
||||
setActiveObservation(activeIndex === index ? -1 : index)
|
||||
}
|
||||
|
||||
function onZoneClick(boneId: string, detailSourceId?: string) {
|
||||
if (!report || !activeObs) return
|
||||
if (!report) return
|
||||
const bone = bones.get(boneId)
|
||||
if (!bone) return
|
||||
|
||||
@@ -91,6 +94,17 @@ export default function EditorRoute() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!activeObs || activeIndex < 0) {
|
||||
// No expanded observation — auto-expand the most recent one (or the
|
||||
// first if no rows yet) so the click lands somewhere.
|
||||
const fallbackIndex =
|
||||
report.observations.length > 0 ? report.observations.length - 1 : -1
|
||||
if (fallbackIndex < 0) return
|
||||
setActiveObservation(fallbackIndex)
|
||||
// Defer the actual zone add to the next render where activeObs is set.
|
||||
return
|
||||
}
|
||||
|
||||
const newZone: ObservationZone = {
|
||||
boneId,
|
||||
...(detailSourceId ? { detailSourceId } : {}),
|
||||
@@ -132,7 +146,7 @@ export default function EditorRoute() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!report || !species || !activeObs) return null
|
||||
if (!report || !species) return null
|
||||
|
||||
return (
|
||||
<main className="min-h-screen flex flex-col">
|
||||
@@ -149,22 +163,23 @@ export default function EditorRoute() {
|
||||
<ObservationList
|
||||
observations={report.observations}
|
||||
activeIndex={activeIndex}
|
||||
onSelect={setActiveObservation}
|
||||
onToggle={onToggleCard}
|
||||
onAdd={addObservation}
|
||||
onDelete={removeObservation}
|
||||
onMoveUp={moveObservationUp}
|
||||
onMoveDown={moveObservationDown}
|
||||
/>
|
||||
<ObservationEditor
|
||||
observation={activeObs}
|
||||
bones={bones}
|
||||
speciesId={species.id}
|
||||
pathologyPool={pathologies}
|
||||
onChange={(next: Observation) => updateObservation(activeIndex, next)}
|
||||
onOpenVertebraPicker={(zoneIndex) => setVertebraTarget(zoneIndex)}
|
||||
onRemoveZone={(zoneIndex) => {
|
||||
const zones = activeObs.zones.filter((_, i) => i !== zoneIndex)
|
||||
updateObservation(activeIndex, { ...activeObs, zones })
|
||||
onChange={(i, next: Observation) => updateObservation(i, next)}
|
||||
onOpenVertebraPicker={(_i, zoneIndex) =>
|
||||
setVertebraTarget(zoneIndex)
|
||||
}
|
||||
onRemoveZone={(i, zoneIndex) => {
|
||||
const obs = report.observations[i]
|
||||
if (!obs) return
|
||||
const zones = obs.zones.filter((_, k) => k !== zoneIndex)
|
||||
updateObservation(i, { ...obs, zones })
|
||||
}}
|
||||
/>
|
||||
<ConclusionPanel
|
||||
@@ -195,26 +210,29 @@ export default function EditorRoute() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{vertebraTarget !== null && activeObs.zones[vertebraTarget] && (
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => setVertebraTarget(null)}
|
||||
onConfirm={(vertebrae) => {
|
||||
const fresh = useReportStore.getState().report?.observations[activeIndex]
|
||||
if (!fresh?.zones[vertebraTarget]) {
|
||||
{vertebraTarget !== null &&
|
||||
activeObs &&
|
||||
activeObs.zones[vertebraTarget] && (
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => setVertebraTarget(null)}
|
||||
onConfirm={(vertebrae) => {
|
||||
const fresh =
|
||||
useReportStore.getState().report?.observations[activeIndex]
|
||||
if (!fresh?.zones[vertebraTarget]) {
|
||||
setVertebraTarget(null)
|
||||
return
|
||||
}
|
||||
const next = [...fresh.zones]
|
||||
next[vertebraTarget] = { ...next[vertebraTarget], vertebrae }
|
||||
updateObservation(activeIndex, { ...fresh, zones: next })
|
||||
setVertebraTarget(null)
|
||||
return
|
||||
}
|
||||
const next = [...fresh.zones]
|
||||
next[vertebraTarget] = { ...next[vertebraTarget], vertebrae }
|
||||
updateObservation(activeIndex, { ...fresh, zones: next })
|
||||
setVertebraTarget(null)
|
||||
}}
|
||||
initial={activeObs.zones[vertebraTarget].vertebrae ?? []}
|
||||
formula={species.vertebralFormula}
|
||||
title={`Préciser les vertèbres — ${bones.get(activeObs.zones[vertebraTarget].boneId)?.fr ?? ''}`}
|
||||
/>
|
||||
)}
|
||||
}}
|
||||
initial={activeObs.zones[vertebraTarget].vertebrae ?? []}
|
||||
formula={species.vertebralFormula}
|
||||
title={`Préciser les vertèbres — ${bones.get(activeObs.zones[vertebraTarget].boneId)?.fr ?? ''}`}
|
||||
/>
|
||||
)}
|
||||
</main>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user