fix(anatomy,editor): detail-popup clicks + spine zones open VertebraPicker via data-anno-special

Three coupled bugs in zone interaction:
1. Clicks inside the head detail popup were ignored — EditorRoute
   looked up the clicked id in the main-SVG bones map only, so
   detail-only ids (point-mpbykomv et al.) returned undefined.
2. Spine zones did not open VertebraPicker on click; the picker was
   only reachable via the per-zone "Vertèbres…" button.
3. The new SVG hint data-anno-special="vertebral-precision" was
   present in Horse.svg but unread by the parser/UI.

Parser now reads data-anno-special into Bone.special. EditorRoute
parses the detail SVG on open and falls back to detailBones for id
lookups. When bone.special === 'vertebral-precision', clicking adds
the zone (if absent) and opens VertebraPicker for that zone index;
toggle-off via main click is disabled for these zones (use ✕). The
"Vertèbres…" button in ObservationCard is now shown only on zones
that support it. Convention doc updated.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude committed 2026-05-19 04:58:04 +02:00
1 parent 21b678c3d5
commit b9da4fa04a
7 files changed
+86 -22

No files matched your search

+5
View File
@@ -52,6 +52,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
const category = el.getAttribute('data-anno-category') as BoneCategory
const opensDetail =
el.getAttribute('data-anno-opens-detail') ?? undefined
const special = el.getAttribute('data-anno-special') ?? undefined
const existing = map.get(id)
if (existing) {
@@ -59,6 +60,9 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
if (opensDetail && !existing.opensDetail) {
existing.opensDetail = opensDetail
}
if (special && !existing.special) {
existing.special = special
}
if (!existing.fr && fr) existing.fr = fr
if (!existing.en && en) existing.en = en
} else {
@@ -68,6 +72,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
en,
category,
opensDetail,
special,
els: [el],
})
}
+9
View File
@@ -24,6 +24,15 @@ export interface Bone {
category: BoneCategory
/** Detail popup id from data-anno-opens-detail, if present */
opensDetail?: string
/**
* Free-form behavior hint from `data-anno-special`.
*
* Known values consumed by the application:
* - `vertebral-precision`: clicking the zone opens VertebraPicker.
*
* Opaque to the parser; new values are accepted without code changes.
*/
special?: string
/** All DOM elements carrying this annotation (used for colorization) */
els: Element[]
}
+42 -9
View File
@@ -31,6 +31,7 @@ export default function EditorRoute() {
const setNextAppointment = useReportStore((s) => s.setNextAppointment)
const [bones, setBones] = useState<Map<string, Bone>>(new Map())
const [detailBones, setDetailBones] = useState<Map<string, Bone>>(new Map())
const [pathologies, setPathologies] = useState<Pathology[]>([])
const [detail, setDetail] = useState<{
id: string
@@ -55,6 +56,21 @@ export default function EditorRoute() {
species.pathologies().then((m) => setPathologies(m.default))
}, [species])
useEffect(() => {
if (!detail) {
setDetailBones(new Map())
return
}
let cancelled = false
loadSvg(detail.src).then((root) => {
if (cancelled) return
setDetailBones(parseSvgBones(root))
})
return () => {
cancelled = true
}
}, [detail])
const activeObs =
activeIndex >= 0 ? report?.observations[activeIndex] : undefined
@@ -82,7 +98,7 @@ export default function EditorRoute() {
function onZoneClick(boneId: string, detailSourceId?: string) {
if (!report) return
const bone = bones.get(boneId)
const bone = bones.get(boneId) ?? detailBones.get(boneId)
if (!bone) return
if (bone.opensDetail && species?.details[bone.opensDetail]) {
@@ -105,18 +121,35 @@ export default function EditorRoute() {
return
}
const matches = (z: ObservationZone) =>
z.boneId === boneId && z.detailSourceId === detailSourceId
const existingIndex = activeObs.zones.findIndex(matches)
if (bone.special === 'vertebral-precision') {
// Spine-zone behavior: always open VertebraPicker on click. Add the
// zone if missing; never toggle it off here (use the ✕ button).
let targetIndex = existingIndex
if (existingIndex < 0) {
const newZone: ObservationZone = {
boneId,
...(detailSourceId ? { detailSourceId } : {}),
}
const nextZones = [...activeObs.zones, newZone]
targetIndex = nextZones.length - 1
updateObservation(activeIndex, { ...activeObs, zones: nextZones })
}
setVertebraTarget(targetIndex)
return
}
const newZone: ObservationZone = {
boneId,
...(detailSourceId ? { detailSourceId } : {}),
}
const exists = activeObs.zones.some(
(z) => z.boneId === boneId && z.detailSourceId === detailSourceId,
)
const nextZones = exists
? activeObs.zones.filter(
(z) => !(z.boneId === boneId && z.detailSourceId === detailSourceId),
)
: [...activeObs.zones, newZone]
const nextZones =
existingIndex >= 0
? activeObs.zones.filter((_, k) => k !== existingIndex)
: [...activeObs.zones, newZone]
updateObservation(activeIndex, { ...activeObs, zones: nextZones })
}
+12 -8
View File
@@ -187,18 +187,22 @@ export default function ObservationCard({
<ul className="flex flex-wrap gap-2">
{observation.zones.map((z, i) => {
const b = bones.get(z.boneId)
const supportsVertebrae =
b?.special === 'vertebral-precision'
return (
<li key={`${z.boneId}-${i}`}>
<Badge tone="accent" className="gap-2">
{describeZone(z, bones)}
<button
type="button"
onClick={() => onOpenVertebraPicker(i)}
className="underline text-xs text-[var(--color-accent-strong)]"
title="Préciser les vertèbres pour cette zone"
>
Vertèbres…
</button>
{supportsVertebrae && (
<button
type="button"
onClick={() => onOpenVertebraPicker(i)}
className="underline text-xs text-[var(--color-accent-strong)]"
title="Préciser les vertèbres pour cette zone"
>
Vertèbres…
</button>
)}
<button
type="button"
aria-label={`Retirer ${b?.fr ?? z.boneId}`}