From 1731adf620aa898c701333e8335d5a4a0008b5f2 Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Wed, 20 May 2026 04:12:27 +0200 Subject: [PATCH] fix(editor): match findings tree to SVG zone via FR label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../observation/ObservationCard.tsx | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/components/observation/ObservationCard.tsx b/src/components/observation/ObservationCard.tsx index f709b405..dae16325 100644 --- a/src/components/observation/ObservationCard.tsx +++ b/src/components/observation/ObservationCard.tsx @@ -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 } => - 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() + 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() + 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 ( ) : (
- {zonesWithTree.map(({ id, tree }) => ( + {zonesWithTree.map(({ tree }) => (
{tree.name_fr}