diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts index 5813e914..3b0c765e 100644 --- a/apps/app/e2e/support/editor.ts +++ b/apps/app/e2e/support/editor.ts @@ -769,10 +769,6 @@ export async function pickAnnotation( await page.evaluate(() => window.scrollTo(0, 0)) } -/** The open properties dialog of an annotation (U2 Task 6), by its name. */ -export const propertiesDialog = (page: Page, name?: string | RegExp) => - page.getByRole('dialog', name === undefined ? {} : { name }) - /** « Propriétés » in the strip: the selection's properties dialog (A1). */ export async function openProperties(page: Page, dict: Dict) { await page diff --git a/apps/app/src/components/editor/EditorGlyph.tsx b/apps/app/src/components/editor/EditorGlyph.tsx index 7b7f8841..0db1f326 100644 --- a/apps/app/src/components/editor/EditorGlyph.tsx +++ b/apps/app/src/components/editor/EditorGlyph.tsx @@ -12,6 +12,9 @@ export type GlyphName = | 'deselect' | 'move' | 'properties' + | 'edit' + | 'check' + | 'trash' /** The editor's one glyph table (24-unit grid strokes); `book` and `close` are in `Icon`. */ const GLYPHS: Record = { @@ -27,6 +30,9 @@ const GLYPHS: Record = { search: 'M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4', move: 'M12 3v18M3 12h18M9 6l3-3 3 3M9 18l3 3 3-3M6 9l-3 3 3 3M18 9l3 3-3 3', properties: 'M7 3h7l4 4v14H7zM14 3v4h4M10 12h5M10 16h5', + edit: 'M4 20h4L19 9l-4-4L4 16zM14 6l4 4', + check: 'M5 12l5 5L19 7', + trash: 'M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13', deselect: 'M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3M9 9l6 6M15 9l-6 6', } diff --git a/apps/app/src/components/editor/annotations/AnnotationDialog.tsx b/apps/app/src/components/editor/annotations/AnnotationDialog.tsx index 2aec6f70..d6131fe3 100644 --- a/apps/app/src/components/editor/annotations/AnnotationDialog.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationDialog.tsx @@ -34,6 +34,13 @@ export interface AnnotationDialogProps { } const EDIT_BUTTON_ID = 'annotation-edit-button' + +/** « Modifier la forme » shows the shape it edits (board 31 A, B). */ +const SHAPE_GLYPH = { + point: 'point', + zone: 'zone', + detail_trigger: 'link', +} as const const ACTION = 'min-h-11 gap-1.5 xl:min-h-9' /** @@ -91,6 +98,7 @@ function StatusAction({ annotation }: { annotation: Annotation }) { className={ACTION} onClick={() => mark(reviewed ? 'to_confirm' : 'reviewed')} > + {!reviewed && } {t( reviewed ? 'editor.annotations.to_confirm' @@ -143,6 +151,7 @@ function ReadActions(props: ReadProps) { className={ACTION} onClick={props.onEdit} > + {t('editor.findings.edit')} {shapeEditable && ( @@ -153,7 +162,7 @@ function ReadActions(props: ReadProps) { className={ACTION} onClick={props.onEditShape} > - + {t('editor.annotations.edit_shape')} )} @@ -163,10 +172,12 @@ function ReadActions(props: ReadProps) { diff --git a/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx b/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx index dace1be2..015f67db 100644 --- a/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx @@ -54,8 +54,17 @@ function draftOf(annotation: Annotation): Draft { } } +/** The draft as it would be saved: names and colour trimmed. */ +const normalized = (draft: Draft): Draft => ({ + ...draft, + fr: draft.fr.trim(), + en: draft.en.trim(), + color: draft.color.trim(), +}) + +/** A space typed and nothing else is no change: no dirty guard, no empty `update`. */ const sameDraft = (a: Draft, b: Draft) => - JSON.stringify(a) === JSON.stringify(b) + JSON.stringify(normalized(a)) === JSON.stringify(normalized(b)) /** The names as saved: trimmed, or none for a link left with both blank. */ function namesOf(annotation: Annotation, draft: Draft) { @@ -69,7 +78,9 @@ function namesOf(annotation: Annotation, draft: Draft) { * change made meanwhile elsewhere (a drag, a review toggle) is never overwritten. */ function merged(current: Annotation, first: Draft, draft: Draft): Annotation { - const changed = (key: keyof Draft) => first[key] !== draft[key] + const was = normalized(first) + const now = normalized(draft) + const changed = (key: keyof Draft) => was[key] !== now[key] const value: Record = { ...current } if (changed('fr') || changed('en')) value.name = namesOf(current, draft) if (changed('categoryId')) value.category_id = draft.categoryId diff --git a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx index 3bd20346..a840519d 100644 --- a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx +++ b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx @@ -362,9 +362,15 @@ function SidePanel({ readOnly={false} filter={ui.filter} onFilter={(term) => dispatch({ type: 'filter', term })} - onSelectView={(id) => dispatch({ type: 'view', viewId: id })} + // The column stays shown during a selection (A3): a row or a view that would drop + // a started move or redraw asks first (R-12). + onSelectView={(id) => + guarded(() => dispatch({ type: 'view', viewId: id }))() + } selectedId={scene.selected?.id ?? null} - onSelectAnnotation={(id) => dispatch({ type: 'select', id })} + onSelectAnnotation={(id) => + guarded(() => dispatch({ type: 'select', id }))() + } onOpenAnnotation={(id) => scene.onOpen(id, 'drawing')} onOpenSection={scene.onOpenSection} /> diff --git a/apps/app/src/editor/annotations/dialogOpening.ts b/apps/app/src/editor/annotations/dialogOpening.ts index 7b1f071c..4ab69898 100644 --- a/apps/app/src/editor/annotations/dialogOpening.ts +++ b/apps/app/src/editor/annotations/dialogOpening.ts @@ -48,6 +48,11 @@ export function useDialogOpening( const opened = useRef<{ id: string; by: OpenedBy } | null>(null) const latest = useRef(layer) latest.current = layer + // A layer opened by a reload or a Forward has no opener: its row is the way back. + const shown = layer?.view?.id + if (shown && opened.current?.id !== shown) { + opened.current = { id: shown, by: 'drawing' } + } const open: OpenDialog = (id, by) => { const go = () => { opened.current = { id, by } diff --git a/apps/app/tests/helpers/annotationLayer.tsx b/apps/app/tests/helpers/annotationLayer.tsx index bfa5ed50..c6c37555 100644 --- a/apps/app/tests/helpers/annotationLayer.tsx +++ b/apps/app/tests/helpers/annotationLayer.tsx @@ -24,17 +24,3 @@ export function LayeredTab( ) } - -/** « Propriétés » in the strip, then the dialog it opened. */ -export async function openProperties( - user: { click: (element: Element) => Promise }, - within: (element: HTMLElement) => { - getByRole: (role: string, o: object) => HTMLElement - }, -): Promise { - const strip = document.querySelector( - '[data-testid="edit-strip"]', - )! - await user.click(within(strip).getByRole('button', { name: 'Propriétés' })) - return document.querySelector('dialog[open]')! -} diff --git a/apps/app/tests/unit/editor-annotation-dialog.test.tsx b/apps/app/tests/unit/editor-annotation-dialog.test.tsx index b0688c30..d7dad64f 100644 --- a/apps/app/tests/unit/editor-annotation-dialog.test.tsx +++ b/apps/app/tests/unit/editor-annotation-dialog.test.tsx @@ -219,6 +219,47 @@ describe('the read mode (board 31 A, B)', () => { expect(within(dialog()!).getByText('#aa0000')).toBeInTheDocument() }) + it('an unnamed link: its opened view, « Vue ouverte », no findings zone', async () => { + const detail = insert(drawnText(), { + kind: 'view', + value: { + kind: 'detail', + id: 'view-det', + name: { fr: 'Tête', en: 'Head' }, + svg_asset_id: null, + view_box: { min_x: 10, min_y: 10, width: 80, height: 80 }, + parent_view_id: 'view-main', + }, + }) + const link = { + id: 'link-a', + view_id: 'view-main', + category_id: 'cat-a', + laterality: 'unpaired', + geometry: { type: 'circle', cx: 90, cy: 90, r: 3 }, + review_status: 'to_confirm', + color: null, + kind: 'detail_trigger', + name: null, + opens_view_id: 'view-det', + } as Annotation + await mount(insert(detail, { kind: 'annotation', value: link })) + await selectRow('link-a') + const opened = await openProperties() + expect(rows()).toEqual([ + 'Nom (FR)', + 'Nom (EN)', + 'Catégorie', + 'Latéralité', + 'Vue ouverte', + 'Vue', + ]) + expect(within(opened).getByTestId('annotation-read')).toHaveTextContent( + 'Accès', + ) + expect(within(opened).getAllByText('Tête').length).toBeGreaterThan(0) + }) + it('« Marquer comme relu » is one change and one undo (A10)', async () => { await mount(insert(drawnText(), point('a', 50, 50, 5))) await selectRow('a') @@ -334,6 +375,22 @@ describe('the edit form (board 31 C, R-3)', () => { expect(store.getState().documentText).toBe(before) }) + it('a space typed and nothing else: no change, no history entry', async () => { + await mount(insert(drawnText(), point('a', 50, 50, 5))) + await selectRow('a') + await startEdit() + const user = userEvent.setup() + const before = depth() + await user.type(field('Nom (FR)'), ' ') + await user.click( + within(dialog()!).getByRole('button', { name: 'Enregistrer' }), + ) + expect(depth()).toBe(before) + expect( + within(dialog()!).getByRole('button', { name: 'Modifier' }), + ).toBeInTheDocument() + }) + it('« Annuler » with changes asks; « Abandonner » writes nothing', async () => { await mount(insert(drawnText(), point('a', 50, 50, 5))) await selectRow('a') @@ -483,6 +540,17 @@ describe('the layer (history)', () => { ).toBeInTheDocument() }) + it('a layer opened with no opener (a Forward, a reload) returns the focus to its row', async () => { + await mount(insert(drawnText(), point('a', 50, 50, 5))) + act(() => layered.nav!.openAnnotation('a')) + const opened = await screen.findByRole('dialog') + await userEvent + .setup() + .click(within(opened).getByRole('button', { name: 'Fermer' })) + await waitFor(() => expect(dialog()).toBeNull()) + await waitFor(() => expect(document.activeElement).toBe(rowOf('a'))) + }) + it('a deletion from the dialog closes it, unsaid as a vanish', async () => { await mount(insert(drawnText(), point('a', 50, 50, 5))) await selectRow('a') diff --git a/apps/app/tests/unit/editor-point-edit.test.tsx b/apps/app/tests/unit/editor-point-edit.test.tsx index 4eec2fbf..ba703404 100644 --- a/apps/app/tests/unit/editor-point-edit.test.tsx +++ b/apps/app/tests/unit/editor-point-edit.test.tsx @@ -505,6 +505,26 @@ describe('review fixes: no silent loss, no empty commit, no lost focus', () => { expect(screen.queryByTestId('annotation-creation')).toBeNull() }) + it('another row or a view row of the overview asks first (A3: the column stays shown)', async () => { + await started() + const list = screen.getByRole('list', { name: 'Annotations de la vue' }) + const rows = within(list).getAllByRole('button') + const other = rows.find( + (row) => row.getAttribute('aria-current') !== 'true', + )! + fireEvent.click(other) + expect(question()).toBe('move') + expect(useAnnotationWork.getState().mode?.started).toBe(true) + expect(within(list).getByRole('button', { current: true })).not.toBe(other) + act(() => useAnnotationWork.setState({ question: null })) + const views = screen + .getByRole('heading', { name: 'Vues' }) + .closest('section')! + fireEvent.click(within(views).getAllByRole('button')[0]!) + expect(question()).toBe('move') + expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument() + }) + it('an unstarted mode ends at once on a tool change', async () => { await mount(two()) await select() diff --git a/apps/app/tests/unit/editor-zone-edit.test.tsx b/apps/app/tests/unit/editor-zone-edit.test.tsx index dbd72d9d..76cc3b63 100644 --- a/apps/app/tests/unit/editor-zone-edit.test.tsx +++ b/apps/app/tests/unit/editor-zone-edit.test.tsx @@ -575,6 +575,17 @@ describe('redraw (R-12, board 06 C)', () => { ).toBeInTheDocument() }) + it('a row of the overview asks first once a vertex is placed (A3, R-12)', async () => { + await redrawing() + pressAt(canvas(), 30, 30) + const list = screen.getByRole('list', { name: 'Annotations de la vue' }) + fireEvent.click(within(list).getAllByRole('button')[0]!) + expect(useAnnotationWork.getState().question?.work).toBe('redraw') + expect( + screen.getByRole('button', { name: 'Fermer le tracé' }), + ).toBeInTheDocument() + }) + it('a tool asks first once a vertex is placed; « Abandonner » ends the trace', async () => { await redrawing() pressAt(canvas(), 30, 30)