fix(app): editor route split into dialogs and pickers components, canvas without lint suppression, findings picker coverage restored; golden test pins every generated draft file; stale doc lines

This commit is contained in:
bchanot committed 2026-10-10 11:55:57 +02:00
1 parent 0476276a8f
commit 09d8b01a54
11 files changed
+374 -161

No files matched your search

@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef } from 'react'
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'
import { buildViewSvg, type ViewStates } from '@/anatomy/drawing'
import type { SheetIndex } from '@/services/sheetIndex'
import { useLocaleStore } from '@/state/localeStore'
@@ -35,13 +35,16 @@ export default function AnatomyCanvas({
const svgRef = useRef<HTMLDivElement | null>(null)
const tooltipRef = useRef<HTMLDivElement | null>(null)
const locale = useLocaleStore((s) => s.locale)
// Latest states for the build effect, which must only re-run on a view change.
const statesRef = useRef(states)
useLayoutEffect(() => {
statesRef.current = states
}, [states])
useEffect(() => {
const host = svgRef.current
if (!host) return
host.replaceChildren(buildViewSvg(index, viewId, states))
// States are applied by the effect below; the build only needs the view.
// eslint-disable-next-line react-hooks/exhaustive-deps
host.replaceChildren(buildViewSvg(index, viewId, statesRef.current))
}, [index, viewId])
useEffect(() => {
@@ -0,0 +1,95 @@
import type { LateralSide, Observation } from '@faunosteo/domain'
import VertebraPicker from '@/components/observation/VertebraPicker'
import LateralityPicker from '@/components/observation/LateralityPicker'
import { useReportStore } from '@/state/reportStore'
import { useLocaleStore } from '@/state/localeStore'
import { isObservable, pickLabel, type SheetIndex } from '@/services/sheetIndex'
import {
addSides,
collectVertebrae,
sidesPresent,
syncVertebrae,
type ZoneRef,
} from '@/services/zoneInteraction'
import { useT } from '@/i18n/useT'
export interface ObservationPickersProps {
sheet: SheetIndex
activeIndex: number
activeObs: Observation | undefined
vertebraTarget: number | null
lateralTarget: ZoneRef | null
onCloseVertebra: () => void
onCloseLateral: () => void
}
/** Vertebra and laterality pickers of the active observation. */
export default function ObservationPickers({
sheet,
activeIndex,
activeObs,
vertebraTarget,
lateralTarget,
onCloseVertebra,
onCloseLateral,
}: ObservationPickersProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const updateObservation = useReportStore((s) => s.updateObservation)
const vertebraZone =
vertebraTarget !== null ? activeObs?.zones[vertebraTarget] : undefined
const vertebraAnnotation =
vertebraZone && sheet.annotation(vertebraZone.annotationId)
const lateralAnnotation =
lateralTarget && sheet.annotation(lateralTarget.annotationId)
return (
<>
{vertebraTarget !== null &&
activeObs &&
vertebraZone &&
isObservable(vertebraAnnotation) && (
<VertebraPicker
open
onClose={onCloseVertebra}
onConfirm={(vertebrae) => {
const fresh =
useReportStore.getState().report?.observations[activeIndex]
if (fresh) {
updateObservation(
activeIndex,
syncVertebrae(fresh, vertebrae, sheet, vertebraZone.viewId),
)
}
onCloseVertebra()
}}
initial={collectVertebrae(activeObs, sheet, vertebraTarget)}
regions={sheet.regions()}
title={`${t('vertebra.title_prefix')}${pickLabel(vertebraAnnotation.name, locale)}`}
initialRegion={
vertebraAnnotation.vertebral_region_code ?? undefined
}
/>
)}
{lateralTarget && activeObs && lateralAnnotation && (
<LateralityPicker
open
onClose={onCloseLateral}
title={pickLabel(sheet.name(lateralAnnotation), locale)}
existingSides={sidesPresent(activeObs, lateralTarget)}
onSelect={(sides: LateralSide[]) => {
const fresh =
useReportStore.getState().report?.observations[activeIndex]
if (fresh)
updateObservation(
activeIndex,
addSides(fresh, lateralAnnotation, sides),
)
onCloseLateral()
}}
/>
)}
</>
)
}
@@ -0,0 +1,31 @@
import Button from '@/components/ui/Button'
import Dialog from '@/components/ui/Dialog'
import { useT } from '@/i18n/useT'
export interface DisclaimerDialogProps {
text: string
onAcknowledge: () => void
}
/** Scope disclaimer of the sheet, shown once per tab session. */
export default function DisclaimerDialog({
text,
onAcknowledge,
}: DisclaimerDialogProps) {
const t = useT()
return (
<Dialog
open
onClose={onAcknowledge}
title={t('editor.disclaimer_title')}
size="md"
>
<div className="space-y-4">
<p className="text-sm text-[var(--color-ink)]">{text}</p>
<div className="flex justify-end">
<Button onClick={onAcknowledge}>{t('common.understood')}</Button>
</div>
</div>
</Dialog>
)
}
@@ -0,0 +1,71 @@
import type { ComponentProps } from 'react'
import type { Animal, Owner, Practitioner } from '@faunosteo/domain'
import Button from '@/components/ui/Button'
import Dialog from '@/components/ui/Dialog'
import PractitionerForm from '@/components/report/PractitionerForm'
import AnimalForm from '@/components/report/AnimalForm'
import { useT } from '@/i18n/useT'
export interface Identity {
practitioner: Practitioner
animal: Animal
owner: Owner
}
export interface EditInfosDialogProps {
draft: Identity
species: ComponentProps<typeof AnimalForm>['species']
onChange: (next: Identity) => void
onCancel: () => void
onSave: () => void
}
/** The three names are mandatory to save the identity block. */
export function isIdentityComplete(identity: Identity): boolean {
return [
identity.practitioner.name,
identity.animal.name,
identity.owner.name,
].every((v) => v.trim())
}
/** Identity edit dialog of the editor: practitioner, animal and owner. */
export default function EditInfosDialog({
draft,
species,
onChange,
onCancel,
onSave,
}: EditInfosDialogProps) {
const t = useT()
return (
<Dialog
open
onClose={onCancel}
title={t('editor.edit_dialog_title')}
size="lg"
>
<div className="space-y-8">
<PractitionerForm
value={draft.practitioner}
onChange={(next) => onChange({ ...draft, practitioner: next })}
/>
<AnimalForm
animal={draft.animal}
owner={draft.owner}
species={species}
onChangeAnimal={(next) => onChange({ ...draft, animal: next })}
onChangeOwner={(next) => onChange({ ...draft, owner: next })}
/>
<div className="flex gap-3 justify-end pt-2 border-t border-[var(--color-border)]">
<Button variant="ghost" onClick={onCancel}>
{t('common.cancel')}
</Button>
<Button onClick={onSave} disabled={!isIdentityComplete(draft)}>
{t('common.save')}
</Button>
</div>
</div>
</Dialog>
)
}