From ff21b0315ecdb4391da617d76df8cfee760b3e9f Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 15 Nov 2026 15:52:28 +0100 Subject: [PATCH] feat(editor): one tab order, vertical Plus list with the error count --- apps/app/e2e/shell/editor-more-menu.spec.ts | 39 ++++++++++++- apps/app/e2e/support/editor.ts | 57 +++++++++---------- apps/app/src/components/editor/EditorTabs.tsx | 33 ++++++++--- .../src/components/editor/EditorWorkspace.tsx | 10 +--- apps/app/src/editor/tabs.ts | 11 ++-- .../app/tests/unit/editor-initial-tab.test.ts | 8 +-- apps/app/tests/unit/editor-mode.test.ts | 4 +- apps/app/tests/unit/editor-more-menu.test.tsx | 30 ++++++++-- apps/app/tests/unit/editor-no-loss.test.tsx | 7 ++- apps/app/tests/unit/editor-route.test.tsx | 8 +-- .../app/tests/unit/editor-tabs-badge.test.tsx | 23 +++++++- 11 files changed, 155 insertions(+), 75 deletions(-) diff --git a/apps/app/e2e/shell/editor-more-menu.spec.ts b/apps/app/e2e/shell/editor-more-menu.spec.ts index 69e7f376..41b82586 100644 --- a/apps/app/e2e/shell/editor-more-menu.spec.ts +++ b/apps/app/e2e/shell/editor-more-menu.spec.ts @@ -12,6 +12,7 @@ import { draftPath, draftTitle, editorActor, + morePlus, pointOf, seedDraft, shapeWith, @@ -40,8 +41,7 @@ async function openAt(page: Page, width: number, height = 800) { ).toBeVisible() } -const more = (page: Page) => - page.getByRole('button', { name: dict['editor.tab.more'], exact: true }) +const more = (page: Page) => morePlus(page, dict) const list = (page: Page) => page.locator('#editor-tabs-more') /** The boxes that must not move when « Plus » opens: the row, the page below it, the document. */ @@ -90,6 +90,41 @@ test.describe('« Plus » dropdown', () => { }) } + for (const width of [375, 320]) { + test(`at ${width} px the entries stack in tab order inside the viewport`, async ({ + page, + }) => { + await openAt(page, width) + await expect(page.getByRole('tablist').getByRole('tab')).toHaveText([ + dict['editor.tab.general'], + dict['editor.tab.annotations'], + ]) + await more(page).click() + const rows = list(page).getByRole('button') + await expect(rows).toHaveCount(3) + // Vérification may carry its error count. + await expect(rows).toHaveText([ + dict['editor.tab.findings'], + dict['editor.tab.references'], + new RegExp(`^${dict['editor.tab.verification']}`), + ]) + const boxes = await rows.evaluateAll((els) => + els.map((el) => el.getBoundingClientRect().toJSON()), + ) + boxes.forEach((box, at) => { + expect(box.height, `row ${at} height`).toBeGreaterThanOrEqual(44) + expect(box.x, `row ${at} left`).toBeGreaterThanOrEqual(0) + expect(box.right, `row ${at} right`).toBeLessThanOrEqual(width) + if (at > 0) { + expect(box.y, `row ${at} below`).toBeGreaterThanOrEqual( + boxes[at - 1].bottom, + ) + } + }) + await expectAccessible(page, `« Plus » list at ${width} px`) + }) + } + test('closes on a selection, outside tap and Escape, focus kept sane', async ({ page, }) => { diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts index 4c4eb329..e4e53f0e 100644 --- a/apps/app/e2e/support/editor.ts +++ b/apps/app/e2e/support/editor.ts @@ -345,13 +345,34 @@ export const TABS = [ /** The Annotations sections and the panel, in the order the overview offers them. */ export const SECTIONS = ['views', 'categories', 'regions'] as const +/** Below this width only the tabs of SHOWN_SMALL stay in the row, the others sit under « Plus ». */ +const SMALL_TIER_WIDTH = 640 +const SHOWN_SMALL = ['general', 'annotations'] + /** - * Clicks a tab by role. The name is a pattern: the Vérification tab adds « n erreur(s) » - * to its name while the in-page check has errors. + * Clicks a tab by role, whatever the width: from 640 px the tab button, below it « Plus » + * opened and the tab picked in its list. The name is a pattern: the Vérification tab adds + * « n erreur(s) » to its name while the in-page check has errors. */ export async function selectTab(page: Page, dict: Dict, tab: string) { - const name = dict[`editor.tab.${tab}`] - await page.getByRole('tab', { name: new RegExp(`^${name}( |$)`) }).click() + const width = page.viewportSize()?.width ?? SMALL_TIER_WIDTH + const name = new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`) + if (width >= SMALL_TIER_WIDTH || SHOWN_SMALL.includes(tab)) { + await page.getByRole('tab', { name }).click() + return + } + const more = morePlus(page, dict) + if ((await more.getAttribute('aria-expanded')) !== 'true') await more.click() + await page.locator('#editor-tabs-more').getByRole('button', { name }).click() + // The dropdown fades out: wait for it to be gone before the next move. + await expect(page.locator('#editor-tabs-more')).toHaveCount(0) +} + +/** « Plus », located without an exact name: it carries the Vérification error count. */ +export function morePlus(page: Page, dict: Dict): Locator { + return page.getByRole('button', { + name: new RegExp(`^${dict['editor.tab.more']}( |$)`), + }) } /** The visible place with this `data-place` name; a hidden copy never answers. */ @@ -395,34 +416,12 @@ export function libraryRoot(page: Page): Locator { return place(page, 'references') } -/** Below this width the tabs other than Annotations and Vérification sit under « Plus ». */ -const SMALL_TIER_WIDTH = 640 - /** - * Shows a tab whatever the width: the tab button from 640 px, below it « Plus » opened and - * the tab picked in its list. Waits for the tab's place to be visible (Annotations names - * its sections, so any of them). + * Shows a tab whatever the width (selectTab). Waits for the tab's place to be visible + * (Annotations names its sections, so any of them). */ export async function openTab(page: Page, dict: Dict, tab: string) { - const width = page.viewportSize()?.width ?? SMALL_TIER_WIDTH - const name = new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`) - const listed = ['annotations', 'verification'].includes(tab) - if (width < SMALL_TIER_WIDTH && !listed) { - const more = page.getByRole('button', { - name: dict['editor.tab.more'], - exact: true, - }) - if ((await more.getAttribute('aria-expanded')) !== 'true') - await more.click() - await page - .locator('#editor-tabs-more') - .getByRole('button', { name }) - .click() - // The dropdown fades out: wait for it to be gone before the next move. - await expect(page.locator('#editor-tabs-more')).toHaveCount(0) - } else { - await page.getByRole('tab', { name }).click() - } + await selectTab(page, dict, tab) await expect( tab === 'annotations' ? page.locator('[data-place^=annotations]:visible').first() diff --git a/apps/app/src/components/editor/EditorTabs.tsx b/apps/app/src/components/editor/EditorTabs.tsx index 85c60993..eb4d2096 100644 --- a/apps/app/src/components/editor/EditorTabs.tsx +++ b/apps/app/src/components/editor/EditorTabs.tsx @@ -15,6 +15,7 @@ import { type EditorTabId, } from '@/editor/tabs' import type { TabTier } from '@/editor/useViewport' +import Icon from '@/components/ui/Icon' import { useT } from '@/i18n/useT' import HistoryButtons from './HistoryButtons' import { MORE_LIST_ID, useMoreDismiss, useMoreMenu } from './useMoreMenu' @@ -26,15 +27,25 @@ const ACTIVE = const IDLE = 'border-transparent text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]' +const ROW = + 'flex min-h-12 w-full items-center justify-between gap-3 rounded-md px-4 text-left text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]' +const ROW_ACTIVE = + 'bg-[var(--color-accent)]/10 font-medium text-[var(--color-accent-strong)]' + /** The blocking-error count on the Vérification tab, as text; absent at zero. */ function ErrorCount({ tab }: { tab: EditorTabId }) { + return tab === 'verification' ? : null +} + +/** The count badge itself; also shown on « Plus » while Vérification sits under it. */ +function ErrorBadge() { const plural = usePlural() const count = useEditorStore( (s) => s.previewState?.report.issues.filter((i) => i.severity === 'error') .length ?? 0, ) - if (tab !== 'verification' || count === 0) return null + if (count === 0) return null return ( <> {' '} @@ -127,19 +138,22 @@ function MoreList({ more, active, onPick }: MoreListProps) { transition: { duration: reduced ? 0 : 0.15 }, }} exit={{ ...hidden, transition: { duration: reduced ? 0 : 0.12 } }} - className="absolute inset-x-0 top-full z-20 flex flex-wrap gap-1 border border-[var(--color-border)] bg-[var(--color-surface)] p-1 shadow-md" + className="absolute inset-x-0 top-full z-20 mt-1 flex flex-col gap-1 rounded-lg border border-[var(--color-border)] bg-[var(--color-surface)] p-2 shadow-lg" > {more.map((tab) => (
  • ))} @@ -169,7 +183,7 @@ function usePanelPick( } } -/** Below 640 px: « Plus » and its dropdown of the tabs that do not fit. */ +/** Below 640 px: « Plus » (with the Vérification count) and its list of the other tabs. */ function MoreTabs({ more, active, onSelect }: MoreTabsProps) { const t = useT() const { open, close, toggle } = useMoreMenu(active) @@ -186,6 +200,7 @@ function MoreTabs({ more, active, onSelect }: MoreTabsProps) { className={`-mb-px ${BASE} ${more.includes(active) ? ACTIVE : IDLE}`} > {t('editor.tab.more')} + {more.includes('verification') && } {open && } @@ -202,8 +217,8 @@ interface EditorTabsProps { /** * The draft's tab row (boards 04 and 05): the five tabs from 640 px (the row may wrap - * between 640 and 1 023 px, never scroll sideways), Annotations and - * Vérification below it with « Plus » opening a dropdown overlay of the others (no measurement). + * between 640 and 1 023 px, never scroll sideways), Général and Annotations below it with + * « Plus » opening a vertical dropdown overlay of the others, in the same order (no measurement). * « Défaire » and « Refaire » sit at the right end of the row on every tab. */ export default function EditorTabs({ diff --git a/apps/app/src/components/editor/EditorWorkspace.tsx b/apps/app/src/components/editor/EditorWorkspace.tsx index dfd8f4a4..7edf5c0f 100644 --- a/apps/app/src/components/editor/EditorWorkspace.tsx +++ b/apps/app/src/components/editor/EditorWorkspace.tsx @@ -187,9 +187,9 @@ function useShowRestored(nav: EditorNavigation) { * confirmation before a history jump leaves with a dirty dialog, and whether the last * editor left a dirty dialog behind. */ -function useWorkspaceNavigation(sheetId: string, tier: TabTier, who: Who) { +function useWorkspaceNavigation(sheetId: string, who: Who) { const previewState = useEditorStore((s) => s.previewState) - const tab = previewState ? initialTab(previewState, tier) : 'annotations' + const tab = previewState ? initialTab(previewState) : 'annotations' const owner = useOwner(sheetId, who.tag) const nav = useEditorNavigation(tab, useRestoredView(owner)) useEditorHistory(nav, owner, defaultView(tab)) @@ -212,11 +212,7 @@ function LeftDraftNotice({ shown }: { shown: boolean }) { */ function Workspace(props: Props & Who) { const { sheet, mode, readOnly } = props - const { nav, left } = useWorkspaceNavigation( - sheet.sheet_id, - props.tier, - props, - ) + const { nav, left } = useWorkspaceNavigation(sheet.sheet_id, props) return (
    diff --git a/apps/app/src/editor/tabs.ts b/apps/app/src/editor/tabs.ts index 9b7aa5df..05deece2 100644 --- a/apps/app/src/editor/tabs.ts +++ b/apps/app/src/editor/tabs.ts @@ -14,11 +14,11 @@ export const EDITOR_TABS = [ ] as const export type EditorTabId = (typeof EDITOR_TABS)[number] -/** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */ +/** The tabs shown beside « Plus » at each width; the rest sit under « Plus », in tab order. */ const SHOWN: Record = { wide: EDITOR_TABS, medium: EDITOR_TABS, - small: ['annotations', 'verification'], + small: ['general', 'annotations'], } export function tabsFor(tier: TabTier): { @@ -31,13 +31,12 @@ export function tabsFor(tier: TabTier): { /** * The tab a version opens on: Annotations once a view can be annotated, Général while - * there is nothing to annotate yet. A tier that does not list Général keeps Annotations. + * there is nothing to annotate yet. Both are shown at every width. */ -export function initialTab(state: PreviewState, tier: TabTier): EditorTabId { +export function initialTab(state: PreviewState): EditorTabId { const unmeasured = unmeasuredViews(state) const measurable = state.document.views.some((v) => !unmeasured.has(v.id)) - const wanted = measurable ? 'annotations' : 'general' - return SHOWN[tier].includes(wanted) ? wanted : 'annotations' + return measurable ? 'annotations' : 'general' } /** diff --git a/apps/app/tests/unit/editor-initial-tab.test.ts b/apps/app/tests/unit/editor-initial-tab.test.ts index 78607eca..aef4b595 100644 --- a/apps/app/tests/unit/editor-initial-tab.test.ts +++ b/apps/app/tests/unit/editor-initial-tab.test.ts @@ -28,14 +28,10 @@ async function stateOf(text: string) { describe('initialTab', () => { it('opens an empty new draft on Général', async () => { - expect(initialTab(await stateOf(emptyText()), 'wide')).toBe('general') + expect(initialTab(await stateOf(emptyText()))).toBe('general') }) it('opens a draft with a measured view on Annotations', async () => { - expect(initialTab(await stateOf(baseText()), 'wide')).toBe('annotations') - }) - - it('keeps Annotations on a tier that does not list Général', async () => { - expect(initialTab(await stateOf(emptyText()), 'small')).toBe('annotations') + expect(initialTab(await stateOf(baseText()))).toBe('annotations') }) }) diff --git a/apps/app/tests/unit/editor-mode.test.ts b/apps/app/tests/unit/editor-mode.test.ts index 69bc2df0..c177b470 100644 --- a/apps/app/tests/unit/editor-mode.test.ts +++ b/apps/app/tests/unit/editor-mode.test.ts @@ -106,11 +106,11 @@ describe('tabsFor', () => { 'references', 'verification', ]) - expect(tabsFor('small').shown).toEqual(['annotations', 'verification']) + expect(tabsFor('small').shown).toEqual(['general', 'annotations']) expect(tabsFor('small').more).toEqual([ - 'general', 'findings', 'references', + 'verification', ]) }) }) diff --git a/apps/app/tests/unit/editor-more-menu.test.tsx b/apps/app/tests/unit/editor-more-menu.test.tsx index d9c0ad4d..78824f5f 100644 --- a/apps/app/tests/unit/editor-more-menu.test.tsx +++ b/apps/app/tests/unit/editor-more-menu.test.tsx @@ -49,7 +49,7 @@ function Page({ />
    - @@ -92,11 +92,33 @@ describe('the overlay', () => { expect(more()).toHaveAttribute('aria-expanded', 'false') await gone() await user.click(more()) - await user.click(screen.getByRole('tab', { name: 'Vérification' })) + await user.click(screen.getByRole('tab', { name: 'Général' })) expect(more()).toHaveAttribute('aria-expanded', 'false') }) }) +describe('the vertical list', () => { + it('stacks the entries in tab order, the active one marked', async () => { + const { user } = mount() + await user.click(more()) + expect(list()).toHaveClass('flex-col') + const rows = [...list()!.querySelectorAll('button')] + expect(rows.map((row) => row.id)).toEqual([ + 'editor-tab-findings', + 'editor-tab-references', + 'editor-tab-verification', + ]) + expect(list()!.querySelector('[aria-current]')).toBeNull() + rows.forEach((row) => expect(row).toHaveClass('min-h-12', 'w-full')) + await user.click(rows[0]) + await user.click(more()) + const current = list()!.querySelectorAll('[aria-current="true"]') + expect(current).toHaveLength(1) + expect(current[0].id).toBe('editor-tab-findings') + expect(current[0].querySelector('svg')).not.toBeNull() + }) +}) + describe('the panel takes the focus after a pick', () => { it('Enter on an entry focuses the panel of that tab once the list is gone', async () => { const { user } = mount() @@ -184,8 +206,8 @@ describe('outside presses', () => { it('a press inside the row closes the menu and goes on to act', async () => { const { user } = mount() await user.click(more()) - await user.click(screen.getByRole('tab', { name: 'Vérification' })) - expect(screen.getByRole('tab', { name: 'Vérification' })).toHaveAttribute( + await user.click(screen.getByRole('tab', { name: 'Général' })) + expect(screen.getByRole('tab', { name: 'Général' })).toHaveAttribute( 'aria-selected', 'true', ) diff --git a/apps/app/tests/unit/editor-no-loss.test.tsx b/apps/app/tests/unit/editor-no-loss.test.tsx index 6f7c29ef..d0a313db 100644 --- a/apps/app/tests/unit/editor-no-loss.test.tsx +++ b/apps/app/tests/unit/editor-no-loss.test.tsx @@ -256,10 +256,11 @@ describe('the guards of a width change', () => { expect(document.activeElement).toBe(tab('Général')) }) - it('the focus of a typed field goes to « Plus » when the shown tab left the row', async () => { + it('the focus of an editing control goes to « Plus » when the shown tab left the row', async () => { const user = await mount() - await user.click(tab('Général')) - await user.click(byId('general-name-fr')) + await user.click(tab('Références')) + const add = button('Ajouter une référence') + act(() => add.focus()) cross(500) expect(document.activeElement).toBe(button('Plus')) }) diff --git a/apps/app/tests/unit/editor-route.test.tsx b/apps/app/tests/unit/editor-route.test.tsx index d38f11cc..ed8405e0 100644 --- a/apps/app/tests/unit/editor-route.test.tsx +++ b/apps/app/tests/unit/editor-route.test.tsx @@ -155,24 +155,24 @@ describe('tabs', () => { expect(screen.queryByRole('button', { name: 'Plus' })).toBeNull() }) - it('below 640 px: two tabs and « Plus » listing Général, Constats and Références', async () => { + it('below 640 px: two tabs and « Plus » listing Constats, Références and Vérification', async () => { const user = userEvent.setup() mountDraft({ width: 375 }) await ready() const shown = within(screen.getByRole('tablist')).getAllByRole('tab') expect(shown.map((tab) => tab.textContent)).toEqual([ + 'Général', 'Annotations', - 'Vérification', ]) await user.click(screen.getByRole('button', { name: 'Plus' })) const more = document.getElementById('editor-tabs-more') as HTMLElement const rest = within(more).getAllByRole('button') expect(rest.map((b) => b.textContent)).toEqual([ - 'Général', 'Constats', 'Références', + 'Vérification', ]) - await user.click(rest[1]) + await user.click(rest[0]) expect(screen.getByTestId('editor-tab-findings')).toBeInTheDocument() await waitFor(() => expect(document.getElementById('editor-tabs-more')).toBeNull(), diff --git a/apps/app/tests/unit/editor-tabs-badge.test.tsx b/apps/app/tests/unit/editor-tabs-badge.test.tsx index ef55b7bb..64fb4164 100644 --- a/apps/app/tests/unit/editor-tabs-badge.test.tsx +++ b/apps/app/tests/unit/editor-tabs-badge.test.tsx @@ -51,9 +51,7 @@ describe('the Vérification tab badge', () => { ])('says « n erreur(s) » for %i blocking error(s)', async (count, name) => { await openReady() render() - reportIssues( - Array.from({ length: count }, (_, at) => issue('error', at)), - ) + reportIssues(Array.from({ length: count }, (_, at) => issue('error', at))) expect(verificationTab()).toHaveTextContent(new RegExp(`^${name}$`)) }) @@ -76,3 +74,22 @@ describe('the Vérification tab badge', () => { ) }) }) + +describe('« Plus » carries the count while Vérification sits under it', () => { + const plus = () => screen.getByRole('button', { name: /^Plus/ }) + + it('shows the count at the small tier, nothing at zero', async () => { + await openReady() + render() + reportIssues([]) + expect(plus()).toHaveTextContent(/^Plus$/) + reportIssues([issue('error', 0), issue('error', 1)]) + expect(plus()).toHaveTextContent(/^Plus 2 erreurs$/) + }) + + it('wide rows have no Plus button', async () => { + await openReady() + render() + expect(screen.queryByRole('button', { name: /^Plus/ })).toBeNull() + }) +})