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
@@ -25,6 +25,14 @@ describe('reportStore.initReport', () => {
|
||||
expect(r.practitioner.name).toBe('Dr. Dupont')
|
||||
})
|
||||
|
||||
it('seeds a single empty observation when the draft has none', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
const r = useReportStore.getState().report!
|
||||
expect(r.observations.length).toBe(1)
|
||||
expect(r.observations[0].zones).toEqual([])
|
||||
expect(r.observations[0].comment).toBe('')
|
||||
})
|
||||
|
||||
it('resets activeObservationIndex to 0', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
expect(useReportStore.getState().activeObservationIndex).toBe(0)
|
||||
@@ -44,8 +52,8 @@ describe('reportStore.addObservation', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
useReportStore.getState().addObservation()
|
||||
const s = useReportStore.getState()
|
||||
expect(s.report!.observations.length).toBe(1)
|
||||
expect(s.activeObservationIndex).toBe(0)
|
||||
expect(s.report!.observations.length).toBe(2)
|
||||
expect(s.activeObservationIndex).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,21 +73,21 @@ describe('reportStore.updateObservation', () => {
|
||||
describe('reportStore.removeObservation', () => {
|
||||
it('drops the observation at the given index', () => {
|
||||
const store = useReportStore.getState()
|
||||
store.initReport(draft)
|
||||
store.initReport(draft) // seeds 1
|
||||
store.addObservation()
|
||||
store.addObservation()
|
||||
store.removeObservation(0)
|
||||
expect(useReportStore.getState().report!.observations.length).toBe(1)
|
||||
expect(useReportStore.getState().report!.observations.length).toBe(2)
|
||||
})
|
||||
|
||||
it('clamps activeObservationIndex within bounds', () => {
|
||||
const store = useReportStore.getState()
|
||||
store.initReport(draft)
|
||||
store.initReport(draft) // seeds 1
|
||||
store.addObservation()
|
||||
store.addObservation()
|
||||
store.setActiveObservation(1)
|
||||
store.removeObservation(1)
|
||||
expect(useReportStore.getState().activeObservationIndex).toBe(0)
|
||||
store.addObservation() // total 3
|
||||
store.setActiveObservation(2)
|
||||
store.removeObservation(2)
|
||||
expect(useReportStore.getState().activeObservationIndex).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user