feat(editor): findings tree picker + scope disclaimer + PDF render

Replaces the flat PathologyPicker with FindingsTreePicker — breadcrumb
navigation, drill into intermediate categories, toggle leaves, optional
vet-referral badge, optional description rendering. One picker per zone
that has a catalog entry; zones without a tree fall back to the free-text
input (renamed FreeTextFindingInput to match the new vocabulary).

EditorRoute now loads SpeciesFindings instead of a Pathology[] and shows
the scope_disclaimer once per session via a sessionStorage flag so the
practitioner is reminded of the legal perimeter the first time.

PDF observationPage renders findings via the snapshotted FR label and
prefixes ⚠ on vet-referral items, keeping the existing layout pipeline
intact (LRN-007/008/009 still apply).

Also drops the unused Toast and ZoneTooltip stubs, refreshes the
CLAUDE.md folder map, and adds a FindingsTreePicker test covering
navigation, leaf toggle, vet-referral flag, and back-out.

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 03:49:11 +02:00
1 parent d08d773d74
commit b67f4cd82b
12 files changed
+473 -186

No files matched your search

@@ -0,0 +1,208 @@
import { useMemo, useState } from 'react'
import type {
FindingNode,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Finding } from '@/domain/schema/observation'
import Button from '@/components/ui/Button'
export interface FindingsTreePickerProps {
zoneId: string
tree: ZoneFindings
selected: Finding[]
onChange: (next: Finding[]) => void
}
function isLeaf(node: FindingNode): boolean {
return !node.children || node.children.length === 0
}
function samePath(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false
for (let i = 0; i < a.length; i += 1) {
if (a[i] !== b[i]) return false
}
return true
}
function findNode(
categories: FindingNode[],
path: string[],
): FindingNode | undefined {
let nodes: FindingNode[] = categories
let node: FindingNode | undefined
for (const segment of path) {
node = nodes.find((n) => n.id === segment)
if (!node) return undefined
nodes = node.children ?? []
}
return node
}
export default function FindingsTreePicker({
zoneId,
tree,
selected,
onChange,
}: FindingsTreePickerProps) {
const [path, setPath] = useState<string[]>([])
const currentNodes = useMemo<FindingNode[]>(() => {
if (path.length === 0) return tree.categories
const node = findNode(tree.categories, path)
return node?.children ?? []
}, [tree, path])
const focusedNode = useMemo(
() => (path.length === 0 ? undefined : findNode(tree.categories, path)),
[tree, path],
)
const breadcrumb = useMemo<{ label: string; depth: number }[]>(() => {
const crumbs: { label: string; depth: number }[] = [
{ label: tree.name_fr, depth: 0 },
]
let nodes: FindingNode[] = tree.categories
path.forEach((seg, i) => {
const n = nodes.find((x) => x.id === seg)
if (n) {
crumbs.push({ label: n.name_fr, depth: i + 1 })
nodes = n.children ?? []
}
})
return crumbs
}, [tree, path])
function isLeafSelected(leafPath: string[]): boolean {
return selected.some(
(f) => f.zoneId === zoneId && samePath(f.path, leafPath),
)
}
function toggleLeaf(leafPath: string[], leaf: FindingNode) {
if (isLeafSelected(leafPath)) {
onChange(
selected.filter(
(f) => !(f.zoneId === zoneId && samePath(f.path, leafPath)),
),
)
return
}
const next: Finding = {
zoneId,
path: leafPath,
labelFrSnapshot: leaf.name_fr,
labelEnSnapshot: leaf.name_en,
}
if (leaf.requires_vet_referral) next.requiresVetReferral = true
onChange([...selected, next])
}
return (
<div className="space-y-2">
<div className="flex flex-wrap items-center gap-1 text-xs text-[var(--color-ink-muted)]">
{breadcrumb.map((c, i) => {
const isLast = i === breadcrumb.length - 1
return (
<span key={`${c.label}-${i}`} className="flex items-center gap-1">
<button
type="button"
onClick={() => setPath(path.slice(0, c.depth))}
disabled={isLast}
className={
isLast
? 'text-[var(--color-ink)] font-medium'
: 'underline text-[var(--color-accent-strong)]'
}
>
{c.label}
</button>
{!isLast && <span aria-hidden="true">›</span>}
</span>
)
})}
</div>
{focusedNode?.description_fr && (
<p className="text-xs italic text-[var(--color-ink-muted)]">
{focusedNode.description_fr}
</p>
)}
{path.length > 0 && (
<Button
size="sm"
variant="ghost"
onClick={() => setPath(path.slice(0, -1))}
aria-label="Retour au niveau précédent"
>
← Retour
</Button>
)}
<ul className="space-y-1.5 max-h-64 overflow-auto pr-1">
{currentNodes.length === 0 ? (
<li className="text-sm text-[var(--color-ink-muted)]">
Aucune option disponible à ce niveau.
</li>
) : (
currentNodes.map((node) => {
const nodePath = [...path, node.id]
if (isLeaf(node)) {
const checked = isLeafSelected(nodePath)
return (
<li key={node.id}>
<label className="flex items-start gap-2 cursor-pointer">
<input
type="checkbox"
checked={checked}
onChange={() => toggleLeaf(nodePath, node)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={node.name_fr}
/>
<div className="flex-1">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{node.name_fr}
</span>
{node.requires_vet_referral && (
<span
title="Référer au vétérinaire"
aria-label="Référer au vétérinaire"
className="text-[var(--color-danger)]"
>
⚠
</span>
)}
</div>
{node.description_fr && (
<div className="text-xs text-[var(--color-ink-muted)]">
{node.description_fr}
</div>
)}
</div>
</label>
</li>
)
}
return (
<li key={node.id}>
<button
type="button"
onClick={() => setPath(nodePath)}
className="flex items-center justify-between w-full text-left text-sm px-2 py-1.5 rounded hover:bg-[var(--color-surface-strong)] text-[var(--color-ink)]"
aria-label={`Ouvrir ${node.name_fr}`}
>
<span>{node.name_fr}</span>
<span aria-hidden="true" className="text-[var(--color-ink-muted)]">
›
</span>
</button>
</li>
)
})
)}
</ul>
</div>
)
}