From 9c7cbeaf1391937ecbb0e0eb7e6564216383f99a Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 23 Nov 2026 17:09:11 +0100 Subject: [PATCH] fix(editor): views requests never run late, refusals announced --- apps/app/e2e/shell/editor-journey.spec.ts | 5 +++ .../annotations/EditableAnnotations.tsx | 7 +++- .../sections/AnnotationSection.tsx | 5 ++- .../components/editor/views/DetailViewRow.tsx | 39 ++++++++++-------- .../editor/annotations/useViewsRequestRun.ts | 30 ++++++++++---- apps/app/src/i18n/en.ts | 2 + apps/app/src/i18n/fr.ts | 2 + .../app/tests/unit/editor-tabs-views.test.tsx | 41 +++++++++++++++++++ 8 files changed, 103 insertions(+), 28 deletions(-) diff --git a/apps/app/e2e/shell/editor-journey.spec.ts b/apps/app/e2e/shell/editor-journey.spec.ts index 2c35cdd4..2ce5ebb8 100644 --- a/apps/app/e2e/shell/editor-journey.spec.ts +++ b/apps/app/e2e/shell/editor-journey.spec.ts @@ -178,6 +178,11 @@ async function createAnnotations(page: Page) { .selectOption({ label: 'Zone essai' }) await createFromPanel(page, dict) await toolButton(page, dict, 'link').click() + // The access tool defaults to the rectangle (D5): the polygon is chosen to trace one. + await page + .getByTestId('access-shape') + .getByText(dict['editor.annotations.shape.polygon'], { exact: true }) + .click() await trace([ [30, 94], [70, 94], diff --git a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx index 662ea752..5f514539 100644 --- a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx +++ b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx @@ -262,7 +262,12 @@ export default function EditableAnnotations(props: Props) { const work = useWork(scene) const { ui, selected } = scene const visible = usePlaceVisible() - useViewsRequestRun(scene, visible) + useViewsRequestRun(scene, visible, () => + work.message.show(work.context.t('editor.views.request_busy'), { + undo: false, + tone: 'info', + }), + ) const framing = useAnnotationWork((s) => s.frame !== null) const { asideRef, byDrawing } = useSelectionEscape( selected?.id ?? null, diff --git a/apps/app/src/components/editor/annotations/sections/AnnotationSection.tsx b/apps/app/src/components/editor/annotations/sections/AnnotationSection.tsx index dcf737f3..cd600a04 100644 --- a/apps/app/src/components/editor/annotations/sections/AnnotationSection.tsx +++ b/apps/app/src/components/editor/annotations/sections/AnnotationSection.tsx @@ -29,7 +29,10 @@ export default function AnnotationSection({ const { titleKey, Body } = ANNOTATION_SECTION_BODIES[section] const headingId = `annotation-section-${section}-title` return ( -
+
diff --git a/apps/app/src/components/editor/views/DetailViewRow.tsx b/apps/app/src/components/editor/views/DetailViewRow.tsx index 875fe28b..d5233931 100644 --- a/apps/app/src/components/editor/views/DetailViewRow.tsx +++ b/apps/app/src/components/editor/views/DetailViewRow.tsx @@ -1,5 +1,6 @@ import type { DetailView, SheetView } from '@faunosteo/core-wasm/types' import ActionButton from '@/components/editor/fields/ActionButton' +import Notice from '@/components/ui/Notice' import SelectField from '@/components/editor/fields/SelectField' import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest' import { useViewUpdate } from '@/editor/useViewUpdate' @@ -66,24 +67,26 @@ export default function DetailViewRow({ {missingAccess && ( -
-

- {t('editor.views.no_access').replace( - '{name}', - () => - parents.find((p) => p.value === view.parent_view_id)?.label ?? - '', - )} -

- - {t('editor.views.add_access')} - -
+ +
+

+ {t('editor.views.no_access').replace( + '{name}', + () => + parents.find((p) => p.value === view.parent_view_id)?.label ?? + '', + )} +

+ + {t('editor.views.add_access')} + +
+
)}
{onRecrop && view.svg_asset_id === null && ( diff --git a/apps/app/src/editor/annotations/useViewsRequestRun.ts b/apps/app/src/editor/annotations/useViewsRequestRun.ts index 32207872..5a046056 100644 --- a/apps/app/src/editor/annotations/useViewsRequestRun.ts +++ b/apps/app/src/editor/annotations/useViewsRequestRun.ts @@ -1,5 +1,6 @@ import { useEffect } from 'react' import { placeAtCentre } from './usePlacement' +import { useAnnotationWork } from './workStore' import type { Scene } from '@/components/editor/annotations/EditableAnnotations' import { clearViewsRequest, @@ -21,7 +22,11 @@ function armed(scene: Scene, viewId: string): boolean { * the default rectangle once the drawing is measured. Each step ends the effect; the * next render runs the next one. */ -function accessStep(scene: Scene, request: ViewsRequest & { kind: 'access' }) { +function accessStep( + scene: Scene, + request: ViewsRequest & { kind: 'access' }, + refuse: () => void, +) { const { dispatch, viewId, frame, model } = scene if (viewId !== request.parentId) { return dispatch({ type: 'view', viewId: request.parentId }) @@ -34,21 +39,30 @@ function accessStep(scene: Scene, request: ViewsRequest & { kind: 'access' }) { if (!frame || !model.measured) return clearViewsRequest() placeAtCentre(scene, 'detail_trigger', 'add') + if (useAnnotationWork.getState().creation === null) refuse() } /** * Runs the views section's request once the drawing is shown: the frame creation, or the - * access placement. A request whose view is gone is dropped. + * access placement. A request that cannot run now (the drawing is hidden, its view is + * gone) is dropped, never kept for a later visit; one the work in progress refuses is + * told through `refuse`. */ -export function useViewsRequestRun(scene: Scene, visible: boolean): void { +export function useViewsRequestRun( + scene: Scene, + visible: boolean, + refuse: () => void, +): void { const request = useViewsRequest((s) => s.request) useEffect(() => { - if (!request || !visible) return + if (!request) return const { parentId: parent } = request - const known = (id: string) => scene.doc.views.some((view) => view.id === id) - if (parent !== null && !known(parent)) return clearViewsRequest() - if (request.kind === 'access') return accessStep(scene, request) + const gone = + parent !== null && !scene.doc.views.some((view) => view.id === parent) + if (!visible || gone) return clearViewsRequest() + if (request.kind === 'access') return accessStep(scene, request, refuse) clearViewsRequest() - startDetailView(parent ?? scene.viewId, scene.viewId, scene.dispatch) + const shown = scene.viewId + if (!startDetailView(parent ?? shown, shown, scene.dispatch)) refuse() }) } diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 8c680663..eefe6daa 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1640,6 +1640,8 @@ export const en: Dict = { 'editor.views.precise': 'Precise values', 'editor.views.no_access': 'No access on “{name}”', 'editor.views.add_access': 'Add the access', + 'editor.views.request_busy': + 'Finish or abandon the work in progress before starting.', 'editor.views.crop.min_x': 'Crop: minimum x', 'editor.views.crop.min_y': 'Crop: minimum y', 'editor.views.crop.width': 'Crop: width', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index 008db107..137a51df 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1703,6 +1703,8 @@ export const fr: Dict = { 'editor.views.precise': 'Valeurs précises', 'editor.views.no_access': 'Aucun accès sur « {name} »', 'editor.views.add_access': "Ajouter l'accès", + 'editor.views.request_busy': + 'Terminez ou abandonnez le travail en cours avant de commencer.', 'editor.views.crop.min_x': 'Recadrage : x minimum', 'editor.views.crop.min_y': 'Recadrage : y minimum', 'editor.views.crop.width': 'Recadrage : largeur', diff --git a/apps/app/tests/unit/editor-tabs-views.test.tsx b/apps/app/tests/unit/editor-tabs-views.test.tsx index 4339fcfd..b756d37e 100644 --- a/apps/app/tests/unit/editor-tabs-views.test.tsx +++ b/apps/app/tests/unit/editor-tabs-views.test.tsx @@ -2,6 +2,7 @@ import { createHash } from 'node:crypto' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { + act, cleanup, render, screen, @@ -23,8 +24,10 @@ import { AnnounceContext } from '@/editor/focusRequest' import { useEditorNavigation } from '@/editor/useEditorNavigation' import { clearViewsRequest, + requestViews, useViewsRequest, } from '@/editor/annotations/viewsRequest' +import { emptyForm } from '@/editor/annotations/creation' import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore' import { useLocaleStore } from '@/state/localeStore' import { @@ -509,6 +512,44 @@ describe('« Gérer les vues » follows the new journey', () => { }) }) +describe('requests the drawing cannot run', () => { + it('a request made while the drawing is hidden is dropped, not kept for a later visit', async () => { + const user = await openViews() + act(() => requestViews({ kind: 'create', parentId: null })) + await waitFor(() => expect(useViewsRequest.getState().request).toBeNull()) + await user.click(screen.getByRole('button', { name: 'Retour au dessin' })) + expect(frame()).toBeNull() + }) + + it('work in progress refuses the creation and the person is told', async () => { + const user = await openViews() + useAnnotationWork.setState({ + creation: { + viewId: 'view-main', + frame: null, + origin: 'add', + pending: { + kind: 'point', + geometry: { type: 'circle', cx: 5, cy: 5, r: 2 }, + }, + closed: true, + form: emptyForm(doc(), 'point'), + dialog: false, + resumed: false, + }, + }) + await user.click( + screen.getByRole('button', { name: 'Tracer sur le dessin' }), + ) + expect( + await screen.findByText( + 'Terminez ou abandonnez le travail en cours avant de commencer.', + ), + ).toBeTruthy() + expect(frame()).toBeNull() + }) +}) + describe('« Valeurs précises » and « Recadrer sur le dessin »', () => { it('the four fields stay folded until the disclosure opens', async () => { await openReady({ text: insert(emptyText(), detail()) })