feat(editor+pdf): per-zone PDF sections + collapsible findings pickers

PDF
---
The flat single-line "CONSTATS" section bundled every selected leaf
from every zone plus the free-text additions on one line, which got
hard to read as soon as an observation touched more than one zone.

The export now groups catalog findings by their JSON `zoneId` and
emits one section per zone, labelled with the zone's French name
("CONSTATS — SPHÉNOÏDE", "CONSTATS — ARTICULATION TEMPORO-MANDIBULAIRE
(ATM)", …). Free-text additions move to a dedicated "CONSTATS LIBRES"
section directly below.

The catalog tree is loaded once at the top of exportReportToPdf and
threaded through to addObservationPage, so the per-zone label lookup
costs nothing extra per observation.

Editor
------
Inside an expanded observation, each available zone's
FindingsTreePicker is now wrapped in an accordion header that mirrors
the ObservationCard expand/collapse semantics:

- Click a zone header → that picker opens and any other picker on the
  card closes.
- Click an open zone header → it collapses.
- Each header shows a selected-count badge and a ▼/▲ caret.

Default state is "all closed" so the card stays compact when the user
expands a new observation. Motion-based height/opacity transition
matches the observation card body animation for visual consistency.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude committed 2026-05-20 05:07:03 +02:00
1 parent 1e12f2252f
commit de40c5f91e
3 files changed
+145 -33

No files matched your search

+32 -1
View File
@@ -1,5 +1,6 @@
import { PDFDocument } from 'pdf-lib'
import type { Report } from '@/domain/schema/report'
import type { SpeciesFindings } from '@/domain/schema/findings'
import { embedFonts } from './fonts'
import { addObservationPage } from './render/observationPage'
import { addConclusionPage } from './render/conclusionPage'
@@ -46,6 +47,27 @@ export async function buildZoneLabels(report: Report): Promise<Map<string, strin
return labels
}
/**
* Loads the parsed findings catalog for a species so the PDF renderer
* can resolve a Finding's `zoneId` (JSON catalog key) back to its
* human-readable zone name. Returns null if the species lacks a
* catalog or the lazy import fails — the PDF still renders, but
* per-zone groups fall back to the raw zoneId.
*/
async function loadSpeciesFindings(
speciesId: string,
): Promise<SpeciesFindings | null> {
const species = getSpecies(speciesId)
if (!species) return null
try {
const m = await species.findings()
return m.default
} catch (err) {
console.warn(`loadSpeciesFindings: failed for ${speciesId}`, err)
return null
}
}
export async function exportReportToPdf(report: Report): Promise<Uint8Array> {
const pdfDoc = await PDFDocument.create()
pdfDoc.setTitle(`Bilan ostéo — ${report.animal.name}`)
@@ -56,9 +78,18 @@ export async function exportReportToPdf(report: Report): Promise<Uint8Array> {
const fonts = await embedFonts(pdfDoc)
const zoneLabels = await buildZoneLabels(report)
const findingsTree = await loadSpeciesFindings(report.animal.speciesId)
for (let i = 0; i < report.observations.length; i += 1) {
await addObservationPage(pdfDoc, report, report.observations[i], i, fonts, zoneLabels)
await addObservationPage(
pdfDoc,
report,
report.observations[i],
i,
fonts,
zoneLabels,
findingsTree,
)
}
await addConclusionPage(pdfDoc, report, fonts)