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}