feat(editor): tell the practitioner when a restored draft was rebased on a different sheet

This commit is contained in:
bchanot committed 2026-10-11 16:15:13 +02:00
1 parent 5ed4a4b620
commit e8f1734424
5 files changed
+64 -5

No files matched your search

+19 -3
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import AnatomyCanvas from '@/components/canvas/AnatomyCanvas'
import DetailModal from '@/components/canvas/DetailModal'
@@ -29,6 +29,7 @@ import {
import type { ViewStates } from '@/anatomy/drawing'
import { exportReportToPdf } from '@/pdf/export'
import type { ExportWarning } from '@faunosteo/pdf'
import type { RebaseOutcome } from '@faunosteo/domain'
import { useT } from '@/i18n/useT'
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
@@ -39,6 +40,11 @@ function missingItemsOf(warnings: readonly ExportWarning[]): string[] {
return warnings.map((w) => (w.kind === 'logo_failed' ? w.slot : w.viewId))
}
/** Zones and findings a draft rebase could not find on the loaded sheet. */
function unresolvedCountOf(outcome: RebaseOutcome): number {
return outcome.unresolvedZones + outcome.unresolvedFindings
}
/** Editor on the reference sheet: wires the canvas, the pickers and the store. */
export default function EditorRoute() {
const navigate = useNavigate()
@@ -55,18 +61,28 @@ export default function EditorRoute() {
const [disclaimer, setDisclaimer] = useState<string | null>(null)
const [exporting, setExporting] = useState(false)
const [editDraft, setEditDraft] = useState<Identity | null>(null)
// One alert per restore, even if the effect runs again before the re-render.
const rebaseAlerted = useRef(false)
useEffect(() => {
window.scrollTo({ top: 0, left: 0, behavior: 'auto' })
}, [])
// No report in memory: restore the per-tab draft once the sheet is known.
// A draft rebased on another sheet is announced with its unresolved count.
useEffect(() => {
if (report) return
if (sheet.status === 'ready') store.restoreDraft(sheet.index)
if (sheet.status === 'ready') {
const outcome = store.restoreDraft(sheet.index)
if (outcome?.rebased && !rebaseAlerted.current) {
rebaseAlerted.current = true
const count = String(unresolvedCountOf(outcome))
window.alert(t('editor.draft_rebased').replace('{count}', count))
}
}
if (sheet.status !== 'loading' && !useReportStore.getState().report)
navigate('/')
}, [report, sheet, store, navigate])
}, [report, sheet, store, navigate, t])
useEffect(() => {
if (sheet.status !== 'ready' || typeof sessionStorage === 'undefined')
+2
View File
@@ -68,6 +68,8 @@ export const en: Dict = {
'editor.export_failed': 'PDF generation failed. Retry or contact support.',
'editor.export_warnings':
'PDF exported with missing elements: {items}. Check the browser console.',
'editor.draft_rebased':
'Draft restored on an anatomical sheet different from the one it was created on. Items not found: {count} (kept with their labels).',
'editor.edit_infos': 'Edit info',
'editor.edit_dialog_title': 'Edit information',
'editor.disclaimer_title': 'Legal scope of animal osteopathy',
+2
View File
@@ -74,6 +74,8 @@ export const fr: Dict = {
'Échec de la génération du PDF. Réessayez ou contactez le support.',
'editor.export_warnings':
'PDF exporté avec des éléments manquants : {items}. Vérifiez la console du navigateur.',
'editor.draft_rebased':
'Brouillon restauré sur une fiche anatomique différente de celle où il a été créé. Éléments non retrouvés : {count} (conservés avec leurs libellés).',
'editor.edit_infos': 'Modifier les infos',
'editor.edit_dialog_title': 'Modifier les informations',
'editor.disclaimer_title': "Périmètre légal de l'ostéopathie animale",