fix(editor,pdf): accordion observation cards + seed 1 obs + native SVG rasterization
Three issues from manual QA: 1. UX restructure — observations are now an accordion list. Each card has a header that's always visible (title + chips + chevron + action buttons) and a body that expands inline showing zones / pathologies / severity / comment. Click the header (or the chevron) to toggle. ObservationEditor has been merged into ObservationCard so each card owns its own details. Only one observation is expanded at a time; the chevron on the active card collapses everything. EditorRoute uses activeObservationIndex === -1 to represent "all collapsed". 2. App used to start with 2 observations instead of 1. Root cause: EditorRoute had a "seed first observation" useEffect that fired twice under React 19 StrictMode in dev, both invocations seeing length=0 and queueing addObservation(). Fixed by moving the seed into the store's initReport (synchronous, one-shot) and removing the useEffect entirely. Store tests updated to assert the seed behaviour (90/90 pass). 3. PDF export still failed with "The input is not a PNG file!" — canvg was returning bytes that pdf-lib rejected at embedPng(). Switched rasterizeSvg to the browser-native pipeline: serialize the SVG into a Blob URL, load it with an Image element, drawImage onto a 2D canvas, then toBlob → PNG bytes (with a toDataURL fallback). Validates the PNG signature before returning. Tree-shaking dropped canvg from the bundle (979 kB → 874 kB JS). Tests updated for the new initReport behaviour and the new svgToPng pipeline (Image mock + dataURL fallback case). lint + typecheck + build all clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bdf5e6475b
commit
e8c29c1fdf
7 files changed
+449
-113
No files matched your search
@@ -1,39 +1,72 @@
|
||||
import type { Observation } from '@/domain/schema/observation'
|
||||
import type { Observation, ObservationZone, Vertebra } from '@/domain/schema/observation'
|
||||
import type { Pathology } from '@/domain/schema/pathology'
|
||||
import type { Bone } from '@/anatomy/types'
|
||||
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 PathologyPicker from './PathologyPicker'
|
||||
import FreeTextPathologyInput from './FreeTextPathologyInput'
|
||||
import SeveritySelector from './SeveritySelector'
|
||||
|
||||
export interface ObservationCardProps {
|
||||
observation: Observation
|
||||
index: number
|
||||
active: boolean
|
||||
onSelect: () => void
|
||||
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>
|
||||
speciesId: string
|
||||
pathologyPool: Pathology[]
|
||||
onChange: (next: Observation) => void
|
||||
onOpenVertebraPicker: (zoneIndex: number) => void
|
||||
onRemoveZone: (zoneIndex: number) => void
|
||||
}
|
||||
|
||||
function describeZone(z: ObservationZone, bones: Map<string, Bone>): string {
|
||||
const b = bones.get(z.boneId)
|
||||
const label = b?.fr ?? z.boneId
|
||||
if (z.vertebrae?.length) {
|
||||
const vs = z.vertebrae
|
||||
.map((v: Vertebra) => `${v.region}${v.index}`)
|
||||
.join(', ')
|
||||
return `${label} (${vs})`
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
export default function ObservationCard({
|
||||
observation,
|
||||
index,
|
||||
active,
|
||||
onSelect,
|
||||
expanded,
|
||||
onToggle,
|
||||
onDelete,
|
||||
onMoveUp,
|
||||
onMoveDown,
|
||||
canMoveUp,
|
||||
canMoveDown,
|
||||
bones,
|
||||
speciesId,
|
||||
pathologyPool,
|
||||
onChange,
|
||||
onOpenVertebraPicker,
|
||||
onRemoveZone,
|
||||
}: ObservationCardProps) {
|
||||
const zoneCount = observation.zones.length
|
||||
const patCount =
|
||||
observation.pathologyIds.length + observation.freeTextPathologies.length
|
||||
|
||||
function onCardKey(event: React.KeyboardEvent<HTMLDivElement>) {
|
||||
function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault()
|
||||
onSelect()
|
||||
onToggle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +77,13 @@ export default function ObservationCard({
|
||||
}
|
||||
}
|
||||
|
||||
const zoneBoneIds = observation.zones.map((z) => z.boneId)
|
||||
|
||||
return (
|
||||
<Card
|
||||
className={[
|
||||
'cursor-pointer p-4 transition',
|
||||
active
|
||||
'transition',
|
||||
expanded
|
||||
? 'ring-2 ring-[var(--color-accent)]'
|
||||
: 'hover:bg-[var(--color-surface-strong)]',
|
||||
].join(' ')}
|
||||
@@ -56,11 +91,11 @@ export default function ObservationCard({
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`Sélectionner l'observation ${index + 1}`}
|
||||
aria-pressed={active}
|
||||
onClick={onSelect}
|
||||
onKeyDown={onCardKey}
|
||||
className="flex items-start justify-between gap-3 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40 rounded-lg"
|
||||
aria-expanded={expanded}
|
||||
aria-label={`${expanded ? 'Réduire' : 'Développer'} l'observation ${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">
|
||||
@@ -83,14 +118,14 @@ export default function ObservationCard({
|
||||
{zoneCount} zone{zoneCount > 1 ? 's' : ''} · {patCount} pathologie
|
||||
{patCount > 1 ? 's' : ''}
|
||||
</div>
|
||||
{observation.comment && (
|
||||
{!expanded && observation.comment && (
|
||||
<p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]">
|
||||
{observation.comment}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className="flex flex-col gap-1"
|
||||
className="flex items-start gap-1"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
@@ -119,8 +154,117 @@ export default function ObservationCard({
|
||||
>
|
||||
🗑
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={stop(onToggle)}
|
||||
aria-label={expanded ? 'Réduire' : 'Développer'}
|
||||
>
|
||||
{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>Zones sélectionnées</Label>
|
||||
{observation.zones.length === 0 ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Cliquez sur les zones du schéma pour les ajouter à cette
|
||||
observation.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="flex flex-wrap gap-2">
|
||||
{observation.zones.map((z, i) => {
|
||||
const b = bones.get(z.boneId)
|
||||
const isSpine = b?.category === 'spine-zone'
|
||||
return (
|
||||
<li key={`${z.boneId}-${i}`}>
|
||||
<Badge tone="accent" className="gap-2">
|
||||
{describeZone(z, bones)}
|
||||
{isSpine && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onOpenVertebraPicker(i)}
|
||||
className="underline text-xs text-[var(--color-accent-strong)]"
|
||||
>
|
||||
Préciser…
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Retirer ${b?.fr ?? z.boneId}`}
|
||||
onClick={() => onRemoveZone(i)}
|
||||
className="ml-1 text-[var(--color-accent-strong)]"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</Badge>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label>Pathologies (référence)</Label>
|
||||
<PathologyPicker
|
||||
pool={pathologyPool}
|
||||
speciesId={speciesId}
|
||||
boneIds={zoneBoneIds}
|
||||
selected={observation.pathologyIds}
|
||||
onChange={(ids) =>
|
||||
onChange({ ...observation, pathologyIds: ids })
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label>Pathologies (texte libre)</Label>
|
||||
<FreeTextPathologyInput
|
||||
items={observation.freeTextPathologies}
|
||||
onChange={(items) =>
|
||||
onChange({ ...observation, freeTextPathologies: items })
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label>Sévérité</Label>
|
||||
<SeveritySelector
|
||||
value={observation.severity}
|
||||
onChange={(s) => onChange({ ...observation, severity: s })}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label htmlFor={`obs-comment-${observation.id}`}>
|
||||
Commentaire
|
||||
</Label>
|
||||
<Textarea
|
||||
id={`obs-comment-${observation.id}`}
|
||||
value={observation.comment}
|
||||
onChange={(e) =>
|
||||
onChange({ ...observation, comment: e.target.value })
|
||||
}
|
||||
placeholder="Notes cliniques détaillées…"
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -1,35 +1,55 @@
|
||||
import type { Observation } from '@/domain/schema/observation'
|
||||
import type { Pathology } from '@/domain/schema/pathology'
|
||||
import type { Bone } from '@/anatomy/types'
|
||||
import ObservationCard from './ObservationCard'
|
||||
import Button from '@/components/ui/Button'
|
||||
|
||||
export interface ObservationListProps {
|
||||
observations: Observation[]
|
||||
activeIndex: number
|
||||
onSelect: (i: number) => void
|
||||
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>
|
||||
speciesId: string
|
||||
pathologyPool: Pathology[]
|
||||
onChange: (i: number, next: Observation) => void
|
||||
onOpenVertebraPicker: (i: number, zoneIndex: number) => void
|
||||
onRemoveZone: (i: number, zoneIndex: number) => void
|
||||
}
|
||||
|
||||
export default function ObservationList({
|
||||
observations,
|
||||
activeIndex,
|
||||
onSelect,
|
||||
onToggle,
|
||||
onAdd,
|
||||
onDelete,
|
||||
onMoveUp,
|
||||
onMoveDown,
|
||||
bones,
|
||||
speciesId,
|
||||
pathologyPool,
|
||||
onChange,
|
||||
onOpenVertebraPicker,
|
||||
onRemoveZone,
|
||||
}: ObservationListProps) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="font-serif text-xl text-[var(--color-ink)]">Observations</h2>
|
||||
<Button size="sm" onClick={onAdd}>+ Nouvelle observation</Button>
|
||||
<h2 className="font-serif text-xl text-[var(--color-ink)]">
|
||||
Observations
|
||||
</h2>
|
||||
<Button size="sm" onClick={onAdd}>
|
||||
+ Nouvelle observation
|
||||
</Button>
|
||||
</div>
|
||||
{observations.length === 0 ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Aucune observation. Cliquez sur "+ Nouvelle observation" puis sur les zones du schéma.
|
||||
Aucune observation. Cliquez sur "+ Nouvelle observation"
|
||||
puis sur les zones du schéma.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="space-y-2">
|
||||
@@ -38,13 +58,21 @@ export default function ObservationList({
|
||||
<ObservationCard
|
||||
observation={obs}
|
||||
index={i}
|
||||
active={i === activeIndex}
|
||||
onSelect={() => onSelect(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}
|
||||
speciesId={speciesId}
|
||||
pathologyPool={pathologyPool}
|
||||
onChange={(next) => onChange(i, next)}
|
||||
onOpenVertebraPicker={(zoneIndex) =>
|
||||
onOpenVertebraPicker(i, zoneIndex)
|
||||
}
|
||||
onRemoveZone={(zoneIndex) => onRemoveZone(i, zoneIndex)}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user