feat(app): R2 switch — the application runs its domain rules in the Rust core

Consumers now fed by the core (crates/core through @faunosteo/core-wasm):
- the sheet: the bundled payload is parsed and indexed by the core
  (SheetHandle, SheetIndexData); SheetIndex reads precomputed tables only;
- the store: new report, add / remove / move observation, draft restore
  (v2 migration + rebase) through the core, actions answering { ok };
- the editor click chain (zone.click), laterality and vertebra pickers
  (zone.add_sides, vertebra.initial / sync / select), the findings picker
  (finding.toggle by clicked leaf position), zone removal;
- the import: engine byte scan (TypeScript until R4), then the core's
  layered reading and rebase in one call; the export: the core builds the
  sheet snapshot, the frozen TypeScript engine writes the PDF (R4).
Lazy core: Home and the new-report form read the sheet availability from
the bundle and load the module on import / submit only; the auth shell
never references it. Degraded states (core_unavailable, invalid_sheet)
show the validated notice with a retry and never redirect or touch the
draft; an unreadable draft or archive is set aside under
osteo:quarantine:* (only content kinds; a failed write keeps it in place
and the editor stays), a rebase that flags items keeps the raw pre-rebase
draft. Four strings, wording validated by the owner.
Deleted: services/zoneInteraction.ts and its suite (13 cases ported to
cargo), the TypeScript Finding builder and vertebra selection rules of the
pickers, store rules, persistence parsing, hydrateReport. ESLint forbids
@faunosteo/domain in apps/app/src; the report:compare CLI keeps the frozen
domain until R4 (scripts/compare/sheet.ts). App suite 313/313 on the real
core (24 new tests: quarantine, degraded editor, core failures, N-1
reader); step6 goldens and the frozen envelopes unchanged.
This commit is contained in:
bchanot committed 2026-10-14 00:41:34 +02:00
1 parent 794dfd9d0b
commit 74fcb37564
65 files changed
+2227 -1678

No files matched your search

@@ -7,9 +7,9 @@ import type {
FindingZone,
LateralSide,
LocalizedOptionalText,
} from '@faunosteo/domain'
} from '@faunosteo/core-wasm/types'
import Button from '@/components/ui/Button'
import { pickLabel } from '@/services/sheetIndex'
import { pickLabel } from '@/i18n/pickLocaleLabel'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import type { Locale } from '@/i18n/types'
@@ -25,7 +25,11 @@ export interface FindingsTreePickerProps {
zone: FindingZone
side?: LateralSide
selected: Finding[]
onChange: (next: Finding[]) => void
/**
* A leaf was ticked or unticked: its path and its position among the siblings shown.
* The parent has the core build or remove the finding (R2).
*/
onToggle: (leafPath: string[], leafPosition: number) => void
}
function isLeaf(node: TreeNode): boolean {
@@ -69,13 +73,14 @@ function descriptionOf(node: TreeNode, locale: Locale): string | undefined {
/**
* Drill-down picker over one finding zone of the sheet. A finding is keyed
* by `(findingZoneId, path, side)`; labels are snapshotted at selection.
* by `(findingZoneId, path, side)`; the core snapshots its labels when it
* builds it. The selection predicates below only decide what is shown.
*/
export default function FindingsTreePicker({
zone,
side,
selected,
onChange,
onToggle,
}: FindingsTreePickerProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
@@ -125,25 +130,6 @@ export default function FindingsTreePicker({
selected.filter((f) => matches(f) && pathStartsWith(f.path, nodePath))
.length
function toggleLeaf(leafPath: string[], leaf: TreeNode) {
if (isLeafSelected(leafPath)) {
onChange(
selected.filter((f) => !(matches(f) && samePath(f.path, leafPath))),
)
return
}
const next: Finding = {
findingZoneId: zone.id,
path: leafPath,
labelFrSnapshot: leaf.name.fr,
labelEnSnapshot: leaf.name.en,
}
if ('requires_vet_referral' in leaf && leaf.requires_vet_referral)
next.requiresVetReferral = true
if (side) next.side = side
onChange([...selected, next])
}
const focusedDescription = focusedNode && descriptionOf(focusedNode, locale)
return (
@@ -202,7 +188,7 @@ export default function FindingsTreePicker({
{t('findings.no_options')}
</li>
) : (
currentNodes.map((node) => {
currentNodes.map((node, position) => {
const nodePath = [...path, node.id]
const nodeLabel = pickLabel(node.name, locale)
const nodeDesc = descriptionOf(node, locale)
@@ -215,7 +201,7 @@ export default function FindingsTreePicker({
<input
type="checkbox"
checked={isLeafSelected(nodePath)}
onChange={() => toggleLeaf(nodePath, node)}
onChange={() => onToggle(nodePath, position)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={nodeLabel}
/>