diff --git a/.changeset/35876-list-header-menu-multi-sort.md b/.changeset/35876-list-header-menu-multi-sort.md new file mode 100644 index 00000000000..ec11c9be232 --- /dev/null +++ b/.changeset/35876-list-header-menu-multi-sort.md @@ -0,0 +1,17 @@ +--- +'@object-ui/components': patch +'@object-ui/plugin-grid': patch +'@object-ui/plugin-list': patch +'@object-ui/i18n': patch +--- + +fix(plugin-list): a list's column header opens a menu and keeps a multi-level sort; a sort chip opens the sort panel + +Clause-②: yes (widening) +Metadata-protocol: none + +On a list page (the grid `ListView` draws), a click on a column header no longer sorts at once. It opens the column menu: sort ascending, sort descending, hide the column (a column that does not sort offers hide alone). Enter, Space or ArrowDown on the focused header opens the same menu, the arrows move through it, Enter chooses, and Esc shuts it without touching the sort. With no sort or a single level, the column picked in the menu replaces the sort; with two levels or more it becomes the first level, the other levels keep their order after it, and a column already in the sort moves up with the picked direction. No level is dropped. The ↑1 / ↓2 marks on the headers are unchanged. + +A sort chip under the view bar no longer reverses its direction on a click: it opens every sort level in one panel. Each level row in the sort builder now has a handle; dragging it, or ArrowUp / ArrowDown on the focused handle, reorders the levels. + +New public surface, all additive: `GridHeaderMenuProvider` and `useGridHeaderMenu` from `@object-ui/components` (a host opts a data-table into the header menu; without it a header click sorts as before, so related lists, dashboard tables and every other host keep click-to-sort); the `headerMenu` runtime prop on `ObjectGrid`; and the `sortBuilder.reorder` key in every `@object-ui/i18n` locale. The column menu itself is now a menu (`role="menu"` entries, keyboard reachable) wherever it opens, including a right-click on a header and the design host's caret. diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index 31d1c45621c..788cd62026b 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -111,6 +111,27 @@ is no top-level `sortable` switch. } ``` +A click on a sortable column header sorts by that column; another click on it +changes the direction. + +**On an object's list page** the header opens a menu instead +(objectstack#35876), which its host turns on (the `headerMenu` component +prop, not a schema key): **Sort ascending**, **Sort descending** and **Hide +column**. A column that does not sort offers **Hide column** alone. The +header itself never changes the sort. Enter, Space or ArrowDown +on the focused header opens the same menu; the arrows move through it, Enter +chooses and Escape closes it without touching the sort. + +- With no sort, or a single level, the column picked in the menu replaces the + sort. +- With two levels or more it becomes the first level and every other level + keeps its place after it; a column already in the sort moves up with the + picked direction. No level is dropped. +- The ↑1 / ↓2 marks on the headers show each level's place. +- A sort chip under the view bar opens every level in one panel (it does not + reverse the direction). Each level's handle reorders it: drag it to another + row, or press ArrowUp / ArrowDown on the focused handle. + ### Filtering and search There is no per-column filter key and no top-level `filterable` switch. A grid diff --git a/ui/e2e/list-condition-row-35549.spec.ts b/ui/e2e/list-condition-row-35549.spec.ts index d11f59615db..79ca8e8900c 100644 --- a/ui/e2e/list-condition-row-35549.spec.ts +++ b/ui/e2e/list-condition-row-35549.spec.ts @@ -318,7 +318,7 @@ test.describe('list condition row under the view bar (objectstack#35549, objects expect(await slotHeight(page)).toBe(0); }); - test('sort: Sort → Descending → Amount is three clicks; chips come before filter chips; a drag reorders; a header click shows as a chip; Reset restores', async ({ page }) => { + test('sort: Sort → Descending → Amount is three clicks; chips come before filter chips; a drag reorders; a handle in a chip panel reorders; a header menu pick shows as a chip; Reset restores', async ({ page }) => { test.setTimeout(120_000); await mount(page); await expect.poll(() => count(page)).toBe('12'); @@ -326,8 +326,8 @@ test.describe('list condition row under the view bar (objectstack#35549, objects await click(page, 'sort-panel-order-desc'); await click(page, 'sort-panel-fields-item-amount'); expect(await sortNow(page)).toEqual(['amount:desc']); - await expect(page.getByTestId('sort-chip-toggle-amount')).toHaveText('Amount'); - await expect(page.getByTestId('sort-chip-toggle-amount')).toHaveAttribute('title', 'High → Low'); + await expect(page.getByTestId('sort-chip-open-amount')).toHaveText('Amount'); + await expect(page.getByTestId('sort-chip-open-amount')).toHaveAttribute('title', 'High → Low'); // a second level await click(page, 'toolbar-sort-trigger'); await click(page, 'sort-panel-fields-item-stage'); @@ -354,15 +354,30 @@ test.describe('list condition row under the view bar (objectstack#35549, objects // a real drag: the second sort chip onto the first await page.getByTestId('sort-chip-stage').dragTo(page.getByTestId('sort-chip-amount')); expect(await sortNow(page)).toEqual(['stage:asc', 'amount:desc']); + // a chip opens every level in one panel (objectstack#35876); a real drag of + // the second level's handle onto the first row puts it first + await click(page, 'sort-chip-open-stage'); + const panel = page.getByTestId('sort-chip-panel'); + await expect(panel.getByTestId('sort-builder-handle')).toHaveCount(2); + expect(await sortNow(page)).toEqual(['stage:asc', 'amount:desc']); + await panel.getByTestId('sort-builder-handle').nth(1).dragTo(panel.getByTestId('sort-builder-row').first()); + await expect.poll(() => sortNow(page)).toEqual(['amount:desc', 'stage:asc']); + await page.keyboard.press('Escape'); // Reset puts the list back as saved: no sort, no filter await click(page, 'condition-reset'); expect(await sortNow(page)).toEqual([]); await expect.poll(() => count(page)).toBe('12'); expect(await slotHeight(page)).toBe(0); - // a click on a column header sorts, and the row shows it as a chip + // a click on a column header opens its menu and sorts nothing + // (objectstack#35876); the entry chosen there sorts, and the row shows it + // as a chip await page.getByRole('columnheader', { name: /Amount/ }).click(); + const columnMenu = page.getByTestId('column-context-menu'); + await expect(columnMenu).toBeVisible(); + expect(await sortNow(page)).toEqual([]); + await columnMenu.getByRole('menuitem', { name: 'Sort descending' }).click(); await style(page); await expect(page.getByTestId('sort-chip-amount')).toBeVisible(); - expect((await sortNow(page))[0]).toMatch(/^amount:/); + expect(await sortNow(page)).toEqual(['amount:desc']); }); }); diff --git a/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx b/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx index b266f1961a3..f0621a76c42 100644 --- a/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/DataPillar.recordsTab-34794.test.tsx @@ -181,7 +181,7 @@ describe('Data pillar Records tab (objectstack#34794)', () => { const caret = within(header('title')).getByRole('button', { name: COLUMN_MENU }); await userEvent.click(caret); const menu = screen.getByTestId('column-context-menu'); - expect(within(menu).getAllByRole('button')).toHaveLength(3); + expect(within(menu).getAllByRole('menuitem')).toHaveLength(3); // The caret's click selected nothing else and did not sort either. expect(firstTitles()).toEqual(before); }); diff --git a/ui/packages/components/src/__tests__/clickableNonControlCensus-13461.test.ts b/ui/packages/components/src/__tests__/clickableNonControlCensus-13461.test.ts index 142d69c6fa1..e756c43f15f 100644 --- a/ui/packages/components/src/__tests__/clickableNonControlCensus-13461.test.ts +++ b/ui/packages/components/src/__tests__/clickableNonControlCensus-13461.test.ts @@ -235,8 +235,6 @@ const NOT_CONTROLS: Array<[file: string, key: string, reason: string]> = [ ['packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx', 'div · setRailOpen', SCRIM], ['packages/app-shell/src/views/studio-design/StudioRightSlot.tsx', 'div · onOverlayDismiss', SCRIM], ['packages/components/src/renderers/complex/data-table.tsx', 'div · stopPropagation', DRAG], - // The column header's context menu: its entries are buttons. - ['packages/components/src/renderers/complex/data-table.tsx', 'div · stopPropagation', GUARD], ['packages/plugin-dashboard/src/DashboardRenderer.tsx', 'div · handleBackgroundClick', CANVAS], ['packages/plugin-dashboard/src/DashboardRenderer.tsx', 'div · handleBackgroundClick', CANVAS], ['packages/plugin-designer/src/ProcessDesigner.tsx', 'div · handleCanvasClick', CANVAS], diff --git a/ui/packages/components/src/__tests__/list-builders-phone-width-29074.test.tsx b/ui/packages/components/src/__tests__/list-builders-phone-width-29074.test.tsx index c496cf8c7c9..62b29d95eae 100644 --- a/ui/packages/components/src/__tests__/list-builders-phone-width-29074.test.tsx +++ b/ui/packages/components/src/__tests__/list-builders-phone-width-29074.test.tsx @@ -42,14 +42,15 @@ describe('SortBuilder below sm (objectstack#29057)', () => { ); } - it('lays a level out on three lines: the words, the field beside Remove, the direction', () => { + it('lays a level out on three lines: the words, the field beside Remove, the direction; the drag handle beside all three (objectstack#35876)', () => { mount(); const row = screen.getByTestId('sort-builder-row'); - expect(tokens(row)).toEqual(expect.arrayContaining(['flex', 'max-sm:grid', 'max-sm:grid-cols-[minmax(0,1fr)_auto]'])); + expect(tokens(row)).toEqual(expect.arrayContaining(['flex', 'max-sm:grid', 'max-sm:grid-cols-[auto_minmax(0,1fr)_auto]'])); + expect(tokens(screen.getByTestId('sort-builder-handle'))).toEqual(expect.arrayContaining(['max-sm:col-start-1', 'max-sm:row-span-3'])); const field = screen.getByTestId('sort-builder-field').parentElement!; expect(tokens(field)).toEqual(expect.arrayContaining(['flex-1', 'max-sm:row-start-2'])); const direction = screen.getByTestId('sort-builder-direction').parentElement!; - expect(tokens(direction)).toEqual(expect.arrayContaining(['w-36', 'max-sm:col-span-2', 'max-sm:row-start-3', 'max-sm:w-auto'])); + expect(tokens(direction)).toEqual(expect.arrayContaining(['w-36', 'max-sm:col-start-2', 'max-sm:col-span-2', 'max-sm:row-start-3', 'max-sm:w-auto'])); }); it('every control is 44 px below sm and keeps its desktop size', () => { diff --git a/ui/packages/components/src/__tests__/sort-builder-disabled-entry-11943.test.tsx b/ui/packages/components/src/__tests__/sort-builder-disabled-entry-11943.test.tsx index 2f5db5fc876..8a9fb337cf5 100644 --- a/ui/packages/components/src/__tests__/sort-builder-disabled-entry-11943.test.tsx +++ b/ui/packages/components/src/__tests__/sort-builder-disabled-entry-11943.test.tsx @@ -160,11 +160,11 @@ describe('SortBuilder honours `disabled` on a fields entry (objectui#11943)', () expect(onChange).toHaveBeenLastCalledWith([asc('title'), asc('status')]); expect(fieldTriggers()[0]).toHaveTextContent('Title'); - // Removed: the row's only button is its remove control. + // Removed: the row's remove control. cleanup(); onChange = mount(FLAGGED, [asc('secret'), asc('status')]); const row = screen.getByText('Sort by').parentElement as HTMLElement; - fireEvent.click(within(row).getByRole('button')); + fireEvent.click(within(row).getByRole('button', { name: /remove sort/i })); expect(onChange).toHaveBeenLastCalledWith([asc('status')]); }); diff --git a/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx b/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx new file mode 100644 index 00000000000..ce1aba0010d --- /dev/null +++ b/ui/packages/components/src/__tests__/sort-builder-reorder-35876.test.tsx @@ -0,0 +1,109 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#35876 — the order of the sort levels is the sort's priority, + * and each level's handle changes it: a drag onto another row, or ArrowUp / + * ArrowDown on the focused handle. A single level has nothing to reorder. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import React from 'react'; +import { cleanup, render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { SortBuilder, type SortItem } from '../custom/sort-builder'; + +const FIELDS = [ + { value: 'name', label: 'Name' }, + { value: 'stage', label: 'Stage' }, + { value: 'amount', label: 'Amount' }, +]; +const THREE: SortItem[] = [ + { id: 'a', field: 'name', order: 'asc' }, + { id: 'b', field: 'stage', order: 'desc' }, + { id: 'c', field: 'amount', order: 'asc' }, +]; + +afterEach(cleanup); + +/** The builder under a host that keeps what it hands back, as a list does. */ +function mount(initial: SortItem[]) { + const onChange = vi.fn(); + function Host() { + const [value, setValue] = React.useState(initial); + return ( + { + onChange(next); + setValue(next); + }} + /> + ); + } + render(); + return onChange; +} +const fieldsOf = (items: SortItem[]) => items.map((i) => `${i.field}:${i.order}`); + +describe('SortBuilder — reordering the levels (objectstack#35876)', () => { + it('every level has a named handle: a keyboard control that is not a + {(() => { + const chipKey = `sort:${item.id}`; + const chipButton = ( + + ); + // objectstack#35876 — the chip opens every sort level in one + // panel; it does not flip the direction. + return ( + setOpenChip(open ? chipKey : null)}> + {chipButton} + +
+ {renderSortLevels()} +
+
+
+ ); + })()}