chore(workspace): move the app to apps/app under a pnpm workspace (step 2)

144 files moved with git mv (pure renames). Root package.json delegates
dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and
pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager,
root devDependency, engine-strict). Dockerfile builds @faunosteo/app on
node:24-alpine and copies apps/app/dist; nginx and runtime config
unchanged. CI workflow for Gitea Actions. packages/ reserved (README only).
Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan.
271/271 tests, typecheck, lint, build green from the root.
This commit is contained in:
bchanot committed 2026-10-08 21:51:13 +02:00
1 parent c8d48ab4cc
commit 8673475293
164 files changed
+348 -128

No files matched your search

@@ -0,0 +1,292 @@
import { useMemo, useState } from 'react'
import { motion } from 'motion/react'
import type {
FindingNode,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Finding, LateralSide } from '@/domain/schema/observation'
import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
const levelVariants = {
enter: (dir: 1 | -1) => ({ opacity: 0, x: dir * 32 }),
center: { opacity: 1, x: 0 },
}
export interface FindingsTreePickerProps {
zoneId: string
tree: ZoneFindings
side?: LateralSide
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 pathStartsWith(full: string[], prefix: string[]): boolean {
if (full.length < prefix.length) return false
for (let i = 0; i < prefix.length; i += 1) {
if (full[i] !== prefix[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,
side,
selected,
onChange,
}: FindingsTreePickerProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const nameOf = (node: { name_fr: string; name_en: string }) =>
locale === 'en' ? node.name_en : node.name_fr
const descOf = (node: { description_fr?: string; description_en?: string }) =>
locale === 'en' ? node.description_en : node.description_fr
const [path, setPath] = useState<string[]>([])
const [direction, setDirection] = useState<1 | -1>(1)
function goInto(nodePath: string[]) {
setDirection(1)
setPath(nodePath)
}
function goBack() {
setDirection(-1)
setPath(path.slice(0, -1))
}
function goToDepth(depth: number) {
setDirection(depth >= path.length ? 1 : -1)
setPath(path.slice(0, depth))
}
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 pick = (z: { name_fr: string; name_en: string }) =>
locale === 'en' ? z.name_en : z.name_fr
const crumbs: { label: string; depth: number }[] = [
{ label: pick(tree), depth: 0 },
]
let nodes: FindingNode[] = tree.categories
path.forEach((seg, i) => {
const n = nodes.find((x) => x.id === seg)
if (n) {
crumbs.push({ label: pick(n), depth: i + 1 })
nodes = n.children ?? []
}
})
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) => matchesSide(f) && samePath(f.path, leafPath),
)
}
function countSelectedUnder(nodePath: string[]): number {
let n = 0
for (const f of selected) {
if (!matchesSide(f)) continue
if (!pathStartsWith(f.path, nodePath)) continue
n += 1
}
return n
}
function toggleLeaf(leafPath: string[], leaf: FindingNode) {
if (isLeafSelected(leafPath)) {
onChange(
selected.filter(
(f) => !(matchesSide(f) && 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
if (side) next.side = side
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={() => goToDepth(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 && descOf(focusedNode) && (
<p className="text-xs italic text-[var(--color-ink-muted)]">
{descOf(focusedNode)}
</p>
)}
{path.length > 0 && (
<Button
size="sm"
variant="ghost"
onClick={goBack}
aria-label={t('findings.back_to_parent')}
>
{t('findings.back')}
</Button>
)}
<motion.ul
key={path.join('/') || '__root__'}
custom={direction}
variants={levelVariants}
initial="enter"
animate="center"
transition={{ duration: 0.22, ease: 'easeOut' }}
style={{ willChange: 'transform, opacity' }}
className="space-y-1.5 max-h-64 overflow-auto pr-1"
>
{currentNodes.length === 0 ? (
<li className="text-sm text-[var(--color-ink-muted)]">
{t('findings.no_options')}
</li>
) : (
currentNodes.map((node) => {
const nodePath = [...path, node.id]
if (isLeaf(node)) {
const checked = isLeafSelected(nodePath)
const nodeLabel = nameOf(node)
const nodeDesc = descOf(node)
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={nodeLabel}
/>
<div className="flex-1">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{nodeLabel}
</span>
{node.requires_vet_referral && (
<span
title={t('findings.vet_referral')}
aria-label={t('findings.vet_referral')}
className="text-[var(--color-danger)]"
>
⚠
</span>
)}
</div>
{nodeDesc && (
<div className="text-xs text-[var(--color-ink-muted)]">
{nodeDesc}
</div>
)}
</div>
</label>
</li>
)
}
const selectedCount = countSelectedUnder(nodePath)
const nodeLabel = nameOf(node)
const selectedAria = `${selectedCount} ${
selectedCount > 1
? t('findings.selected_plural')
: t('findings.selected_singular')
}`
return (
<li key={node.id}>
<button
type="button"
onClick={() => goInto(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={`${t('findings.open')} ${nodeLabel}`}
>
<span className="flex items-center gap-2">
<span>{nodeLabel}</span>
{selectedCount > 0 && (
<span
aria-label={selectedAria}
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
>
{selectedCount}
</span>
)}
</span>
<span aria-hidden="true" className="text-[var(--color-ink-muted)]">
›
</span>
</button>
</li>
)
})
)}
</motion.ul>
</div>
)
}
@@ -0,0 +1,70 @@
import { useState } from 'react'
import Input from '@/components/ui/Input'
import Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge'
import { useT } from '@/i18n/useT'
export interface FreeTextFindingInputProps {
items: string[]
onChange: (next: string[]) => void
}
export default function FreeTextFindingInput({
items,
onChange,
}: FreeTextFindingInputProps) {
const [v, setV] = useState('')
const t = useT()
function add() {
const trimmed = v.trim()
if (!trimmed) return
onChange([...items, trimmed])
setV('')
}
function remove(i: number) {
onChange(items.filter((_, k) => k !== i))
}
return (
<div className="space-y-2">
<div className="flex gap-2">
<Input
value={v}
onChange={(e) => setV(e.target.value)}
placeholder={t('observation.free_placeholder')}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault()
add()
}
}}
aria-label={t('observation.free_aria')}
/>
<Button onClick={add} variant="secondary">
{t('common.add')}
</Button>
</div>
{items.length > 0 && (
<ul className="flex flex-wrap gap-2">
{items.map((it, i) => (
<li key={`${it}-${i}`}>
<Badge tone="accent" className="gap-1">
{it}
<button
type="button"
aria-label={`${t('observation.remove_zone')} ${it}`}
onClick={() => remove(i)}
className="ml-1 text-[var(--color-accent-strong)] hover:text-[var(--color-danger)]"
>
✕
</button>
</Badge>
</li>
))}
</ul>
)}
</div>
)
}
@@ -0,0 +1,62 @@
import Dialog from '@/components/ui/Dialog'
import Button from '@/components/ui/Button'
import type { LateralSide } from '@/domain/schema/observation'
import { useT } from '@/i18n/useT'
export interface LateralityPickerProps {
open: boolean
onClose: () => void
onSelect: (sides: LateralSide[]) => void
title: string
existingSides: LateralSide[]
}
export default function LateralityPicker({
open,
onClose,
onSelect,
title,
existingSides,
}: LateralityPickerProps) {
const t = useT()
const hasLeft = existingSides.includes('left')
const hasRight = existingSides.includes('right')
return (
<Dialog open={open} onClose={onClose} title={title} size="sm">
<div className="space-y-4">
<p className="text-sm text-[var(--color-ink-muted)]">
{t('lateral.which_side')}
</p>
<div className="flex gap-3 justify-center">
<Button
variant={hasLeft ? 'ghost' : 'primary'}
disabled={hasLeft}
onClick={() => onSelect(['left'])}
>
{t('lateral.left')}
</Button>
<Button
variant={hasRight ? 'ghost' : 'primary'}
disabled={hasRight}
onClick={() => onSelect(['right'])}
>
{t('lateral.right')}
</Button>
<Button
variant={hasLeft && hasRight ? 'ghost' : 'primary'}
disabled={hasLeft && hasRight}
onClick={() => {
const sides: LateralSide[] = []
if (!hasLeft) sides.push('left')
if (!hasRight) sides.push('right')
onSelect(sides)
}}
>
{t('lateral.both')}
</Button>
</div>
</div>
</Dialog>
)
}
@@ -0,0 +1,418 @@
import { useMemo, useState } from 'react'
import type {
Observation,
ObservationZone,
Vertebra,
LateralSide,
} from '@/domain/schema/observation'
import type {
SpeciesFindings,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import { matchZoneFindings } from '@/lib/zoneMatch'
import { AnimatePresence, motion } from 'motion/react'
import Card from '@/components/ui/Card'
import Badge from '@/components/ui/Badge'
import Button from '@/components/ui/Button'
import Label from '@/components/ui/Label'
import Textarea from '@/components/ui/Textarea'
import FindingsTreePicker from './FindingsTreePicker'
import FreeTextFindingInput from './FreeTextFindingInput'
import SeveritySelector from './SeveritySelector'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import { boneLabel } from '@/anatomy/labels'
import type { Locale } from '@/i18n/types'
export interface ObservationCardProps {
observation: Observation
index: number
expanded: boolean
onToggle: () => void
onDelete: () => void
onMoveUp: () => void
onMoveDown: () => void
canMoveUp: boolean
canMoveDown: boolean
// Editor body props (used only when expanded)
bones: Map<string, Bone>
findings: SpeciesFindings | null
onChange: (next: Observation) => void
onOpenVertebraPicker: (zoneIndex: number) => void
onRemoveZone: (zoneIndex: number) => void
}
function describeZone(
z: ObservationZone,
bones: Map<string, Bone>,
locale: Locale,
t: (key: string) => string,
): string {
const label = boneLabel(bones.get(z.boneId), locale, z.boneId)
if (z.vertebrae?.length) {
const vs = z.vertebrae
.map((v: Vertebra) => `${v.region}${v.index}`)
.join(', ')
return `${label} (${vs})`
}
if (z.side) {
const sideLabel = t(
z.side === 'left' ? 'lateral.left_short' : 'lateral.right_short',
)
return `${label} (${sideLabel})`
}
return label
}
export default function ObservationCard({
observation,
index,
expanded,
onToggle,
onDelete,
onMoveUp,
onMoveDown,
canMoveUp,
canMoveDown,
bones,
findings,
onChange,
onOpenVertebraPicker,
onRemoveZone,
}: ObservationCardProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const nameOf = (z: { name_fr: string; name_en: string }) =>
locale === 'en' ? z.name_en : z.name_fr
// Per-zone picker accordion — only one tree picker open at a time,
// matching the observation-card accordion semantics. Closed by default
// so the card stays compact when first expanded.
const [expandedZoneId, setExpandedZoneId] = useState<string | null>(null)
const zoneCount = observation.zones.length
const findingCount =
observation.findings.length + observation.freeTextFindings.length
const zoneCountLabel =
zoneCount > 1
? t('observation.zone_label_plural')
: t('observation.zone_label_singular')
const findingCountLabel =
findingCount > 1
? t('observation.finding_label_plural')
: t('observation.finding_label_singular')
function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
onToggle()
}
}
function stop(fn: () => void) {
return (event: React.MouseEvent) => {
event.stopPropagation()
fn()
}
}
const zonesArray = useMemo(
() => (findings ? Object.values(findings.zones) : []),
[findings],
)
const zonesWithTree = useMemo(() => {
if (zonesArray.length === 0)
return [] as { tree: ZoneFindings; side?: LateralSide }[]
const seen = new Set<string>()
const out: { tree: ZoneFindings; side?: LateralSide }[] = []
for (const z of observation.zones) {
const bone = bones.get(z.boneId)
if (!bone) continue
const tree = matchZoneFindings(
{ fr: bone.fr, en: bone.en },
zonesArray,
)
if (!tree) continue
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])
return (
<Card
className={[
'transition',
expanded
? 'ring-2 ring-[var(--color-accent)]'
: 'hover:bg-[var(--color-surface-strong)]',
].join(' ')}
>
<div
role="button"
tabIndex={0}
aria-expanded={expanded}
aria-label={`${expanded ? t('observation.collapse_aria') : t('observation.expand_aria')} ${index + 1}`}
onClick={onToggle}
onKeyDown={onHeaderKey}
className="flex items-start justify-between gap-3 p-4 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40 rounded-2xl"
>
<div className="flex-1 min-h-[60px] text-left">
<div className="flex items-center gap-2 mb-2">
<Badge tone="neutral">{t('observation.badge_n')}{index + 1}</Badge>
{observation.severity && (
<Badge
tone={
observation.severity === 'sévère'
? 'danger'
: observation.severity === 'modérée'
? 'warn'
: 'neutral'
}
>
{t(`severity.${observation.severity}`)}
</Badge>
)}
</div>
<div className="text-sm text-[var(--color-ink-muted)]">
{zoneCount} {zoneCountLabel} · {findingCount} {findingCountLabel}
</div>
{!expanded && observation.comment && (
<p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]">
{observation.comment}
</p>
)}
</div>
<div
className="flex items-start gap-1"
onClick={(event) => event.stopPropagation()}
>
<Button
size="sm"
variant="ghost"
disabled={!canMoveUp}
onClick={stop(onMoveUp)}
aria-label={t('common.move_up')}
>
↑
</Button>
<Button
size="sm"
variant="ghost"
disabled={!canMoveDown}
onClick={stop(onMoveDown)}
aria-label={t('common.move_down')}
>
↓
</Button>
<Button
size="sm"
variant="ghost"
onClick={stop(onDelete)}
aria-label={t('common.delete')}
>
🗑
</Button>
<Button
size="sm"
variant="ghost"
onClick={stop(onToggle)}
aria-label={expanded ? t('common.collapse') : t('common.expand')}
>
{expanded ? '▲' : '▼'}
</Button>
</div>
</div>
<AnimatePresence initial={false}>
{expanded && (
<motion.div
key="body"
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.18, ease: 'easeOut' }}
className="overflow-hidden"
>
<div className="px-4 pb-4 pt-2 border-t border-[var(--color-border)] space-y-6">
<section>
<Label>{t('observation.zones_label')}</Label>
{observation.zones.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('observation.zones_empty')}
</p>
) : (
<ul className="flex flex-wrap gap-2">
{observation.zones.map((z, i) => {
const b = bones.get(z.boneId)
const supportsVertebrae =
b?.special === 'vertebral-precision'
return (
<li key={`${z.boneId}-${i}`}>
<Badge tone="accent" className="gap-2">
{describeZone(z, bones, locale, t)}
{supportsVertebrae && (
<button
type="button"
onClick={() => onOpenVertebraPicker(i)}
className="underline text-xs text-[var(--color-accent-strong)]"
title={t('observation.vertebrae_button_title')}
>
{t('observation.vertebrae_button')}
</button>
)}
<button
type="button"
aria-label={`${t('observation.remove_zone')} ${boneLabel(b, locale, z.boneId)}`}
onClick={() => onRemoveZone(i)}
className="ml-1 text-[var(--color-accent-strong)]"
>
✕
</button>
</Badge>
</li>
)
})}
</ul>
)}
</section>
<section>
<Label>{t('observation.findings_catalog_label')}</Label>
{zonesWithTree.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{observation.zones.length === 0
? t('observation.findings_pick_zone_first')
: t('observation.findings_no_catalog')}
</p>
) : (
<ul className="space-y-2">
{zonesWithTree.map(({ tree, side }) => {
const pickerKey = side
? `${tree.id}:${side}`
: tree.id
const expanded = expandedZoneId === pickerKey
const selectedCount = observation.findings.filter(
(f) =>
f.zoneId === tree.id && f.side === side,
).length
const selectedAria = `${selectedCount} ${
selectedCount > 1
? t('findings.selected_plural')
: t('findings.selected_singular')
}`
return (
<li
key={pickerKey}
className={[
'rounded-xl border bg-[var(--color-surface)] transition',
expanded
? 'border-[var(--color-accent)] ring-1 ring-[var(--color-accent)]'
: 'border-[var(--color-border)]',
].join(' ')}
>
<button
type="button"
onClick={() =>
setExpandedZoneId(expanded ? null : pickerKey)
}
aria-expanded={expanded}
aria-controls={`findings-zone-${pickerKey}`}
className="w-full flex items-center justify-between gap-2 px-3 py-2 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40"
>
<span className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{nameOf(tree)}
{side && ` (${t(side === 'left' ? 'lateral.left' : 'lateral.right')})`}
</span>
{selectedCount > 0 && (
<span
aria-label={selectedAria}
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
>
{selectedCount}
</span>
)}
</span>
<span
aria-hidden="true"
className="text-[var(--color-ink-muted)]"
>
{expanded ? '▲' : '▼'}
</span>
</button>
<AnimatePresence initial={false}>
{expanded && (
<motion.div
key="picker-body"
id={`findings-zone-${pickerKey}`}
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.18, ease: 'easeOut' }}
className="overflow-hidden"
>
<div className="px-3 pb-3 pt-1 border-t border-[var(--color-border)]">
<FindingsTreePicker
zoneId={tree.id}
tree={tree}
side={side}
selected={observation.findings}
onChange={(next) =>
onChange({ ...observation, findings: next })
}
/>
</div>
</motion.div>
)}
</AnimatePresence>
</li>
)
})}
</ul>
)}
</section>
<section>
<Label>{t('observation.findings_free_label')}</Label>
<FreeTextFindingInput
items={observation.freeTextFindings}
onChange={(items) =>
onChange({ ...observation, freeTextFindings: items })
}
/>
</section>
<section>
<Label>{t('observation.severity_label')}</Label>
<SeveritySelector
value={observation.severity}
onChange={(s) => onChange({ ...observation, severity: s })}
/>
</section>
<section>
<Label htmlFor={`obs-comment-${observation.id}`}>
{t('observation.comment_label')}
</Label>
<Textarea
id={`obs-comment-${observation.id}`}
value={observation.comment}
onChange={(e) =>
onChange({ ...observation, comment: e.target.value })
}
placeholder={t('observation.comment_placeholder')}
/>
</section>
</div>
</motion.div>
)}
</AnimatePresence>
</Card>
)
}
@@ -0,0 +1,81 @@
import type { Observation } from '@/domain/schema/observation'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import ObservationCard from './ObservationCard'
import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT'
export interface ObservationListProps {
observations: Observation[]
activeIndex: number
onToggle: (i: number) => void
onAdd: () => void
onDelete: (i: number) => void
onMoveUp: (i: number) => void
onMoveDown: (i: number) => void
// Editor body props forwarded to each card
bones: Map<string, Bone>
findings: SpeciesFindings | null
onChange: (i: number, next: Observation) => void
onOpenVertebraPicker: (i: number, zoneIndex: number) => void
onRemoveZone: (i: number, zoneIndex: number) => void
}
export default function ObservationList({
observations,
activeIndex,
onToggle,
onAdd,
onDelete,
onMoveUp,
onMoveDown,
bones,
findings,
onChange,
onOpenVertebraPicker,
onRemoveZone,
}: ObservationListProps) {
const t = useT()
return (
<div className="space-y-3">
<div className="flex items-center justify-between">
<h2 className="font-serif text-lg sm:text-xl text-[var(--color-ink)]">
{t('observation.section_title')}
</h2>
<Button size="sm" onClick={onAdd}>
{t('observation.add')}
</Button>
</div>
{observations.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('observation.empty')}
</p>
) : (
<ul className="space-y-2">
{observations.map((obs, i) => (
<li key={obs.id}>
<ObservationCard
observation={obs}
index={i}
expanded={i === activeIndex}
onToggle={() => onToggle(i)}
onDelete={() => onDelete(i)}
onMoveUp={() => onMoveUp(i)}
onMoveDown={() => onMoveDown(i)}
canMoveUp={i > 0}
canMoveDown={i < observations.length - 1}
bones={bones}
findings={findings}
onChange={(next) => onChange(i, next)}
onOpenVertebraPicker={(zoneIndex) =>
onOpenVertebraPicker(i, zoneIndex)
}
onRemoveZone={(zoneIndex) => onRemoveZone(i, zoneIndex)}
/>
</li>
))}
</ul>
)}
</div>
)
}
@@ -0,0 +1,38 @@
import type { Severity } from '@/domain/schema/observation'
import { useT } from '@/i18n/useT'
export interface SeveritySelectorProps {
value: Severity | undefined
onChange: (s: Severity | undefined) => void
}
const SEVERITIES: Severity[] = ['légère', 'modérée', 'sévère']
const COLORS: Record<Severity, string> = {
'légère': 'border-[var(--severity-mild)] text-[var(--severity-mild)]',
'modérée': 'border-[var(--severity-moderate)] text-[var(--severity-moderate)]',
'sévère': 'border-[var(--severity-severe)] text-[var(--severity-severe)]',
}
export default function SeveritySelector({ value, onChange }: SeveritySelectorProps) {
const t = useT()
return (
<div role="radiogroup" aria-label={t('severity.aria')} className="flex gap-2">
{SEVERITIES.map((s) => (
<button
key={s}
role="radio"
aria-checked={value === s}
onClick={() => onChange(value === s ? undefined : s)}
className={[
'rounded-full border px-3 py-1.5 text-sm font-medium capitalize',
value === s
? `bg-white ${COLORS[s]}`
: 'border-[var(--color-border)] text-[var(--color-ink-muted)]',
].join(' ')}
>
{t(`severity.${s}`)}
</button>
))}
</div>
)
}
@@ -0,0 +1,115 @@
import { useState } from 'react'
import Dialog from '@/components/ui/Dialog'
import Button from '@/components/ui/Button'
import Chip from '@/components/ui/Chip'
import type { Vertebra, VertebralRegion } from '@/domain/schema/observation'
import type { VertebralFormula } from '@/domain/species/types'
import { useT } from '@/i18n/useT'
const REGIONS: VertebralRegion[] = ['C', 'T', 'L', 'S', 'Cd']
const REGION_KEY: Record<VertebralRegion, string> = {
C: 'vertebra.region.C',
T: 'vertebra.region.T',
L: 'vertebra.region.L',
S: 'vertebra.region.S',
Cd: 'vertebra.region.Cd',
}
export interface VertebraPickerProps {
open: boolean
onClose: () => void
onConfirm: (vertebrae: Vertebra[]) => void
initial: Vertebra[]
formula: VertebralFormula
title: string
/** Tab to open on. Takes priority so a click always lands on its own zone. */
initialRegion?: VertebralRegion
}
export default function VertebraPicker({
open,
onClose,
onConfirm,
initial,
formula,
title,
initialRegion,
}: VertebraPickerProps) {
const t = useT()
const [selected, setSelected] = useState<Vertebra[]>(initial)
const [activeRegion, setActiveRegion] = useState<VertebralRegion>(
() => initialRegion ?? initial[0]?.region ?? 'C',
)
const has = (r: VertebralRegion, i: number) =>
selected.some((v) => v.region === r && v.index === i)
const toggle = (r: VertebralRegion, i: number) => {
setSelected((cur) =>
has(r, i)
? cur.filter((v) => !(v.region === r && v.index === i))
: [...cur, { region: r, index: i }],
)
}
const all = (r: VertebralRegion, count: number) => {
setSelected((cur) => {
const rest = cur.filter((v) => v.region !== r)
return [...rest, ...Array.from({ length: count }, (_, k) => ({ region: r, index: k + 1 }))]
})
}
const none = (r: VertebralRegion) =>
setSelected((cur) => cur.filter((v) => v.region !== r))
const count = formula[activeRegion]
return (
<Dialog open={open} onClose={onClose} title={title} size="lg">
<div role="tablist" className="flex flex-wrap gap-2 mb-4">
{REGIONS.map((r) => (
<button
key={r}
role="tab"
aria-selected={activeRegion === r}
onClick={() => setActiveRegion(r)}
className={[
'rounded-full px-4 py-2.5 sm:py-1.5 text-sm font-medium border min-h-[2.75rem]',
activeRegion === r
? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'
: 'bg-white text-[var(--color-ink)] border-[var(--color-border)]',
].join(' ')}
>
{t(REGION_KEY[r])}
</button>
))}
</div>
<div className="flex flex-wrap gap-2 mb-4 max-h-64 overflow-auto">
{Array.from({ length: count }, (_, k) => k + 1).map((i) => (
<Chip
key={i}
active={has(activeRegion, i)}
onClick={() => toggle(activeRegion, i)}
>
{activeRegion}{i}
</Chip>
))}
</div>
<div className="flex flex-wrap items-center gap-2 mb-6">
<Button variant="ghost" size="sm" onClick={() => all(activeRegion, count)}>
{t('vertebra.check_all')}
</Button>
<Button variant="ghost" size="sm" onClick={() => none(activeRegion)}>
{t('vertebra.uncheck_all')}
</Button>
</div>
<div className="flex justify-end gap-2">
<Button variant="ghost" onClick={onClose}>{t('common.cancel')}</Button>
<Button onClick={() => onConfirm(selected)}>{t('common.confirm')}</Button>
</div>
</Dialog>
)
}