feat(editor): a clear final state once the engine spent its three recoveries (canvas and action alerts)
This commit is contained in:
1 parent
f0580922b5
commit
0279953e9e
19 files changed
+101
-16
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { coreStopped } from '@/core/runtime'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
|
||||
/**
|
||||
@@ -10,11 +11,12 @@ import type { SheetIndex } from '@/services/sheetIndex'
|
||||
export type ViewStates = ReadonlyMap<string, 'current'>
|
||||
|
||||
/**
|
||||
* Why a view cannot be drawn: the engine did not run (a retry may succeed), or the view
|
||||
* Why a view cannot be drawn: the engine did not run (a retry may succeed), the engine
|
||||
* stopped after its three recoveries (only a reload starts it again), or the view
|
||||
* itself cannot be drawn (a refused drawing, a view the core cannot compose: retrying
|
||||
* changes nothing). The technical kind stays in the core's outcome and the DEV console.
|
||||
*/
|
||||
export type ViewFailure = 'engine' | 'view'
|
||||
export type ViewFailure = 'engine' | 'engine_stopped' | 'view'
|
||||
|
||||
export type ViewBuild = { ok: true; svg: SVGSVGElement } | { ok: false; failure: ViewFailure }
|
||||
|
||||
@@ -28,7 +30,8 @@ function failed(failure: ViewFailure, kind: string, detail?: string): ViewBuild
|
||||
export function buildViewSvg(index: SheetIndex, viewId: string): ViewBuild {
|
||||
const text = index.canvasSvg(viewId)
|
||||
if (!text.ok) {
|
||||
return failed(ENGINE_KINDS.has(text.kind) ? 'engine' : 'view', text.kind, text.detail)
|
||||
const engine = coreStopped() ? 'engine_stopped' : 'engine'
|
||||
return failed(ENGINE_KINDS.has(text.kind) ? engine : 'view', text.kind, text.detail)
|
||||
}
|
||||
const parsed = new DOMParser().parseFromString(text.value, 'image/svg+xml')
|
||||
const root = parsed.documentElement
|
||||
|
||||
@@ -36,6 +36,7 @@ import type { ExportWarning } from '@faunosteo/pdf'
|
||||
import type { RebaseOutcome } from '@faunosteo/core-wasm/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
|
||||
import { coreFailureMessage } from '@/core/failure'
|
||||
|
||||
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
||||
|
||||
@@ -161,7 +162,7 @@ export default function EditorRoute() {
|
||||
const activeObs =
|
||||
activeIndex >= 0 ? report.observations[activeIndex] : undefined
|
||||
const outcome = sheet.index.ops.zoneClick(activeObs ?? null, annotationId)
|
||||
if (!outcome.ok) return window.alert(t('core.action_failed'))
|
||||
if (!outcome.ok) return window.alert(coreFailureMessage(t))
|
||||
const click = outcome.value
|
||||
if (click.observation) store.updateObservation(activeIndex, click.observation)
|
||||
switch (click.kind) {
|
||||
@@ -189,7 +190,7 @@ export default function EditorRoute() {
|
||||
/** A store action the core ran: the practitioner hears about a failure. */
|
||||
const guarded = useCallback(
|
||||
(result: ActionResult) => {
|
||||
if (!result.ok) window.alert(t('core.action_failed'))
|
||||
if (!result.ok) window.alert(coreFailureMessage(t))
|
||||
},
|
||||
[t],
|
||||
)
|
||||
@@ -198,7 +199,7 @@ export default function EditorRoute() {
|
||||
function openVertebraPicker(index: SheetIndex, zoneIndex: number) {
|
||||
if (!activeObs) return
|
||||
const outcome = index.ops.vertebraInitial(activeObs, zoneIndex)
|
||||
if (!outcome.ok) return window.alert(t('core.action_failed'))
|
||||
if (!outcome.ok) return window.alert(coreFailureMessage(t))
|
||||
setVertebraTarget({ zoneIndex, initial: outcome.value })
|
||||
}
|
||||
|
||||
@@ -207,7 +208,7 @@ export default function EditorRoute() {
|
||||
if (!obs) return
|
||||
const outcome = index.ops.removeZoneAt(obs, zoneIndex)
|
||||
if (outcome.ok) store.updateObservation(i, outcome.value)
|
||||
else window.alert(t('core.action_failed'))
|
||||
else window.alert(coreFailureMessage(t))
|
||||
}
|
||||
|
||||
function acknowledgeDisclaimer() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { loadSheetIndex, useSheetAvailability } from '@/sheets/useSheet'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { coreFailureMessage } from '@/core/failure'
|
||||
|
||||
/** The one species this build ships a sheet for. */
|
||||
export const DEFAULT_SPECIES_ID = 'equine'
|
||||
@@ -71,7 +72,7 @@ export default function NewReportRoute() {
|
||||
else if (created.reason === 'held') {
|
||||
window.alert(t('session.held_blocked'))
|
||||
navigate('/editor')
|
||||
} else window.alert(t('core.action_failed'))
|
||||
} else window.alert(coreFailureMessage(t))
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -17,6 +17,13 @@ export interface AnatomyCanvasProps {
|
||||
|
||||
const ANNOTATED = '[data-anno-id]'
|
||||
|
||||
/** Only an engine that can still recover offers a retry. */
|
||||
const FAILURE_MESSAGE: Record<ViewFailure, string> = {
|
||||
engine: 'sheet.core_unavailable',
|
||||
engine_stopped: 'core.stopped',
|
||||
view: 'canvas.view_unavailable',
|
||||
}
|
||||
|
||||
function annotatedTarget(event: Event): Element | null {
|
||||
const target = event.target
|
||||
return target instanceof Element ? target.closest(ANNOTATED) : null
|
||||
@@ -133,9 +140,7 @@ export default function AnatomyCanvas({
|
||||
{failure && (
|
||||
<div className="absolute inset-0 grid place-items-center p-4">
|
||||
<div className="space-y-3 max-w-sm">
|
||||
<Notice tone="error">
|
||||
{t(failure === 'engine' ? 'sheet.core_unavailable' : 'canvas.view_unavailable')}
|
||||
</Notice>
|
||||
<Notice tone="error">{t(FAILURE_MESSAGE[failure])}</Notice>
|
||||
{failure === 'engine' && (
|
||||
<Button onClick={() => setAttempt((n) => n + 1)}>
|
||||
{t('sheet.core_retry')}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { pickLabel } from '@/i18n/pickLocaleLabel'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
import { coreFailureMessage } from '@/core/failure'
|
||||
|
||||
export interface ObservationCardProps {
|
||||
observation: Observation
|
||||
@@ -168,7 +169,7 @@ export default function ObservationCard({
|
||||
...(side ? { side } : {}),
|
||||
})
|
||||
if (outcome.ok) onChange(outcome.value)
|
||||
else window.alert(t('core.action_failed'))
|
||||
else window.alert(coreFailureMessage(t))
|
||||
}
|
||||
const removeFinding = (target: Finding) =>
|
||||
onChange({
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useLocaleStore } from '@/state/localeStore'
|
||||
import { isObservable, type SheetIndex } from '@/services/sheetIndex'
|
||||
import { pickLabel } from '@/i18n/pickLocaleLabel'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { coreFailureMessage } from '@/core/failure'
|
||||
|
||||
/** The zone the vertebra picker edits, with its initial selection (computed on open). */
|
||||
export interface VertebraTarget {
|
||||
@@ -63,7 +64,7 @@ export default function ObservationPickers({
|
||||
if (!fresh) return
|
||||
const outcome = run(fresh)
|
||||
if (outcome.ok) updateObservation(activeIndex, outcome.value)
|
||||
else window.alert(t('core.action_failed'))
|
||||
else window.alert(coreFailureMessage(t))
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -11,6 +11,7 @@ import { pickLabel } from '@/i18n/pickLocaleLabel'
|
||||
import { reportOps } from '@/core/reportOps'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { coreFailureMessage } from '@/core/failure'
|
||||
|
||||
export interface VertebraPickerProps {
|
||||
open: boolean
|
||||
@@ -68,7 +69,7 @@ export default function VertebraPicker({
|
||||
const apply = (action: VertebraAction) => {
|
||||
const outcome = reportOps.selectVertebrae(selected, action)
|
||||
if (outcome.ok) setSelected(outcome.value)
|
||||
else window.alert(t('core.action_failed'))
|
||||
else window.alert(coreFailureMessage(t))
|
||||
}
|
||||
const toggle = (region: string, index: number) =>
|
||||
apply({ kind: 'toggle', region, index })
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { useT } from '@/i18n/useT'
|
||||
import { coreStopped } from './runtime'
|
||||
|
||||
/**
|
||||
* The alert after a core action failed: "try again" while a retry can work; once the engine
|
||||
* stopped after its three recoveries, the clear final state (reload the page, the report is
|
||||
* kept in the tab) instead of a retry that cannot succeed (owner decision 2026-10-15).
|
||||
*/
|
||||
export function coreFailureMessage(t: ReturnType<typeof useT>): string {
|
||||
return t(coreStopped() ? 'core.stopped' : 'core.action_failed')
|
||||
}
|
||||
@@ -34,6 +34,11 @@ const browserSource: CoreSource = {
|
||||
|
||||
let runtime: CoreRuntime | null = null
|
||||
|
||||
/** Whether the page's runtime spent its recoveries (never creates the runtime). */
|
||||
export function coreStopped(): boolean {
|
||||
return runtime?.stopped ?? false
|
||||
}
|
||||
|
||||
/** The page's runtime, created on first use. */
|
||||
export function coreRuntime(): CoreRuntime {
|
||||
runtime ??= new CoreRuntime(browserSource)
|
||||
|
||||
@@ -201,6 +201,8 @@ export const en: Dict = {
|
||||
'sheet.core_unavailable':
|
||||
"Faunosteo's computation engine could not be loaded. Your session data is kept.",
|
||||
'sheet.core_retry': 'Retry',
|
||||
'core.stopped':
|
||||
"Faunosteo's computation engine stopped after several successive errors. Reload the page to start it again: your report is kept in this tab.",
|
||||
'canvas.view_unavailable':
|
||||
"This anatomical view cannot be displayed: its drawing was refused by the safety checks or could not be composed. Your report is not changed.",
|
||||
'core.action_failed':
|
||||
|
||||
@@ -215,6 +215,8 @@ export const fr: Dict = {
|
||||
'sheet.core_unavailable':
|
||||
"Le moteur de calcul de Faunosteo n'a pas pu être chargé. Vos données de session sont conservées.",
|
||||
'sheet.core_retry': 'Réessayer',
|
||||
'core.stopped':
|
||||
"Le moteur de calcul de Faunosteo s'est arrêté après plusieurs erreurs successives. Rechargez la page pour le relancer : votre bilan est conservé dans cet onglet.",
|
||||
'canvas.view_unavailable':
|
||||
"Cette vue anatomique ne peut pas être affichée : son dessin a été refusé par les contrôles de sécurité ou n'a pas pu être composé. Votre bilan n'est pas modifié.",
|
||||
'core.action_failed':
|
||||
|
||||
Reference in new issue
Block a user