From 1bf27014b3919eab848e8305d675deb403f0e586 Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 13 Nov 2026 01:08:00 +0100 Subject: [PATCH] fix(editor): one history entry per reference edit, focus kept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final review fixes. « Terminer » and every panel close re-committed the edited field against a stale value, adding a second identical history entry so the first « Défaire » seemed to do nothing: the tile now reads the latest applied value (tests assert the undo-length delta). A tile leaving the search on « Terminer » stays pinned until the next view change and keeps focus; « Ajouter la référence » resets search and sort and focuses the new tile. Also: refused draft dropped on a read-only flip is announced; arrow keys respect a refused tab switch; pinned index kept across read-only; the panel announces « Références citées »; search text inserted literally; « Aller à » names its citer; the edit header's name starts with « Terminer. »; undo removing the focused panel tile moves focus per P20; no-result announced once; docs corrected. Gates: typecheck, lint, test:run (app 1510), build, e2e:ui 251; e2e:shell 16 specs (admin and editor-equine excluded): 117 passed / 108 skipped / 1 failed (crossing:211 stuck on the MFA step-up screen before the editor), rerun alone 11 passed; full-row guard: no pre-existing row changed in any table. --- apps/app/e2e/shell/editor-references.spec.ts | 20 +- apps/app/src/components/editor/EditorTabs.tsx | 11 +- .../editor/references/CitationsPanel.tsx | 7 +- .../editor/references/CitersList.tsx | 4 + .../components/editor/references/NoResult.tsx | 9 +- .../editor/references/ReferenceEditor.tsx | 12 +- .../editor/references/ReferenceTile.tsx | 22 ++- .../editor/references/ReferenceTiles.tsx | 1 + .../editor/references/ReferenceToolbar.tsx | 2 +- .../editor/references/useCitationsPanel.ts | 77 +++++--- .../editor/references/useReferenceEdit.ts | 171 +++++++++++++----- .../editor/references/useReferenceLibrary.ts | 12 +- .../editor/references/useReferenceView.ts | 55 ++++-- .../editor/references/useTileState.ts | 10 + apps/app/src/editor/focusRequest.ts | 2 +- apps/app/src/editor/useEditorNavigation.ts | 28 +-- .../unit/editor-references-panel.test.tsx | 151 +++++++++++++++- .../tests/unit/editor-references-tab.test.tsx | 80 +++++++- .../unit/editor-references-view.test.tsx | 116 +++++++++++- docs/development/V1-2-6_R2_LABELS.md | 19 +- docs/development/V1-2-6_U1_CORRECTIONS.md | 4 +- 21 files changed, 677 insertions(+), 136 deletions(-) diff --git a/apps/app/e2e/shell/editor-references.spec.ts b/apps/app/e2e/shell/editor-references.spec.ts index 4934fd7e..86ce870a 100644 --- a/apps/app/e2e/shell/editor-references.spec.ts +++ b/apps/app/e2e/shell/editor-references.spec.ts @@ -168,15 +168,24 @@ test.describe('reference tiles, edit mode', () => { const url = tile.getByLabel(dict['editor.reference.url']) await url.fill('exemple.org') await tile - .getByRole('button', { name: dict['editor.references.done'] }) + .getByRole('button', { + name: dict['editor.references.done'], + exact: true, + }) .click() await expect(url).toBeFocused() await expect( - tile.getByRole('button', { name: dict['editor.references.done'] }), + tile.getByRole('button', { + name: dict['editor.references.done'], + exact: true, + }), ).toBeVisible() await url.fill('https://exemple.org/page') await tile - .getByRole('button', { name: dict['editor.references.done'] }) + .getByRole('button', { + name: dict['editor.references.done'], + exact: true, + }) .click() await expect(tile.getByLabel(dict['editor.reference.url'])).toHaveCount(0) await expect( @@ -338,9 +347,8 @@ test.describe('reference tiles, search, sort and add', () => { // No result, then the notice's own clear button. await bar.search.fill('radiographie') - const notice = libraryRoot(page).getByRole('status').filter({ - hasText: 'radiographie', - }) + const notice = libraryRoot(page).getByTestId('editor-references-no-result') + await expect(notice).toContainText('radiographie') await expect(notice).toContainText('Aucune référence ne contient') await expectAccessible(page, 'the no result notice') await notice diff --git a/apps/app/src/components/editor/EditorTabs.tsx b/apps/app/src/components/editor/EditorTabs.tsx index fb6ec0c5..84840fd1 100644 --- a/apps/app/src/components/editor/EditorTabs.tsx +++ b/apps/app/src/components/editor/EditorTabs.tsx @@ -40,10 +40,13 @@ function ErrorCount({ tab }: { tab: EditorTabId }) { ) } +/** Answers false when the change was refused (a field of the open panel refused to apply). */ +type SelectTab = (tab: EditorTabId) => boolean | void + interface TabListProps { shown: readonly EditorTabId[] active: EditorTabId - onSelect: (tab: EditorTabId) => void + onSelect: SelectTab } /** The tablist proper: the shown tabs only, arrows move between them. */ @@ -56,7 +59,7 @@ function TabList({ shown, active, onSelect }: TabListProps) { if (step === 0 || at < 0) return event.preventDefault() const next = shown[(at + step + shown.length) % shown.length] - onSelect(next) + if (onSelect(next) === false) return document.getElementById(tabDomId(next))?.focus() } return ( @@ -89,7 +92,7 @@ function TabList({ shown, active, onSelect }: TabListProps) { interface MoreTabsProps { more: readonly EditorTabId[] active: EditorTabId - onSelect: (tab: EditorTabId) => void + onSelect: SelectTab } /** @@ -164,7 +167,7 @@ function MoreTabs({ more, active, onSelect }: MoreTabsProps) { interface EditorTabsProps { active: EditorTabId tier: TabTier - onSelect: (tab: EditorTabId) => void + onSelect: SelectTab } /** diff --git a/apps/app/src/components/editor/references/CitationsPanel.tsx b/apps/app/src/components/editor/references/CitationsPanel.tsx index f3837832..ac36c732 100644 --- a/apps/app/src/components/editor/references/CitationsPanel.tsx +++ b/apps/app/src/components/editor/references/CitationsPanel.tsx @@ -168,6 +168,7 @@ function EntryTile({ done: tiles.finish, goTo: (target) => navigate(targetOfKey(target)), registerLeave: tiles.registerLeave, + takeFocus: () => tiles.takeFocus(key), }} /> ) @@ -176,7 +177,11 @@ function EntryTile({ /** The cited references as tiles, the dangling ids as rows. */ function Entries({ panel, props }: { panel: Panel; props: Props }) { return ( -