diff --git a/src/components/observation/FindingsTreePicker.tsx b/src/components/observation/FindingsTreePicker.tsx index 0f5b256d..221aae5f 100644 --- a/src/components/observation/FindingsTreePicker.tsx +++ b/src/components/observation/FindingsTreePicker.tsx @@ -4,7 +4,7 @@ import type { FindingNode, ZoneFindings, } from '@/domain/schema/findings' -import type { Finding } from '@/domain/schema/observation' +import type { Finding, LateralSide } from '@/domain/schema/observation' import Button from '@/components/ui/Button' import { useT } from '@/i18n/useT' import { useLocaleStore } from '@/state/localeStore' @@ -17,6 +17,7 @@ const levelVariants = { export interface FindingsTreePickerProps { zoneId: string tree: ZoneFindings + side?: LateralSide selected: Finding[] onChange: (next: Finding[]) => void } @@ -58,6 +59,7 @@ function findNode( export default function FindingsTreePicker({ zoneId, tree, + side, selected, onChange, }: FindingsTreePickerProps) { @@ -112,16 +114,20 @@ export default function FindingsTreePicker({ return crumbs }, [tree, path, locale]) + function matchesSide(f: Finding): boolean { + return f.zoneId === zoneId && f.side === side + } + function isLeafSelected(leafPath: string[]): boolean { return selected.some( - (f) => f.zoneId === zoneId && samePath(f.path, leafPath), + (f) => matchesSide(f) && samePath(f.path, leafPath), ) } function countSelectedUnder(nodePath: string[]): number { let n = 0 for (const f of selected) { - if (f.zoneId !== zoneId) continue + if (!matchesSide(f)) continue if (!pathStartsWith(f.path, nodePath)) continue n += 1 } @@ -132,7 +138,7 @@ export default function FindingsTreePicker({ if (isLeafSelected(leafPath)) { onChange( selected.filter( - (f) => !(f.zoneId === zoneId && samePath(f.path, leafPath)), + (f) => !(matchesSide(f) && samePath(f.path, leafPath)), ), ) return @@ -144,6 +150,7 @@ export default function FindingsTreePicker({ labelEnSnapshot: leaf.name_en, } if (leaf.requires_vet_referral) next.requiresVetReferral = true + if (side) next.side = side onChange([...selected, next]) } diff --git a/src/components/observation/ObservationCard.tsx b/src/components/observation/ObservationCard.tsx index a9787488..86de9ea6 100644 --- a/src/components/observation/ObservationCard.tsx +++ b/src/components/observation/ObservationCard.tsx @@ -3,6 +3,7 @@ import type { Observation, ObservationZone, Vertebra, + LateralSide, } from '@/domain/schema/observation' import type { SpeciesFindings, @@ -123,9 +124,10 @@ export default function ObservationCard({ ) const zonesWithTree = useMemo(() => { - if (zonesArray.length === 0) return [] as { tree: ZoneFindings }[] + if (zonesArray.length === 0) + return [] as { tree: ZoneFindings; side?: LateralSide }[] const seen = new Set() - const out: { tree: ZoneFindings }[] = [] + const out: { tree: ZoneFindings; side?: LateralSide }[] = [] for (const z of observation.zones) { const bone = bones.get(z.boneId) if (!bone) continue @@ -134,9 +136,10 @@ export default function ObservationCard({ zonesArray, ) if (!tree) continue - if (seen.has(tree.id)) continue - seen.add(tree.id) - out.push({ tree }) + const key = z.side ? `${tree.id}:${z.side}` : tree.id + if (seen.has(key)) continue + seen.add(key) + out.push({ tree, side: z.side }) } return out }, [observation.zones, bones, zonesArray]) @@ -289,10 +292,14 @@ export default function ObservationCard({

) : (