feat(editor): the canvas tells an engine failure (retry) from a view it cannot draw (no retry)

This commit is contained in:
bchanot committed 2026-10-15 01:03:16 +02:00
1 parent 6882c6da4a
commit c0a5c8c7ce
8 files changed
+182 -36

No files matched your search

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { buildViewSvg, type ViewStates } from '@/anatomy/drawing'
import { buildViewSvg, type ViewFailure, type ViewStates } from '@/anatomy/drawing'
import type { SheetIndex } from '@/services/sheetIndex'
import { useLocaleStore } from '@/state/localeStore'
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
@@ -26,8 +26,9 @@ function annotatedTarget(event: Event): Element | null {
* One view of the sheet: the drawing plus the annotation layer, composed by
* the core (R3), rebuilt when the view changes and restyled in place when the
* selection changes (the restyle runs right after every build). Clicks are
* delegated on `data-anno-id`. When the core cannot compose the view, the
* canvas shows the degraded notice with a retry.
* delegated on `data-anno-id`. When the engine cannot run, the canvas shows the
* degraded notice with a retry; when the view itself cannot be drawn (a drawing
* refused or impossible to compose), a notice without retry: nothing would change.
*/
export default function AnatomyCanvas({
index,
@@ -43,14 +44,14 @@ export default function AnatomyCanvas({
const t = useT()
// Each retry builds again; a failed build leaves the canvas empty behind the notice.
const [attempt, setAttempt] = useState(0)
const [failed, setFailed] = useState(false)
const [failure, setFailure] = useState<ViewFailure | null>(null)
useEffect(() => {
const host = svgRef.current
if (!host) return
const svg = buildViewSvg(index, viewId)
setFailed(svg === null)
host.replaceChildren(...(svg ? [svg] : []))
const build = buildViewSvg(index, viewId)
setFailure(build.ok ? null : build.failure)
host.replaceChildren(...(build.ok ? [build.svg] : []))
}, [index, viewId, attempt])
useEffect(() => {
@@ -129,13 +130,17 @@ export default function AnatomyCanvas({
className="w-full h-full [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:mx-auto"
/>
<div ref={tooltipRef} className="zone-tooltip" style={{ opacity: 0 }} />
{failed && (
{failure && (
<div className="absolute inset-0 grid place-items-center p-4">
<div className="space-y-3 max-w-sm">
<Notice tone="error">{t('sheet.core_unavailable')}</Notice>
<Button onClick={() => setAttempt((n) => n + 1)}>
{t('sheet.core_retry')}
</Button>
<Notice tone="error">
{t(failure === 'engine' ? 'sheet.core_unavailable' : 'canvas.view_unavailable')}
</Notice>
{failure === 'engine' && (
<Button onClick={() => setAttempt((n) => n + 1)}>
{t('sheet.core_retry')}
</Button>
)}
</div>
</div>
)}