fix(editor): scope zone highlight to active obs + repaint detail SVG + harmonize header
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
19c9c15979
commit
ff7ac5969e
3 files changed
+28
-19
No files matched your search
@@ -133,18 +133,11 @@ export default function EditorRoute() {
|
|||||||
|
|
||||||
const boneStates = useMemo<Map<string, BoneState>>(() => {
|
const boneStates = useMemo<Map<string, BoneState>>(() => {
|
||||||
const map = new Map<string, BoneState>()
|
const map = new Map<string, BoneState>()
|
||||||
if (!report) return map
|
if (!report || activeIndex < 0) return map
|
||||||
report.observations.forEach((obs, i) => {
|
const active = report.observations[activeIndex]
|
||||||
obs.zones.forEach((z) => {
|
if (!active) return map
|
||||||
const prev = map.get(z.boneId)
|
active.zones.forEach((z) => {
|
||||||
if (i === activeIndex) {
|
map.set(z.boneId, 'current')
|
||||||
map.set(z.boneId, prev === undefined ? 'current' : 'multi')
|
|
||||||
} else if (prev === undefined) {
|
|
||||||
map.set(z.boneId, 'linked')
|
|
||||||
} else {
|
|
||||||
map.set(z.boneId, 'multi')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
return map
|
return map
|
||||||
}, [report, activeIndex])
|
}, [report, activeIndex])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState } from 'react'
|
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 PractitionerForm from '@/components/report/PractitionerForm'
|
||||||
import AnimalForm from '@/components/report/AnimalForm'
|
import AnimalForm from '@/components/report/AnimalForm'
|
||||||
import Brand from '@/components/brand/Brand'
|
import Brand from '@/components/brand/Brand'
|
||||||
@@ -43,9 +43,22 @@ export default function NewReportRoute() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen">
|
<main className="min-h-screen">
|
||||||
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center justify-between">
|
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center gap-3">
|
||||||
<Brand />
|
<Button
|
||||||
<Button variant="ghost" onClick={() => navigate('/')}>← Accueil</Button>
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => navigate('/')}
|
||||||
|
aria-label="Retour à l'accueil"
|
||||||
|
>
|
||||||
|
← Accueil
|
||||||
|
</Button>
|
||||||
|
<Link
|
||||||
|
to="/"
|
||||||
|
aria-label="Retour à l'accueil"
|
||||||
|
className="rounded-md px-1 py-0.5 hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||||
|
>
|
||||||
|
<Brand />
|
||||||
|
</Link>
|
||||||
</header>
|
</header>
|
||||||
<div className="max-w-3xl mx-auto px-6 py-8 space-y-8">
|
<div className="max-w-3xl mx-auto px-6 py-8 space-y-8">
|
||||||
<h1 className="font-serif text-3xl">Nouveau bilan</h1>
|
<h1 className="font-serif text-3xl">Nouveau bilan</h1>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { loadSvg } from '@/anatomy/svgLoader'
|
import { loadSvg } from '@/anatomy/svgLoader'
|
||||||
import { getBoneIdFromEvent } from '@/anatomy/svgConvention'
|
import { getBoneIdFromEvent } from '@/anatomy/svgConvention'
|
||||||
import type { BoneState } from '@/anatomy/types'
|
import type { BoneState } from '@/anatomy/types'
|
||||||
@@ -17,15 +17,18 @@ export default function AnatomyCanvas({
|
|||||||
className = '',
|
className = '',
|
||||||
}: AnatomyCanvasProps) {
|
}: AnatomyCanvasProps) {
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
const [loadedSrc, setLoadedSrc] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
const c = containerRef.current
|
const c = containerRef.current
|
||||||
if (!c) return
|
if (!c) return
|
||||||
c.replaceChildren()
|
c.replaceChildren()
|
||||||
|
setLoadedSrc(null)
|
||||||
loadSvg(src).then((root) => {
|
loadSvg(src).then((root) => {
|
||||||
if (cancelled || !c) return
|
if (cancelled || !c) return
|
||||||
c.appendChild(root)
|
c.appendChild(root)
|
||||||
|
setLoadedSrc(src)
|
||||||
})
|
})
|
||||||
return () => { cancelled = true }
|
return () => { cancelled = true }
|
||||||
}, [src])
|
}, [src])
|
||||||
@@ -43,7 +46,7 @@ export default function AnatomyCanvas({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const c = containerRef.current
|
const c = containerRef.current
|
||||||
if (!c) return
|
if (!c || loadedSrc !== src) return
|
||||||
const all = c.querySelectorAll<Element>('[data-anno-id]')
|
const all = c.querySelectorAll<Element>('[data-anno-id]')
|
||||||
all.forEach((el) => {
|
all.forEach((el) => {
|
||||||
const id = el.getAttribute('data-anno-id') as string
|
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)
|
if (state && state !== 'default') el.setAttribute('data-state', state)
|
||||||
else el.removeAttribute('data-state')
|
else el.removeAttribute('data-state')
|
||||||
})
|
})
|
||||||
}, [boneStates])
|
}, [boneStates, loadedSrc, src])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in new issue
Block a user