feat(observation): PathologyPicker filtered by species + zones

This commit is contained in:
Bastien Chanot committed 2026-05-18 21:27:11 +02:00
1 parent b3e1a87690
commit 4c67c900b9
2 files changed
+121 -2

No files matched your search

+64 -2
View File
@@ -1,3 +1,65 @@
export default function PathologyPicker() {
return <div>PathologyPicker placeholder</div>
import { useMemo } from 'react'
import type { Pathology } from '@/domain/schema/pathology'
export interface PathologyPickerProps {
pool: Pathology[]
speciesId: string
boneIds: string[]
selected: string[]
onChange: (next: string[]) => void
}
function matches(p: Pathology, speciesId: string, boneIds: string[]): boolean {
const speciesOk = p.speciesIds.length === 0 || p.speciesIds.includes(speciesId)
if (!speciesOk) return false
if (boneIds.length === 0) return true
if (p.boneIds.length === 0) return true
return p.boneIds.some((b) => boneIds.includes(b))
}
export default function PathologyPicker({
pool,
speciesId,
boneIds,
selected,
onChange,
}: PathologyPickerProps) {
const filtered = useMemo(
() => pool.filter((p) => matches(p, speciesId, boneIds)),
[pool, speciesId, boneIds],
)
function toggle(id: string) {
onChange(selected.includes(id) ? selected.filter((x) => x !== id) : [...selected, id])
}
if (filtered.length === 0) {
return (
<p className="text-sm text-[var(--color-ink-muted)]">
Aucune pathologie de référence pour ces zones. Ajoutez-en une en texte libre ci-dessous.
</p>
)
}
return (
<ul className="space-y-2 max-h-64 overflow-auto pr-1">
{filtered.map((p) => (
<li key={p.id}>
<label className="flex items-start gap-2 cursor-pointer">
<input
type="checkbox"
checked={selected.includes(p.id)}
onChange={() => toggle(p.id)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={p.labelFr}
/>
<div>
<div className="text-sm font-medium text-[var(--color-ink)]">{p.labelFr}</div>
<div className="text-xs text-[var(--color-ink-muted)]">{p.description}</div>
</div>
</label>
</li>
))}
</ul>
)
}