diff --git a/.changeset/35684-35687-list-cells-select-first.md b/.changeset/35684-35687-list-cells-select-first.md new file mode 100644 index 00000000000..2c09483711c --- /dev/null +++ b/.changeset/35684-35687-list-cells-select-first.md @@ -0,0 +1,31 @@ +--- +'@object-ui/components': minor +'@object-ui/core': minor +'@object-ui/plugin-grid': minor +'@object-ui/plugin-list': minor +'@object-ui/i18n': patch +'@object-ui/app-shell': patch +--- + +feat(list): a list's cells are selected by a click and edited by a double-click, Enter or typing, with no inline-edit toggle + +Clause-②: yes (widening) +Metadata-protocol: semantic +Skills-docs: none — `skills/objectstack-ui/rules/list-views.md` already teaches that inline editing is on by default for a user who may update the object, with `userActions: { editInline: false }` as the opt-out, which the list page now does with no toggle; no skill teaches the toggle or a single-click edit. + +**The list page (`ListView`) has no inline-edit mode and no toggle.** Its grid is editable in place wherever the reader may update the object and the view does not declare `userActions.editInline: false`; a view's boolean `inlineEdit` still folds into that switch, so `inlineEdit: false` reads off and `inlineEdit: true` reads on. Before, a view that declared neither opened read-only with an "Edit inline" toggle in the toolbar and in the Display menu, the mode lasted for the session, and a click on a cell edited it. Both toggles are gone, and `ListViewProps.onInlineEditChange` is deprecated and never called; the console stops passing it. + +**The select-first cell model** (`data-table`, behind the new `GridCellSelectionProvider` in `@object-ui/components`; `ObjectGrid` mounts it when its host passes the new `cellSelection` prop, and `ListView` passes it for every `object-grid` view it draws, on the hosts listed below): + +- A click selects a cell (a ring around it) and neither edits it nor opens the record. A link the cell draws (the name, a lookup, a phone or an email) keeps its own click. A touch tap opens the record and never edits in place. +- Double-click, Enter or F2 edits, keeping the value with the caret at its end; typing a character replaces the value with it (a picker or a date opens instead); Backspace or Delete opens an empty editor and saves nothing. +- While editing, Enter commits and moves down, Tab and Shift+Tab commit and move right and left, Escape cancels and keeps the cell selected; in a multi-line editor Enter is a new line and Ctrl/Cmd+Enter commits. Commits are the grid's staged edits, saved by the row's Save and Save All as before. +- On the selected cell the arrows and Tab move the selection, Space opens the record (a checkbox cell flips and commits instead, as a second click on it does), Ctrl/Cmd+C copies, Ctrl/Cmd+V converts the text to the field's type and commits it, and Escape clears the selection. +- An input method's composition is kept whole: keys pressed while composing, and the 229 Enter Safari raises after it, never commit, cancel or move, and a composition started on a selected cell opens the editor with the composed text. This guard applies to every `data-table` editor. +- A cell that opens no editor says why on the cell: the field is read-only, calculated or not editable in a list, the reader may not edit the field, these records or this record, the view turned editing off, or the record is locked by an approval. The approval lock is read from the approvals service's per-record lock when a cell of the row is selected, through the record page's rule (`resolveApprovalLock`); until it answers, the row's `approval_status` stands in only where the view fetches that column, which a view that authors its columns does only when a column, a row predicate or a grouping names it. + +Every grid a `ListView` draws has this model, because `ListView` passes `cellSelection` to each `object-grid` view: the console's object list pages, interface list pages, the object data page (`/apps/:app/:object/data`), the Studio Data pillar's records artboard, and every `list-view` block, whether an SDUI page node or a `ListView` on a `kind: 'react'` page; a grid no `ListView` draws mounts no provider and keeps its click-to-edit (`singleClickEdit`) and click-to-open behaviour unchanged: an authored `object-grid` node, `ObjectView`'s own grid (the `object-view` block, or a host that passes no `renderListView`), a related list, a dashboard table, the record picker and the designer's grids. + +On every `ListView` grid (the select-first model) the table's trailing edit column, which holds a changed row's Cancel and Save, is drawn only while a row has changes, so the list at rest ends on its last data column. `@object-ui/core` exports `resolveAffordanceGrant`, the grant half of `resolveAffordance`, which the list cell's read-only reason reads. + +New locale keys, in every pack: `table.cellReadOnly` and `grid.readOnlyReason.*` (nine reasons). No key is removed: `list.inlineEditShort` and `list.inlineEditLabel`, the toggle's words, stay in every pack, though the list no longer draws the toggle. diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index 29c39fb02ea..40d537767d3 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -350,6 +350,38 @@ through the host's data source (`dataSource.update`) with no callback to wire. To own persistence in a React host, supply `onCellChange` as a **component prop** — it is not a schema key. +#### On an object's list page + +The console's list page draws its grid with the **select-first** cell model +(objectstack#35684, objectstack#35687), which its host turns on (the +`cellSelection` component prop, not a schema key). There is no inline-edit +mode and no toggle: the grid is editable wherever the reader may edit the +object and the view does not declare `userActions.editInline: false`, and +`singleClickEdit` is not read there. + +- **A click selects** a cell (a ring around it); it neither edits nor opens the + record. A link a cell draws (the name, a lookup, a phone or an email) keeps + its own click. On a touch screen a tap opens the record. +- **Editing** starts on a double-click, Enter or F2 (the value kept, caret at + its end), or by typing, which replaces the value; an input method's + composition is kept whole. Backspace or Delete opens an empty editor and + saves nothing yet. +- **While editing**, Enter commits and moves down, Tab / Shift+Tab commit and + move right / left, and Escape cancels and keeps the cell selected. In a + multi-line editor Enter is a new line and Ctrl/Cmd+Enter commits. A click + elsewhere commits. +- **Selected cell keys:** the arrows and Tab move the selection; Space opens the + record (a checkbox cell flips instead, as does a second click on it); + Ctrl/Cmd+C copies; Ctrl/Cmd+V converts the text to the field's type and + commits it; Escape clears the selection. +- **A cell that opens no editor says why** on the cell: the field is read-only, + calculated or not editable in a list, the reader may not edit the field, the + object or the record, the view turned editing off, or the record is locked + by an approval. + +Commits are the grid's own staged edits: the row's Save / Cancel and the Save +All bar save them, as before. + ### Keyboard navigation `keyboardNavigation` turns the grid's data cells into one roving Tab stop, on the diff --git a/content/docs/frontend/plugins/plugin-view.mdx b/content/docs/frontend/plugins/plugin-view.mdx index 80501a07684..ffd6dcc3d83 100644 --- a/content/docs/frontend/plugins/plugin-view.mdx +++ b/content/docs/frontend/plugins/plugin-view.mdx @@ -654,29 +654,27 @@ panel offers every field the user may read, minus the fields the object marks **Inline editing on that node is on by default.** Both keys below are the author's permission. `ListView` reads the node's `userActions.editInline` with the spec's default, on since the v18 ruling (objectstack#22605), so a view that -declares neither key offers the inline-edit toggle (objectui#12086), and -`userActions.editInline: false` is how a view withdraws it. When the node -carries no `editInline` of its own, its `inlineEdit` stands in for it -(objectui#5144). The named view's keys win over the host `views` entry's, as -for every member above: +declares neither key is editable in place, and `userActions.editInline: false` +is how a view withdraws it. When the node carries no `editInline` of its own, +its `inlineEdit` stands in for it (objectui#5144). The named view's keys win +over the host `views` entry's, as for every member above: -| The view declares | Inline-edit toggle | Grid opens in edit mode | -| --- | --- | --- | -| neither key | offered | no | -| `inlineEdit: true` | offered | yes | -| `inlineEdit: false` | not offered | no | -| `userActions.editInline: true` | offered | only with `inlineEdit: true` | -| `userActions.editInline: false` | not offered | no, whatever `inlineEdit` says | - -The toggle switches the edit mode for the session and reports it through -`ListView`'s `onInlineEditChange`. The console stores nothing for it: each load -opens in the mode the view's `inlineEdit` declares, so a user's choice is not -remembered across loads. A view where an earlier console stored -`inlineEdit: false` still reads off; that data is not migrated, and declaring -`userActions.editInline: true` brings the toggle back. A list whose records are -read-only by nature declares `userActions.editInline: false`. Neither key opens -editing past the object's own editability or the user's permission to update -the object. +| The view declares | Grid editable in place | +| --- | --- | +| neither key | yes | +| `inlineEdit: true` | yes | +| `inlineEdit: false` | no | +| `userActions.editInline: true` | yes, whatever `inlineEdit` says | +| `userActions.editInline: false` | no, whatever `inlineEdit` says | + +There is no inline-edit mode and no toggle (objectstack#35684): a click selects +a cell and a double-click, Enter or typing edits it (the list page's +select-first model, see the grid's Inline Editing). A view where an earlier +console stored `inlineEdit: false` still reads off; that data is not migrated, +and declaring `userActions.editInline: true` turns editing back on. A list +whose records are read-only by nature declares `userActions.editInline: false`. +Neither key opens editing past the object's own editability or the user's +permission to update the object. ### Update diff --git a/docs/qa/platform-checklist/areas/ux-conventions.json b/docs/qa/platform-checklist/areas/ux-conventions.json index e8c3d2acfee..e1fea4d9173 100644 --- a/docs/qa/platform-checklist/areas/ux-conventions.json +++ b/docs/qa/platform-checklist/areas/ux-conventions.json @@ -9,7 +9,7 @@ "title": "Every user-initiated write answers visibly — success names what changed, a refusal says why, and a no-op claims nothing", "since": "v17.7", "status": "active", - "revision": 13, + "revision": 14, "priority": "P1", "surface": "browser", "personas": [ @@ -32,7 +32,7 @@ }, "variants": [ "record create — New form save on showcase_task", - "record inline edit — on the task object's Grid view (the named view `grid`, labelled 'Grid': the one task list that declares inlineEdit: true, examples/app-showcase/src/ui/views/task.view.ts; the default All Tasks list declares none), double-click a Priority cell (the grid has no 'Edit inline' button), change it, then Save row or Save All", + "record inline edit — on any task list (since #35684 a list is editable in place wherever its reader may edit and its view declares no userActions.editInline: false; there is no 'Edit inline' toggle), double-click a Priority cell (a single click only selects it), change it, then Save row or Save All", "bulk delete — select two rows → Delete in the selection bar → confirm", "kanban move — drag a card Backlog → To Do (direct manipulation: the card in its new column IS the success feedback; a move the transition rule blocks never leaves the client — its lane is dimmed, data-kanban-drop-blocked, and the drop sends nothing, #25933)", "declared record action — Mark Done on a task record (declared successMessage `{{ record.title | default:'Task' }} marked done.`, which names the task, examples/app-showcase/src/ui/actions/index.ts#MarkDoneAction). The action patches only done and progress, so the record's Status still reads its old value (e.g. 'To Do') beside the toast: that is the declaration, not a failed write (QA run #33861)", @@ -183,6 +183,12 @@ "date": "2026-11-15", "change": "steps[1], [2], [5] and variants[4], [6], [8] and [11] re-pointed: the update-mode import's inline result is its feedback (no toast); the settings PUT is outside /api/v1; the import Undo answers with the row's 'Undone' label; Mark Done leaves Status unchanged by declaration; the record title opens the subject record's page, where Approve also sits; Studio autosave needs a record and the column's 'Edit field properties'; and the stock currency is locked (QA run #33861, comment 6894395705, and QA run #33914, comment 6895723718; ledger 6896511848 of #33761 rows 182, 229, 230 and 231). The clauses are unchanged. Read at base 895783a1", "ref": "#33981" + }, + { + "revision": 14, + "date": "2026-11-20", + "change": "variants[1] follows #35684: every task list is editable in place, not only the Grid view that declares inlineEdit: true, and a single click selects a cell while a double-click edits it. The clauses are unchanged. Read at base 238661f4", + "ref": "#35684" } ] }, diff --git a/ui/packages/app-shell/src/views/InterfaceListPage.editInlineFold-5144.test.tsx b/ui/packages/app-shell/src/views/InterfaceListPage.editInlineFold-5144.test.tsx index 292e9ddca62..729d17cbd01 100644 --- a/ui/packages/app-shell/src/views/InterfaceListPage.editInlineFold-5144.test.tsx +++ b/ui/packages/app-shell/src/views/InterfaceListPage.editInlineFold-5144.test.tsx @@ -5,17 +5,14 @@ * * An ADR-0047 interface page reads the page config's `userActions.editInline` * with the protocol's default, on (`!== false`, objectstack#22605), and hands - * it to `ListView` as the view's `inlineEdit`. It does not forward `editInline` - * itself, so the `userActions` block it builds carries no `editInline` key. The - * page wires no inline-edit toggle, so that `inlineEdit` is the grid's edit - * mode: a page that declares nothing opens its grid editable in place, and + * it to `ListView` as the `userActions.editInline` it builds. Since the list + * has no edit mode (objectstack#35684) it writes no legacy `inlineEdit`: a page + * that declares nothing opens its grid editable in place, and * `editInline: false` is the opt-out. * - * `ListView` reads what this page composes through `normalizeListViewSchema`, - * which folds the `inlineEdit` the page sets into `userActions.editInline`. So - * the two readings agree. This file pins it by capturing the schema the page - * hands `ListView` and running it through the real fold, which is the input - * `ListView`'s `inlineEditOffered` reads. What `ListView` does with + * This file pins it by capturing the schema the page hands `ListView` and + * running it through the real fold (`normalizeListViewSchema`), which is the + * input `ListView`'s `inlineEditOffered` reads. What `ListView` does with * `editInline`, the permission gate included, is pinned in * `@object-ui/plugin-list`'s `ListView.permissions.test.tsx`. */ @@ -106,31 +103,26 @@ describe('InterfaceListPage: editInline reads the same as ListView after the fol testObjects = []; }); - it('an ABSENT page editInline reads on, on both: edit mode, and `editInline` folds to true (objectui#12086)', async () => { + it('an ABSENT page editInline reads on: the page writes `editInline: true`, and no legacy `inlineEdit` (objectui#12086)', async () => { const schema = await composedSchema({ search: true }); // The page's own reading: the protocol default, `!== false`. - expect(schema.inlineEdit).toBe(true); - // The page forwards no `editInline` of its own… - expect(schema.userActions).not.toHaveProperty('editInline'); - // …so `ListView` reads the folded one, which is on. + expect((schema.userActions as Record).editInline).toBe(true); + expect(schema).not.toHaveProperty('inlineEdit'); expect(editInlineRead(schema)).toBe(true); }); it('a page with no `userActions` block at all reads on the same way', async () => { const schema = await composedSchema(undefined); - expect(schema.inlineEdit).toBe(true); expect(editInlineRead(schema)).toBe(true); }); it('an explicit page `editInline: true` reads on, on both', async () => { const schema = await composedSchema({ editInline: true }); - expect(schema.inlineEdit).toBe(true); expect(editInlineRead(schema)).toBe(true); }); it('an explicit page `editInline: false` is the opt-out: off on both', async () => { const schema = await composedSchema({ editInline: false }); - expect(schema.inlineEdit).toBe(false); expect(editInlineRead(schema)).toBe(false); }); }); diff --git a/ui/packages/app-shell/src/views/InterfaceListPage.relayCensus-11572.test.ts b/ui/packages/app-shell/src/views/InterfaceListPage.relayCensus-11572.test.ts index 1a6acdf6715..44481258990 100644 --- a/ui/packages/app-shell/src/views/InterfaceListPage.relayCensus-11572.test.ts +++ b/ui/packages/app-shell/src/views/InterfaceListPage.relayCensus-11572.test.ts @@ -500,7 +500,6 @@ const NOT_RELAYED: Record = { showRecordCount: { kind: 'page-owned', from: 'showRecordCount', reason: "The page config's record-count toggle, page presentation policy; the referenced view's toggle does not stand in for it." }, allowPrinting: { kind: 'page-owned', from: 'allowPrinting', reason: "The page config's \"Allow users to print the page\". It went unwritten until objectui#11572, so the declared toggle drew no print button; the page's value only, like its siblings." }, userActions: { kind: 'page-owned', from: 'userActions', reason: "The page config's toolbar toggles, read with the published `UserActionsConfigSchema` defaults (a control is withheld by writing `false`; rowColor is opt-in). The view's toolbar vocabulary is the object page's policy, not this page's." }, - inlineEdit: { kind: 'page-owned', from: 'userActions', reason: "Read from the page's `userActions.editInline` (default on since objectstack#22605; `editInline: false` opts out). Whether this page's cells are editable is the page author's decision, not the referenced view's." }, navigation: { kind: 'page-prop', from: 'recordAction', prop: 'onRowClick', reason: "The page config's `recordAction` (drawer / page / modal / none) decides how a record opens, wired through `onRowClick` to this page's own overlay. The view's `navigation` would be a second, competing answer." }, // ── The page's own binding and text ────────────────────────────────────── diff --git a/ui/packages/app-shell/src/views/InterfaceListPage.tsx b/ui/packages/app-shell/src/views/InterfaceListPage.tsx index 64bc00b32e5..f6b987b4ce0 100644 --- a/ui/packages/app-shell/src/views/InterfaceListPage.tsx +++ b/ui/packages/app-shell/src/views/InterfaceListPage.tsx @@ -618,17 +618,16 @@ export function InterfaceListPage({ page, className, onConfigChange, reserveEdit group: userActions.group !== false, hideFields: userActions.hideFields !== false, rowColor: userActions.rowColor === true, + // Inline record editing is a page-authored property, on by default + // (the v18 protocol default, objectstack#22605): a page opts out with + // `editInline: false`. A cell edits in place with the dedicated field + // widgets, same as the object views, and only where `ListView`'s + // permission gate admits the principal (the object editable in place, + // and the `update` grant). Written as the canonical key since the list + // has no edit mode for a legacy `inlineEdit` to start (objectstack#35684). + editInline: userActions.editInline !== false, }, allowExport: false, - // Inline record editing is a page-authored property read from - // `userActions.editInline`, on by default (the v18 protocol default, - // objectstack#22605): a page opts out with `editInline: false`. This page - // wires no inline-edit toggle, so the value is the grid's edit mode - // itself. When on, a cell edits in place with the dedicated field - // widgets, same as the object views, and only where `ListView`'s - // permission gate admits the principal (the object editable in place, and - // the `update` grant). - inlineEdit: userActions.editInline !== false, }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [objectDefName, viewDefJson, cfg, orgAttribution]); diff --git a/ui/packages/app-shell/src/views/InterfaceListPage.userActionsSpecDefaults.test.tsx b/ui/packages/app-shell/src/views/InterfaceListPage.userActionsSpecDefaults.test.tsx index 4c7761ddcca..59f73f2ff5b 100644 --- a/ui/packages/app-shell/src/views/InterfaceListPage.userActionsSpecDefaults.test.tsx +++ b/ui/packages/app-shell/src/views/InterfaceListPage.userActionsSpecDefaults.test.tsx @@ -123,6 +123,9 @@ const SPEC_DEFAULT_TOOLBAR = { group: true, hideFields: true, rowColor: false, + // On by default as well: the page writes it as the canonical key, since the + // list has no edit mode for a legacy `inlineEdit` to start (objectstack#35684). + editInline: true, }; const ON_BY_DEFAULT = ['filter', 'rowHeight', 'group', 'hideFields'] as const; diff --git a/ui/packages/app-shell/src/views/ObjectView.fallbackTabSessionOnly-11643.test.tsx b/ui/packages/app-shell/src/views/ObjectView.fallbackTabSessionOnly-11643.test.tsx index d9309eefd15..f2250fab0ea 100644 --- a/ui/packages/app-shell/src/views/ObjectView.fallbackTabSessionOnly-11643.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.fallbackTabSessionOnly-11643.test.tsx @@ -128,6 +128,9 @@ vi.mock('@object-ui/plugin-list', async (importOriginal) => ({ })); import { toast } from 'sonner'; +// `ObjectView` reaches a dynamic `import('@objectstack/lint')`: pay its load at +// collection, never inside a case's clocked window (`check:test-source-alias`). +import '@objectstack/lint'; import { ObjectView } from './ObjectView'; import { ExpressionProvider } from '../providers/ExpressionProvider'; import { answerObjectViewRead } from './__tests__/objectViewRoute'; @@ -344,9 +347,9 @@ describe('objectui#11643 — the console-made tab of a view-less object keeps it expect(listSchema.label).toBe(FALLBACK_TAB_LABEL); // Every control that used to reach the toolbar's view write, through both - // the schema's and the list's own spelling of it. `onInlineEditChange` no longer reaches - // it at all (objectui#5144, ruling E: the toggle is session-only); it stays - // here because it must still write nothing. + // the schema's and the list's own spelling of it. (`onInlineEditChange` + // is no longer handed to the list at all: objectstack#35684 retired the + // toggle it reported.) act(() => { listSchema.onDensityChange('comfortable'); listSchema.onSortChange(SORT); @@ -354,7 +357,6 @@ describe('objectui#11643 — the console-made tab of a view-less object keeps it listSchema.onColumnStateChange({ widths: { title: 240 } }); listProps.onSortChange(SORT); listProps.onHiddenFieldsChange(['status']); - listProps.onInlineEditChange(true); listProps.onColumnStateChange({ order: ['status', 'title'] }); }); // Past the 300 ms debounce and any round trip it would have started. diff --git a/ui/packages/app-shell/src/views/ObjectView.inlineEditSessionOnly-5144.test.tsx b/ui/packages/app-shell/src/views/ObjectView.inlineEditSessionOnly-5144.test.tsx index 3ea7cf7e26d..15c4b69e19a 100644 --- a/ui/packages/app-shell/src/views/ObjectView.inlineEditSessionOnly-5144.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.inlineEditSessionOnly-5144.test.tsx @@ -8,7 +8,10 @@ /** * objectui#5144, triage's ruling E — the console's inline-edit toggle is - * session state and writes nothing. + * session state and writes nothing. Since objectstack#35684 there is no + * toggle and no mode at all: the page hands `ListView` no inline-edit + * callback, and these cases pin that nothing the page does stores an + * `inlineEdit`, and what the fold reads. * * The view's `inlineEdit` and `userActions.editInline` are the author's * permission keys, and `normalizeListViewSchema` folds the first into the @@ -102,6 +105,9 @@ vi.mock('@object-ui/plugin-list', async (importOriginal) => ({ })); import { toast } from 'sonner'; +// `ObjectView` reaches a dynamic `import('@objectstack/lint')`: pay its load at +// collection, never inside a case's clocked window (`check:test-source-alias`). +import '@objectstack/lint'; import { ObjectView } from './ObjectView'; import { ExpressionProvider } from '../providers/ExpressionProvider'; import { answerObjectViewRead } from './__tests__/objectViewRoute'; @@ -308,17 +314,13 @@ afterEach(() => { vi.clearAllMocks(); }); -describe('objectui#5144 (ruling E) — the console inline-edit toggle writes nothing', () => { - it('switching the toggle on a served view sends no write; the store records a view write when one is made', async () => { +describe('objectui#5144 (ruling E), objectstack#35684 — the console stores no inline-edit mode', () => { + it('a served view hands `ListView` no inline-edit callback and sends no write; the store records a view write when one is made', async () => { const { meta, rows, bodies } = makeStore([SERVED_OVERLAY]); const ds = await openPage(meta, OPTED_IN_OBJECT, 'all'); expect(listSchema.label).toBe('All notes'); - expect(typeof listProps.onInlineEditChange).toBe('function'); - - act(() => { - listProps.onInlineEditChange(true); - listProps.onInlineEditChange(false); - }); + // objectstack#35684 — no toggle, so no callback to report it. + expect(listProps.onInlineEditChange).toBeUndefined(); // Past the old toolbar write's 300 ms debounce, with room to spare. await wait(700); expect(meta.saveItem).not.toHaveBeenCalled(); @@ -338,33 +340,26 @@ describe('objectui#5144 (ruling E) — the console inline-edit toggle writes not expect(toast.error).not.toHaveBeenCalled(); }); - it('two-way: on a view that declares `userActions.editInline: true`, the toggle is still offered after it is switched off and the view remounts', async () => { + it('a view that declares `userActions.editInline: true` reads on, and still does after the view remounts', async () => { const { meta, rows } = makeStore([SERVED_OVERLAY]); await openPage(meta, OPTED_IN_OBJECT, 'all'); expect(folded().editInline).toBe(true); - - act(() => listProps.onInlineEditChange(false)); await wait(700); expect(rows.get('all')).toEqual(SERVED_OVERLAY); cleanup(); await openPage(meta, OPTED_IN_OBJECT, 'all'); expect(folded().editInline).toBe(true); - // Nothing was stored, so the mode is seeded from the view again. + // Nothing was stored. expect(folded().inlineEdit).toBeUndefined(); }); - it('a saved view: the toggle switched off writes nothing, and the stored `inlineEdit: true` is what the next load reads', async () => { - // Recorded cost of ruling E: the edit mode is not remembered across loads. + it('a saved view writes nothing, and the stored `inlineEdit: true` is what the next load reads', async () => { const { meta, rows, bodies } = makeStore([SAVED_ROW]); await openPage(meta, PLAIN_OBJECT, SAVED_ID); expect(listSchema.label).toBe('Mine'); expect(folded()).toEqual({ editInline: true, inlineEdit: true }); - act(() => listProps.onInlineEditChange(false)); - await wait(700); - expect(meta.saveItem).not.toHaveBeenCalled(); - // Since objectui#12474 a density change on the same saved view writes no // row either (it is the user's own list state), so the row's own // `inlineEdit` is untouched and no body carries the toggle's `false`. diff --git a/ui/packages/app-shell/src/views/ObjectView.listOnlyRecordPage-33219.test.tsx b/ui/packages/app-shell/src/views/ObjectView.listOnlyRecordPage-33219.test.tsx index 475755fb5d4..e015b30aa9c 100644 --- a/ui/packages/app-shell/src/views/ObjectView.listOnlyRecordPage-33219.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.listOnlyRecordPage-33219.test.tsx @@ -234,6 +234,7 @@ describe('objectstack#33219 — a list-only object\'s rows open no record page', it('a row click opens nothing: no `?recordId=`, no drawer, the list stays', async () => { await mountList(LIST_ONLY_OPERATIONS); fireEvent.click(screen.getByText('okta-staging')); + openWithSpace('scim_ab12'); await settle(); expect(search()).toBe(''); expect(pathname()).toBe(LIST_PATH); @@ -271,18 +272,32 @@ describe('objectstack#33219 — a list-only object\'s rows open no record page', expect(await rowMenuItems('okta-staging')).toContain('Revoke'); }); - it('CONTROL — the same object served with no restriction: the row click opens the drawer', async () => { + it('CONTROL — the same object served with no restriction: the name opens the drawer, and ⌘ on it is the browser\'s new tab', async () => { await mountList(undefined); expect(screen.getAllByTestId('record-open-as-page').length).toBeGreaterThan(0); - expect(screen.getByText('okta-staging').closest('tr')!.querySelector('a[href]')).not.toBeNull(); + const anchor = screen.getByText('okta-staging').closest('tr')!.querySelector('a[href]') as HTMLElement; + expect(anchor).not.toBeNull(); + // objectstack#35684: a ⌘-click on the name link keeps the browser's default + // (`fireEvent` answers false when it was prevented); on a data cell it opens nothing. + expect(fireEvent.click(anchor, { metaKey: true })).toBe(true); fireEvent.click(screen.getByText('scim_ab12'), { metaKey: true }); - expect(openSpy).toHaveBeenCalledTimes(1); + expect(openSpy).not.toHaveBeenCalled(); fireEvent.click(screen.getByText('okta-staging')); await waitFor(() => expect(search()).toBe('?recordId=c1')); expect(await screen.findByRole('dialog', undefined, { timeout: 5000 })).toBeTruthy(); }); }); +/** + * objectstack#35684 — the list's other way to open a row: a click on a data + * cell selects it (and opens nothing), and Space on the selected cell opens + * its record, as the row's click used to. + */ +function openWithSpace(text: string): void { + fireEvent.click(screen.getByText(text).closest('td') as HTMLElement); + fireEvent.keyDown(document.activeElement as HTMLElement, { key: ' ' }); +} + async function mountDataPage(apiOperations: string[] | undefined, search = '') { findOne = vi.fn(async () => null); const dataSource = { @@ -318,6 +333,7 @@ describe('objectstack#33219 — the bare data page opens no record of a list-onl await mountDataPage(LIST_ONLY_OPERATIONS); fireEvent.click(screen.getByText('scim_ab12')); fireEvent.click(screen.getByText('scim_ab12'), { metaKey: true }); + openWithSpace('scim_ab12'); await settle(); expect(search()).toBe(''); expect(openSpy).not.toHaveBeenCalled(); @@ -332,9 +348,9 @@ describe('objectstack#33219 — the bare data page opens no record of a list-onl expect(findOne).not.toHaveBeenCalled(); }); - it('CONTROL — the same object served with no restriction: the row click opens the drawer', async () => { + it('CONTROL — the same object served with no restriction: Space on a selected cell opens the drawer', async () => { await mountDataPage(undefined); - fireEvent.click(screen.getByText('scim_ab12')); + openWithSpace('scim_ab12'); await waitFor(() => expect(search()).toBe('?recordId=c1')); expect(await screen.findByRole('dialog', undefined, { timeout: 5000 })).toBeTruthy(); }); diff --git a/ui/packages/app-shell/src/views/ObjectView.rowOpensNothing-33317.test.tsx b/ui/packages/app-shell/src/views/ObjectView.rowOpensNothing-33317.test.tsx index ae81ea60f5d..0faed25f564 100644 --- a/ui/packages/app-shell/src/views/ObjectView.rowOpensNothing-33317.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.rowOpensNothing-33317.test.tsx @@ -285,6 +285,16 @@ async function contextMenuOf(plainText: string): Promise<{ ids: (string | null)[ const OPEN_ITEMS = ['row-context-open', 'row-context-open-new-tab']; +/** + * objectstack#35684 — the list's other way to open a row: a click on a data + * cell selects it (and opens nothing), and Space on the selected cell opens + * its record, as the row's click used to. + */ +function openWithSpace(text: string): void { + fireEvent.click(screen.getByText(text).closest('td') as HTMLElement); + fireEvent.keyDown(document.activeElement as HTMLElement, { key: ' ' }); +} + describe('objectstack#33317 — the console object list: a row that opens nothing does not look clickable', () => { it('authored `navigation.mode: none`: the name cell is plain text, and the right-click menu has no Open but keeps Revoke', async () => { await mountList({ navigation: { mode: 'none' } }); @@ -303,6 +313,7 @@ describe('objectstack#33317 — the console object list: a row that opens nothin fireEvent.click(screen.getByText('scim_ab12'), { button: 1 }); // The name cell, no longer a link of its own, hands its click to the row too. fireEvent.click(screen.getByText('okta-staging'), { metaKey: true }); + openWithSpace('scim_ab12'); expect(openSpy).not.toHaveBeenCalled(); expect(screen.queryByTestId('left-the-list')).toBeNull(); }); @@ -314,12 +325,17 @@ describe('objectstack#33317 — the console object list: a row that opens nothin expect(openSpy).not.toHaveBeenCalled(); }); - it('CONTROL — the default drawer: a ⌘, Ctrl or middle click on the row opens the record in a new tab', async () => { + it('CONTROL — the default drawer: a ⌘, Ctrl or middle click on the record link is the browser\'s new tab, and on a data cell opens nothing (objectstack#35684)', async () => { await mountList({}); + const link = within(nameCell('okta-staging')).getByTestId('primary-field-link'); + expect(link.getAttribute('href')).toContain('c1'); + // `fireEvent` answers false when the default was prevented: these keep the browser's. + expect(fireEvent.click(link, { metaKey: true })).toBe(true); + expect(fireEvent.click(link, { ctrlKey: true })).toBe(true); + expect(fireEvent.click(link, { button: 1 })).toBe(true); fireEvent.click(screen.getByText('scim_ab12'), { metaKey: true }); - fireEvent.click(screen.getByText('scim_ab12'), { ctrlKey: true }); - fireEvent.click(screen.getByText('scim_ab12'), { button: 1 }); - expect(openSpy).toHaveBeenCalledTimes(3); + expect(openSpy).not.toHaveBeenCalled(); + expect(drawerRecordId()).toBeNull(); }); it('a list-only object: the name cell is plain text, and the right-click menu has no Open but keeps Revoke', async () => { @@ -369,6 +385,7 @@ describe('objectstack#33549 — the console object list: `navigation.preventNavi await mountList({ navigation: PREVENTED_DRAWER }); fireEvent.click(screen.getByText('scim_ab12')); fireEvent.click(screen.getByText('okta-staging')); + openWithSpace('scim_ab12'); expect(drawerRecordId()).toBeNull(); expect(screen.queryByTestId('left-the-list')).toBeNull(); expect(openSpy).not.toHaveBeenCalled(); @@ -395,20 +412,20 @@ describe('objectstack#33549 — the console object list: `navigation.preventNavi it('a `page` view with `preventNavigation: true` draws no link face either', async () => { await mountList({ navigation: { mode: 'page', preventNavigation: true } }); expect(looksLikeALink('okta-staging')).toBe(false); - fireEvent.click(screen.getByText('scim_ab12')); + openWithSpace('scim_ab12'); expect(screen.queryByTestId('left-the-list')).toBeNull(); }); - it('CONTROL — the same `drawer` view with `preventNavigation: false`: a row click writes `?recordId=`, and the name cell is the record link', async () => { + it('CONTROL — the same `drawer` view with `preventNavigation: false`: Space on a selected cell writes `?recordId=`, and the name cell is the record link', async () => { await mountList({ navigation: { mode: 'drawer', preventNavigation: false } }); expect(looksLikeALink('okta-staging')).toBe(true); - fireEvent.click(screen.getByText('scim_ab12')); + openWithSpace('scim_ab12'); await waitFor(() => expect(drawerRecordId()).toBe('c1')); }); - it('CONTROL — the same `drawer` view with the flag absent: a row click writes `?recordId=`', async () => { + it('CONTROL — the same `drawer` view with the flag absent: the record link writes `?recordId=`', async () => { await mountList({ navigation: { mode: 'drawer' } }); - fireEvent.click(screen.getByText('scim_ab12')); + fireEvent.click(within(nameCell('okta-staging')).getByTestId('primary-field-link')); await waitFor(() => expect(drawerRecordId()).toBe('c1')); }); }); diff --git a/ui/packages/app-shell/src/views/objectViewChrome.tsx b/ui/packages/app-shell/src/views/objectViewChrome.tsx index b90a531bb8e..0677b76ec64 100644 --- a/ui/packages/app-shell/src/views/objectViewChrome.tsx +++ b/ui/packages/app-shell/src/views/objectViewChrome.tsx @@ -42,29 +42,6 @@ export function ObjectNotFoundState({ objectName, packageDisabled = false }: { o ); } -/** - * The list toolbar's inline-edit toggle, as this page wires it: it writes - * nothing (objectui#5144, triage's ruling E). - * - * The view's `inlineEdit` and `userActions.editInline` are the AUTHOR's - * permission keys, and `normalizeListViewSchema` folds the first into the - * second. `editInline` is on by default since the v18 ruling (objectstack#22605, - * objectui#12086), so a view that declares neither key offers the toggle, and - * `editInline: false` withdraws it. This toggle used to persist a USER's edit - * mode into `inlineEdit` through `persistViewPatch`. After the fold, switching - * it off stored `inlineEdit: false`, which reads as "not offered", so the - * toggle was gone from the next load and nothing in the console could bring it - * back. - * - * The edit mode is now session state. `ListView` keeps it, and seeds it from - * the view's `inlineEdit` on each load. The callback stays wired because - * `ListView` offers the wide toolbar toggle only to a host that wires one. - * - * Recorded costs: the edit mode is not remembered across loads, and an overlay - * that already stores `inlineEdit: false` still reads off. That is existing - * data, and the maintainer's ruling rejects migrating it. Declaring - * `userActions.editInline: true` on such a view brings the toggle back. - */ /** * Tailwind's `sm` breakpoint (px): from here up the list page draws its page * header, whose title is the view switcher (objectstack#27594); below it the @@ -96,7 +73,3 @@ export function useViewTabsFit(): boolean { }, []); return fits; } - -export function keepInlineEditModeForTheSession(): void { - // Deliberately empty: see the docblock. -} diff --git a/ui/packages/app-shell/src/views/objectViewListRenderer.tsx b/ui/packages/app-shell/src/views/objectViewListRenderer.tsx index 45ba77619a5..0651c259509 100644 --- a/ui/packages/app-shell/src/views/objectViewListRenderer.tsx +++ b/ui/packages/app-shell/src/views/objectViewListRenderer.tsx @@ -40,7 +40,7 @@ import { kanbanViewOptions, isSameOptionsValue, } from './objectViewOptions.js'; -import { keepInlineEditModeForTheSession, useViewTabsFit } from './objectViewChrome.js'; +import { useViewTabsFit } from './objectViewChrome.js'; import { ListRecordCountContext } from './objectViewTitleSwitcher.js'; import { OpenAsPageLink } from './objectViewOpenAsPage.js'; import type { useObjectViewIdentity } from './objectViewIdentity.js'; @@ -1101,8 +1101,6 @@ export function useObjectViewListRenderer({ // the door that stores a change to them (see `persistAddedFields`). addedFields={listColumns.addedFields} onAddedFieldsChange={addedFieldsStored ? persistAddedFields : undefined} - // objectui#5144 (ruling E): session-only, writes nothing. - onInlineEditChange={keepInlineEditModeForTheSession} onColumnStateChange={persistListColumnState} userFilterSelections={initialUfSelections} onUserFilterSelectionsChange={handleUserFilterSelectionsChange} diff --git a/ui/packages/components/src/__tests__/data-table-keys-35687.test.tsx b/ui/packages/components/src/__tests__/data-table-keys-35687.test.tsx new file mode 100644 index 00000000000..69c8dbe00a2 --- /dev/null +++ b/ui/packages/components/src/__tests__/data-table-keys-35687.test.tsx @@ -0,0 +1,270 @@ +/** + * 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. + */ + +/** + * The keys of `data-table`'s select-first cell model (objectstack#35687); + * what a click does is `data-table-select-first-35684.test.tsx`. + * + * 1. On the selected cell: the arrows and Tab move the selection; Escape + * clears it; typing opens the editor with the typed text in place of the + * value (a number column gets the number); Backspace opens it empty and + * writes nothing; Ctrl/Cmd+V converts and commits; Ctrl/Cmd+C copies. + * 2. While editing: Enter commits and moves down, Tab / Shift+Tab commit and + * move right / left, Escape cancels and keeps the selection. In a + * multi-line editor Enter is the editor's and Ctrl/Cmd+Enter commits. + * 3. An input method: the keys pressed while it composes, and the 229 + * Enter a browser raises after `compositionend`, never commit; a + * composition started on the selected cell opens the editor with the + * whole composed text. + */ +import React from 'react'; +import { describe, it, expect, afterEach, vi } from 'vitest'; +import { render, fireEvent, cleanup } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { ComponentRegistry } from '@object-ui/core'; +// Registers `data-table` at module scope, not in a hook (objectui#3010). +import '../renderers'; +// `react-page` reaches a dynamic `import('@object-ui/react-runtime')`: pay its load +// at collection, never inside a case's clocked window (`check:test-source-alias`). +import '@object-ui/react-runtime'; +import { GridCellSelectionProvider, type GridCellSelection } from '../context/gridCellSelection'; + +afterEach(() => { + cleanup(); + vi.restoreAllMocks(); +}); + +const ROWS = [ + { id: '1', name: 'Alpha', amount: 10, notes: 'one' }, + { id: '2', name: 'Beta', amount: 20, notes: 'two' }, + { id: '3', name: 'Gamma', amount: 30, notes: 'three' }, +]; + +function renderTable(extra: Record = {}, selection: GridCellSelection = {}) { + const DataTable = ComponentRegistry.get('data-table')!; + const onCellChange = vi.fn(); + const schema = { + type: 'data-table', + columns: [ + { header: 'Name', accessorKey: 'name' }, + { header: 'Amount', accessorKey: 'amount', type: 'number' }, + { header: 'Notes', accessorKey: 'notes' }, + ], + data: ROWS, + editable: true, + searchable: false, + pagination: false, + onCellChange, + ...extra, + }; + const utils = render( + + + , + ); + const cell = (row: number, col: number) => + utils.container.querySelectorAll('tbody tr')[row].querySelectorAll('td[data-grid-cell]')[col] as HTMLElement; + const selected = () => { + const td = utils.container.querySelector('td[data-selected-cell]'); + return td ? td.getAttribute('data-grid-cell') : null; + }; + const editor = () => + utils.container.querySelector('td[data-editing-cell] input, td[data-editing-cell] textarea'); + const catcher = () => utils.container.querySelector('[data-slot="cell-type-catcher"]')!; + const select = (row: number, col: number) => fireEvent.click(cell(row, col)); + return { ...utils, cell, selected, editor, catcher, select, onCellChange }; +} + +describe('data-table select-first keys — on the selected cell (objectstack#35687)', () => { + it('the arrows move the selection, Tab moves along the row, Escape clears it', () => { + const t = renderTable(); + t.select(0, 0); + fireEvent.keyDown(t.catcher(), { key: 'ArrowDown' }); + expect(t.selected()).toBe('1:0'); + fireEvent.keyDown(t.catcher(), { key: 'ArrowRight' }); + expect(t.selected()).toBe('1:1'); + fireEvent.keyDown(t.catcher(), { key: 'Tab' }); + expect(t.selected()).toBe('1:2'); + fireEvent.keyDown(t.catcher(), { key: 'Tab' }); + expect(t.selected()).toBe('2:0'); + fireEvent.keyDown(t.catcher(), { key: 'Tab', shiftKey: true }); + expect(t.selected()).toBe('1:2'); + expect(t.editor()).toBeNull(); + fireEvent.keyDown(t.catcher(), { key: 'Escape' }); + expect(t.selected()).toBeNull(); + }); + + it('typing replaces the value with the typed text, and Escape puts the value back', () => { + const t = renderTable(); + t.select(0, 0); + fireEvent.change(t.catcher(), { target: { value: 'Z' } }); + expect(t.editor()).toHaveValue('Z'); + fireEvent.keyDown(t.editor()!, { key: 'Escape' }); + expect(t.editor()).toBeNull(); + expect(t.cell(0, 0)).toHaveTextContent('Alpha'); + expect(t.selected()).toBe('0:0'); + expect(t.onCellChange).not.toHaveBeenCalled(); + }); + + it('typing 5 on a number cell edits 5, and Escape leaves the old figure', () => { + const t = renderTable(); + t.select(1, 1); + fireEvent.change(t.catcher(), { target: { value: '5' } }); + expect(t.editor()).toHaveValue(5); + fireEvent.keyDown(t.editor()!, { key: 'Escape' }); + expect(t.cell(1, 1)).toHaveTextContent('20'); + expect(t.onCellChange).not.toHaveBeenCalled(); + }); + + it.each(['Backspace', 'Delete'])('%s opens an empty editor and writes nothing', (key) => { + const t = renderTable(); + t.select(1, 1); + fireEvent.keyDown(t.catcher(), { key }); + expect(t.editor()).not.toBeNull(); + expect(t.editor()!.value).toBe(''); + expect(t.onCellChange).not.toHaveBeenCalled(); + }); + + it('Ctrl/Cmd+V converts the text to the column and commits it; text that is no value writes nothing', () => { + const t = renderTable(); + t.select(0, 1); + fireEvent.paste(t.catcher(), { clipboardData: { getData: () => '42\n' } }); + expect(t.onCellChange).toHaveBeenCalledWith(0, 'amount', 42, ROWS[0]); + t.onCellChange.mockClear(); + fireEvent.paste(t.catcher(), { clipboardData: { getData: () => 'forty-two' } }); + expect(t.onCellChange).not.toHaveBeenCalled(); + // The host's reading of the text wins. + const h = renderTable({}, { describeCell: () => ({ fromText: (text) => text.toUpperCase() }) }); + h.select(0, 0); + fireEvent.paste(h.catcher(), { clipboardData: { getData: () => 'zed' } }); + expect(h.onCellChange).toHaveBeenCalledWith(0, 'name', 'ZED', ROWS[0]); + }); + + it('Ctrl/Cmd+C copies the selected value', () => { + const writeText = vi.fn().mockResolvedValue(undefined); + const had = Object.getOwnPropertyDescriptor(navigator, 'clipboard'); + Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true }); + try { + const t = renderTable(); + t.select(2, 0); + fireEvent.keyDown(t.catcher(), { key: 'c', ctrlKey: true }); + expect(writeText).toHaveBeenCalledWith('Gamma'); + } finally { + if (had) Object.defineProperty(navigator, 'clipboard', had); + else delete (navigator as { clipboard?: unknown }).clipboard; + } + }); + + it('with CapsLock on, Ctrl+C (key `C`) still copies', () => { + const writeText = vi.fn().mockResolvedValue(undefined); + const had = Object.getOwnPropertyDescriptor(navigator, 'clipboard'); + Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true }); + try { + const t = renderTable(); + t.select(2, 0); + fireEvent.keyDown(t.catcher(), { key: 'C', ctrlKey: true }); + expect(writeText).toHaveBeenCalledWith('Gamma'); + } finally { + if (had) Object.defineProperty(navigator, 'clipboard', had); + else delete (navigator as { clipboard?: unknown }).clipboard; + } + }); + + it('with CapsLock on, Ctrl+V (key `V`) types nothing into the cell, and the paste still commits', () => { + const t = renderTable(); + t.select(0, 1); + fireEvent.keyDown(t.catcher(), { key: 'V', ctrlKey: true }); + expect(t.editor()).toBeNull(); + fireEvent.paste(t.catcher(), { clipboardData: { getData: () => '42' } }); + expect(t.onCellChange).toHaveBeenCalledWith(0, 'amount', 42, ROWS[0]); + }); +}); + +describe('data-table select-first keys — while editing', () => { + it('Enter commits and moves down; Tab commits and moves right; Shift+Tab left', () => { + const t = renderTable(); + t.select(0, 0); + fireEvent.change(t.catcher(), { target: { value: 'A' } }); + fireEvent.keyDown(t.editor()!, { key: 'Enter' }); + expect(t.onCellChange).toHaveBeenLastCalledWith(0, 'name', 'A', ROWS[0]); + expect(t.editor()).toBeNull(); + expect(t.selected()).toBe('1:0'); + fireEvent.keyDown(t.catcher(), { key: 'Enter' }); + fireEvent.keyDown(t.editor()!, { key: 'Tab' }); + expect(t.selected()).toBe('1:1'); + expect(t.editor()).toBeNull(); + fireEvent.keyDown(t.catcher(), { key: 'F2' }); + fireEvent.keyDown(t.editor()!, { key: 'Tab', shiftKey: true }); + expect(t.selected()).toBe('1:0'); + expect(t.onCellChange).toHaveBeenCalledTimes(3); + }); + + it('Escape cancels and keeps the cell selected, with focus on it', () => { + const t = renderTable(); + t.select(2, 2); + fireEvent.keyDown(t.catcher(), { key: 'Enter' }); + fireEvent.change(t.editor()!, { target: { value: 'changed' } }); + fireEvent.keyDown(t.editor()!, { key: 'Escape' }); + expect(t.editor()).toBeNull(); + expect(t.cell(2, 2)).toHaveTextContent('three'); + expect(t.selected()).toBe('2:2'); + expect(document.activeElement).toBe(t.catcher()); + }); + + it('a multi-line editor keeps Enter, and Ctrl/Cmd+Enter commits it', () => { + const renderCellEditor = (ctx: { value: unknown; stage: (v: unknown) => void }) => ( +