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:
1 parent
b7b094535e
commit
1731adf620
1 file changed
+36
-11
@@ -1,9 +1,13 @@
|
|||||||
|
import { useMemo } from 'react'
|
||||||
import type {
|
import type {
|
||||||
Observation,
|
Observation,
|
||||||
ObservationZone,
|
ObservationZone,
|
||||||
Vertebra,
|
Vertebra,
|
||||||
} from '@/domain/schema/observation'
|
} 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 type { Bone } from '@/anatomy/types'
|
||||||
import { AnimatePresence, motion } from 'motion/react'
|
import { AnimatePresence, motion } from 'motion/react'
|
||||||
import Card from '@/components/ui/Card'
|
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.
|
// SVG data-anno-id values are opaque (e.g. "point-mpbyk..."); the JSON
|
||||||
const uniqueZoneIds = Array.from(new Set(observation.zones.map((z) => z.boneId)))
|
// catalog keys observations by stable human zone names (e.g. "sphenoid").
|
||||||
const zonesWithTree = uniqueZoneIds
|
// We bridge the two via the French label parsed from data-anno-name-fr,
|
||||||
.map((id) => ({ id, tree: findings?.zones[id] }))
|
// which matches the JSON zone.name_fr exactly.
|
||||||
.filter((z): z is { id: string; tree: NonNullable<typeof z.tree> } =>
|
const labelToTree = useMemo(() => {
|
||||||
Boolean(z.tree),
|
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 (
|
return (
|
||||||
<Card
|
<Card
|
||||||
@@ -237,16 +262,16 @@ export default function ObservationCard({
|
|||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{zonesWithTree.map(({ id, tree }) => (
|
{zonesWithTree.map(({ tree }) => (
|
||||||
<div
|
<div
|
||||||
key={id}
|
key={tree.id}
|
||||||
className="rounded-xl border border-[var(--color-border)] p-3 bg-[var(--color-surface)]"
|
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">
|
<div className="text-xs uppercase tracking-wide text-[var(--color-ink-muted)] mb-2">
|
||||||
{tree.name_fr}
|
{tree.name_fr}
|
||||||
</div>
|
</div>
|
||||||
<FindingsTreePicker
|
<FindingsTreePicker
|
||||||
zoneId={id}
|
zoneId={tree.id}
|
||||||
tree={tree}
|
tree={tree}
|
||||||
selected={observation.findings}
|
selected={observation.findings}
|
||||||
onChange={(next) =>
|
onChange={(next) =>
|
||||||
|
|||||||
Reference in new issue
Block a user