fix(editor): match findings tree to SVG zone via FR label

SVG data-anno-id values are opaque generator strings (point-mpbyk...,
zone-mpbx...) that never match the human keys used in the findings
catalog (sphenoid, ssb, atm, ...). The picker therefore stayed hidden
whenever a zone was clicked.

ObservationCard now bridges the two via the FR label parsed from
data-anno-name-fr: it builds a name_fr → ZoneFindings index from the
loaded findings, looks up each observation zone by its Bone.fr, and
renders one picker per matched JSON tree (deduped on tree.id). Emitted
findings carry zoneId = tree.id (the JSON key), keeping the snapshot
contract intact.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-20 04:12:27 +02:00
1 parent b7b094535e
commit 1731adf620
1 file changed
+36 -11
+36 -11
View File
@@ -1,9 +1,13 @@
import { useMemo } from 'react'
import type {
Observation,
ObservationZone,
Vertebra,
} from '@/domain/schema/observation'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type {
SpeciesFindings,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import { AnimatePresence, motion } from 'motion/react'
import Card from '@/components/ui/Card'
@@ -79,13 +83,34 @@ export default function ObservationCard({
}
}
// Deduplicate zones by boneId so we don't render the same picker tree twice.
const uniqueZoneIds = Array.from(new Set(observation.zones.map((z) => z.boneId)))
const zonesWithTree = uniqueZoneIds
.map((id) => ({ id, tree: findings?.zones[id] }))
.filter((z): z is { id: string; tree: NonNullable<typeof z.tree> } =>
Boolean(z.tree),
)
// SVG data-anno-id values are opaque (e.g. "point-mpbyk..."); the JSON
// catalog keys observations by stable human zone names (e.g. "sphenoid").
// We bridge the two via the French label parsed from data-anno-name-fr,
// which matches the JSON zone.name_fr exactly.
const labelToTree = useMemo(() => {
const m = new Map<string, ZoneFindings>()
if (!findings) return m
for (const tree of Object.values(findings.zones)) {
m.set(tree.name_fr, tree)
}
return m
}, [findings])
const zonesWithTree = useMemo(() => {
if (!findings) return [] as { tree: ZoneFindings }[]
const seen = new Set<string>()
const out: { tree: ZoneFindings }[] = []
for (const z of observation.zones) {
const label = bones.get(z.boneId)?.fr
if (!label) continue
const tree = labelToTree.get(label)
if (!tree) continue
if (seen.has(tree.id)) continue
seen.add(tree.id)
out.push({ tree })
}
return out
}, [observation.zones, bones, findings, labelToTree])
return (
<Card
@@ -237,16 +262,16 @@ export default function ObservationCard({
</p>
) : (
<div className="space-y-4">
{zonesWithTree.map(({ id, tree }) => (
{zonesWithTree.map(({ tree }) => (
<div
key={id}
key={tree.id}
className="rounded-xl border border-[var(--color-border)] p-3 bg-[var(--color-surface)]"
>
<div className="text-xs uppercase tracking-wide text-[var(--color-ink-muted)] mb-2">
{tree.name_fr}
</div>
<FindingsTreePicker
zoneId={id}
zoneId={tree.id}
tree={tree}
selected={observation.findings}
onChange={(next) =>