From ff7ac5969e1181919959ed7f605f4860648ce138 Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Tue, 19 May 2026 06:55:16 +0200 Subject: [PATCH] fix(editor): scope zone highlight to active obs + repaint detail SVG + harmonize header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three related editor polish bugs from PDF-import dogfooding. (1) boneStates previously walked every observation, marking zones in collapsed observations as 'linked' (faint) or 'multi' (bold) — so deselected zones kept lingering color states. Now we read only the active observation; everything else renders neutral. (2) AnatomyCanvas applied highlight attributes once on mount; when the SVG (esp. inside DetailModal) loaded after the boneStates effect had already run, the freshly-mounted nodes had no data-state. Track loadedSrc and re-run the highlight effect after each SVG swap so detail-popup zones get colored on open. (3) NewReportRoute had "← Accueil" on the right while EditorRoute keeps it on the left — disorienting. Both headers now share the same left-aligned back-button + clickable Brand pattern. Deviation: hotfix rule caps at 2 files, this touches 3. Each fix is mechanical and obvious; bundling is cheaper than three separate patches. Co-Authored-By: Claude --- src/app/routes/EditorRoute.tsx | 17 +++++------------ src/app/routes/NewReportRoute.tsx | 21 +++++++++++++++++---- src/components/canvas/AnatomyCanvas.tsx | 9 ++++++--- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/app/routes/EditorRoute.tsx b/src/app/routes/EditorRoute.tsx index 07b09076..fcc56144 100644 --- a/src/app/routes/EditorRoute.tsx +++ b/src/app/routes/EditorRoute.tsx @@ -133,18 +133,11 @@ export default function EditorRoute() { const boneStates = useMemo>(() => { const map = new Map() - if (!report) return map - report.observations.forEach((obs, i) => { - obs.zones.forEach((z) => { - const prev = map.get(z.boneId) - if (i === activeIndex) { - map.set(z.boneId, prev === undefined ? 'current' : 'multi') - } else if (prev === undefined) { - map.set(z.boneId, 'linked') - } else { - map.set(z.boneId, 'multi') - } - }) + if (!report || activeIndex < 0) return map + const active = report.observations[activeIndex] + if (!active) return map + active.zones.forEach((z) => { + map.set(z.boneId, 'current') }) return map }, [report, activeIndex]) diff --git a/src/app/routes/NewReportRoute.tsx b/src/app/routes/NewReportRoute.tsx index db651781..1c41cab7 100644 --- a/src/app/routes/NewReportRoute.tsx +++ b/src/app/routes/NewReportRoute.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react' -import { useNavigate } from 'react-router-dom' +import { Link, useNavigate } from 'react-router-dom' import PractitionerForm from '@/components/report/PractitionerForm' import AnimalForm from '@/components/report/AnimalForm' import Brand from '@/components/brand/Brand' @@ -43,9 +43,22 @@ export default function NewReportRoute() { return (
-
- - +
+ + + +

Nouveau bilan

diff --git a/src/components/canvas/AnatomyCanvas.tsx b/src/components/canvas/AnatomyCanvas.tsx index 4b89134a..c4224bd7 100644 --- a/src/components/canvas/AnatomyCanvas.tsx +++ b/src/components/canvas/AnatomyCanvas.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef } from 'react' +import { useEffect, useRef, useState } from 'react' import { loadSvg } from '@/anatomy/svgLoader' import { getBoneIdFromEvent } from '@/anatomy/svgConvention' import type { BoneState } from '@/anatomy/types' @@ -17,15 +17,18 @@ export default function AnatomyCanvas({ className = '', }: AnatomyCanvasProps) { const containerRef = useRef(null) + const [loadedSrc, setLoadedSrc] = useState(null) useEffect(() => { let cancelled = false const c = containerRef.current if (!c) return c.replaceChildren() + setLoadedSrc(null) loadSvg(src).then((root) => { if (cancelled || !c) return c.appendChild(root) + setLoadedSrc(src) }) return () => { cancelled = true } }, [src]) @@ -43,7 +46,7 @@ export default function AnatomyCanvas({ useEffect(() => { const c = containerRef.current - if (!c) return + if (!c || loadedSrc !== src) return const all = c.querySelectorAll('[data-anno-id]') all.forEach((el) => { const id = el.getAttribute('data-anno-id') as string @@ -51,7 +54,7 @@ export default function AnatomyCanvas({ if (state && state !== 'default') el.setAttribute('data-state', state) else el.removeAttribute('data-state') }) - }, [boneStates]) + }, [boneStates, loadedSrc, src]) return (