From 9fcdfaf82fd2f28b298a576685a1cbd8a569a041 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 18:15:35 +0000 Subject: [PATCH 1/4] fix(plugin-grid): row menu hides Edit on a row held by a locking approval The grid's row menu (list page and record-page related tab) now reads the approval locks the select-first cells read, asked when a row's actions are reached for. An answered lock hides Edit; Delete stays. Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- ui/packages/plugin-grid/src/ObjectGrid.tsx | 27 +- .../rowMenuApprovalLock-36911.test.tsx | 231 ++++++++++++++++++ .../src/objectGridActionsColumn.tsx | 35 ++- 3 files changed, 286 insertions(+), 7 deletions(-) create mode 100644 ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx diff --git a/ui/packages/plugin-grid/src/ObjectGrid.tsx b/ui/packages/plugin-grid/src/ObjectGrid.tsx index c33d5e0246c..05144f17170 100644 --- a/ui/packages/plugin-grid/src/ObjectGrid.tsx +++ b/ui/packages/plugin-grid/src/ObjectGrid.tsx @@ -1485,7 +1485,28 @@ export const ObjectGrid: React.FC = ({ // object, an approval lock, the record — `cellReadOnlyKind`), what typing // does there and what pasted text stands for. `null` without the host's // ask, so every other grid keeps the table it had. - const approvalLocks = useRowApprovalLocks(hostCellSelection ? objectName : undefined); + // + // objectstack#36911 — the row menu reads the same locks: a row an approval + // locks offers no Edit, as the record page offers none (objectstack#35593). + // Delete stays: the server lets a locked record be deleted and cancels its + // request. So the hook also runs on a grid whose rows offer Edit. It still + // reads nothing until it is asked: by a cell being selected, or by a row's + // actions being reached for (`demandRowActions` below). + const rowMenuOffersEdit = canEdit && !!onEdit; + const approvalLocks = useRowApprovalLocks(hostCellSelection || rowMenuOffersEdit ? objectName : undefined); + /** + * objectstack#36911 — what reaching for a row's actions asks + * (`RowActionMenuProps.onActionsDemand`, objectstack#34208): the + * record-grained verdicts, and the approval locks of the rows on screen in + * one read (objectstack#35795), never on first paint. A repeat call is free: + * the hook asks only ids it has not asked yet. + */ + const requestRecordVerdicts = recordVerdict.requestVerdicts; + const probeApprovalLocks = approvalLocks.probe; + const demandRowActions = useCallback(() => { + requestRecordVerdicts(); + if (rowMenuOffersEdit) probeApprovalLocks(pageRecordIds); + }, [requestRecordVerdicts, probeApprovalLocks, rowMenuOffersEdit, pageRecordIds]); // objectstack#35956 — a cell change that makes other fields required asks // for them first, and saves them with it (`./objectGridRequiredPrompt`). const fieldLabelOf = (field: string): string => { @@ -2418,8 +2439,8 @@ export const ObjectGrid: React.FC = ({ } = resolveObjectGridActionsColumn({ schema, data, objectSchema, persistedColumns, operations, resolvedRowActionDefs, wantEditAction, wantDeleteAction, mayInvokeRowAction, rowOperations, canEdit, canDelete, - recordVerdict, predicateScope, onEdit, onDelete, editPredicates, deletePredicates, executeAction, - setRefreshKey, t, foldInlineRowActions: inlineActionFold.folded, + recordVerdict, approvalLocks, demandRowActions, predicateScope, onEdit, onDelete, editPredicates, + deletePredicates, executeAction, setRefreshKey, t, foldInlineRowActions: inlineActionFold.folded, drawRowControls: !listPageGrid, }); diff --git a/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx b/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx new file mode 100644 index 00000000000..c83873d6be2 --- /dev/null +++ b/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx @@ -0,0 +1,231 @@ +/** + * 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#36911 — the row menu follows the approval lock. + * + * A row held by a locking approval is refused `RECORD_LOCKED` on update. The + * record page offers no Edit on such a record (objectstack#35593) and keeps + * Delete, because the server lets a locked record be deleted and cancels its + * request. The grid's row menu, which the list page and a record page's + * related tab both render, offered Edit on it. + * + * The menu now reads the lock the select-first cells read + * (`useRowApprovalLocks`, the batch door + * `POST /api/v1/approvals/records/:object/locks`), asked when a row's actions + * are reached for, never on first paint (objectstack#35795). Only an ANSWERED + * lock hides Edit: a 501, a `null` entry, a failed read or a read not yet + * asked leaves the menu as it was. + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, waitFor, cleanup, act } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import '@testing-library/jest-dom'; +import React from 'react'; + +// Stable-identity permission stub, as `rowRecordCrudVerdict.test.tsx` has it: +// ObjectGrid carries `perms` in memo dependency arrays. +const { permsStub } = vi.hoisted(() => ({ + permsStub: { + isLoaded: false, + checkField: () => true, + getObjectApiOperations: () => ['get', 'list', 'create', 'update', 'delete'], + can: () => true, + }, +})); + +vi.mock('@object-ui/permissions', async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, usePermissions: () => permsStub }; +}); + +import { ObjectGrid } from '../ObjectGrid'; +import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts'; +import { __resetApprovalsServiceLatch } from '../hooks/useRowApprovalLocks'; +import { registerAllFields } from '@object-ui/fields'; +import { ActionProvider, SchemaRendererProvider } from '@object-ui/react'; + +registerAllFields(); + +const OBJECT = 'showcase_project'; +const LOCKS_PATH = `/api/v1/approvals/records/${OBJECT}/locks`; +/** Under an executive review whose node locks the record. */ +const LOCKED_ROW = { id: 'p_locked', name: 'Data Centre Build' }; +/** Its sibling on the same page, with no approval running. */ +const OPEN_ROW = { id: 'p_open', name: 'Office Refresh' }; + +/** What the lock door answers, per id; `undefined` is the read's `null` entry. */ +type LockDoor = + | { kind: 'answers'; locked: Record } + | { kind: 'status'; status: number } + | { kind: 'network' }; + +const server = { + door: { kind: 'answers', locked: {} } as LockDoor, + lockCalls: [] as Array<{ recordIds: string[] }>, + responses: [] as Promise[], + reset() { + server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false } }; + server.lockCalls = []; + server.responses = []; + }, +}; + +const apiFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise => { + const url = String(input); + const body = JSON.parse(String(init?.body ?? '{}')); + const respond = (status: number, payload: unknown) => { + const res = { ok: status >= 200 && status < 300, status, json: async () => payload } as unknown as Response; + const settled = Promise.resolve(res); + server.responses.push(settled); + return settled; + }; + if (url === LOCKS_PATH) { + server.lockCalls.push(body); + const door = server.door; + if (door.kind === 'network') { + const failed = Promise.reject(new TypeError('Failed to fetch')); + server.responses.push(failed.catch(() => undefined)); + return failed; + } + if (door.kind === 'status') return respond(door.status, { success: false }); + const ids: string[] = body.recordIds ?? []; + return respond(200, { + success: true, + data: { records: ids.map((recordId) => ({ recordId, locked: door.locked[recordId] ?? null })) }, + }); + } + // `security/explain`: every row may be written, so only the lock can take Edit away. + const ids: string[] = Array.isArray(body.recordIds) ? body.recordIds : []; + return respond(200, { + allowed: true, + object: body.object, + operation: body.operation, + principal: { userId: 'u_member' }, + layers: [], + records: ids.map((recordId) => ({ recordId, visible: true })), + }); +}; + +function renderGrid(rows: Array> = [LOCKED_ROW, OPEN_ROW]) { + const dataSource: any = { + getObjectSchema: async (name: string) => ({ + name, + fields: { id: { type: 'text' }, name: { type: 'text', label: 'Name' }, approval_status: { type: 'text' } }, + }), + }; + const schema: any = { + type: 'object-grid', + objectName: OBJECT, + columns: [{ field: 'name', label: 'Name' }], + data: { provider: 'value', items: rows }, + pageSize: 500, + }; + return render( + + + {}} onDelete={() => {}} /> + + , + ); +} + +/** Reach for the first row's actions the way a pointer does: hover its "⋮". */ +async function reachRowActions() { + await userEvent.hover(screen.getAllByTestId('row-action-trigger')[0]); +} + +async function settleReads() { + await act(async () => { + await Promise.allSettled(server.responses); + }); +} + +/** What the "⋮" of the row showing `label` offers. */ +async function rowMenu(label: string): Promise<{ edit: boolean; delete: boolean }> { + const row = screen.getByText(label).closest('tr'); + const trigger = row?.querySelector('[data-testid="row-action-trigger"]'); + if (!trigger) return { edit: false, delete: false }; + await userEvent.click(trigger); + const answer = { + edit: screen.queryAllByTestId('row-action-builtin-edit').length > 0, + delete: screen.queryAllByTestId('row-action-builtin-delete').length > 0, + }; + await userEvent.keyboard('{Escape}'); + return answer; +} + +beforeEach(() => { + server.reset(); + __clearRecordCrudVerdictCache(); + __resetApprovalsServiceLatch(); +}); +afterEach(() => { + cleanup(); +}); + +describe('objectstack#36911 — the row menu follows the approval lock', () => { + it('a row held by a locking approval offers no Edit and keeps Delete; its unlocked sibling keeps Edit', async () => { + renderGrid(); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + await reachRowActions(); + await waitFor(() => expect(server.lockCalls.length).toBe(1)); + await settleReads(); + await waitFor(async () => expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: false, delete: true })); + expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: true, delete: true }); + }); + + it('reads no lock before a row\'s actions are reached for, then the page in one read', async () => { + renderGrid(); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + await settleReads(); + expect(server.lockCalls).toHaveLength(0); + await reachRowActions(); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + expect([...server.lockCalls[0].recordIds].sort()).toEqual([LOCKED_ROW.id, OPEN_ROW.id].sort()); + // Reaching again, and opening the menus, asks nothing more. + await settleReads(); + await rowMenu(LOCKED_ROW.name); + await rowMenu(OPEN_ROW.name); + expect(server.lockCalls).toHaveLength(1); + }); + + it('a 501 (no approvals service) leaves the menu as it was, even over an approval_status column', async () => { + server.door = { kind: 'status', status: 501 }; + renderGrid([{ ...LOCKED_ROW, approval_status: 'pending' }, OPEN_ROW]); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + await reachRowActions(); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + await settleReads(); + expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); + expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: true, delete: true }); + }); + + it('a null entry (a row the reader cannot read) leaves Edit where it was', async () => { + server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: null, [OPEN_ROW.id]: false } }; + renderGrid(); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + await reachRowActions(); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + await settleReads(); + expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); + }); + + it('a read that fails, or that never answered, leaves Edit where it was', async () => { + server.door = { kind: 'network' }; + renderGrid(); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + // Not asked yet: the menu is the one it always was. + expect(server.lockCalls).toHaveLength(0); + await reachRowActions(); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + await settleReads(); + expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); + }); +}); diff --git a/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx b/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx index 16d0d6e977e..2c0f37efe68 100644 --- a/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx +++ b/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx @@ -11,6 +11,7 @@ import { isActionSwitchedOff } from '@object-ui/core'; import { PINNED_RIGHT_SEAM_SHADOW_CLASSES } from '@object-ui/components'; import { resolveRowRecordCrudAffordance } from './rowCrudAffordances'; import { useRecordCrudVerdicts } from './hooks/useRecordCrudVerdicts'; +import type { RowApprovalLocks } from './hooks/useRowApprovalLocks'; import { resolveLegacyRowActions } from './resolveLegacyRowActions'; import { RowActionMenu, planRowActionMenu, type RowActionMenuProps } from './components/RowActionMenu'; import { rowRecordId } from './objectGridLinkCell'; @@ -29,8 +30,8 @@ type RowCrudAffordances = ReturnType; export function resolveObjectGridActionsColumn({ schema, data, objectSchema, persistedColumns, operations, resolvedRowActionDefs, wantEditAction, wantDeleteAction, mayInvokeRowAction, rowOperations, canEdit, canDelete, - recordVerdict, predicateScope, onEdit, onDelete, editPredicates, deletePredicates, executeAction, - setRefreshKey, t, foldInlineRowActions = false, drawRowControls = true, + recordVerdict, approvalLocks, demandRowActions, predicateScope, onEdit, onDelete, editPredicates, + deletePredicates, executeAction, setRefreshKey, t, foldInlineRowActions = false, drawRowControls = true, }: { schema: ObjectGridSchema; data: any[]; @@ -45,6 +46,18 @@ export function resolveObjectGridActionsColumn({ canEdit: RowCrudAffordances['canEdit']; canDelete: RowCrudAffordances['canDelete']; recordVerdict: ReturnType; + /** + * objectstack#36911 — the approval locks of the rows on screen, the read the + * select-first cells ask (`useRowApprovalLocks`). A row a read ANSWERED as + * locked offers no Edit; Delete is untouched. + */ + approvalLocks: RowApprovalLocks; + /** + * objectstack#36911 — a row's actions are reached for: asks the + * record-grained verdicts and the page's approval locks + * (`RowActionMenuProps.onActionsDemand`). + */ + demandRowActions: () => void; predicateScope: ReturnType; onEdit: ObjectGridComponentProps['onEdit']; onDelete: ObjectGridComponentProps['onDelete']; @@ -85,11 +98,24 @@ export function resolveObjectGridActionsColumn({ const rowActionDefsGated = (resolvedRowActionDefs as any[]).filter((d) => mayInvokeRowAction(d?.requiredPermissions) && !isActionSwitchedOff(d)); // NON-AUTHOR SURFACE — see the `maxInlineActions` prop below. const maxInlineRowActions: number = foldInlineRowActions ? 0 : ((schema as any).maxInlineRowActions ?? 1); + /** + * objectstack#36911 — is this row held by a locking approval, by a lock read + * that ANSWERED? The row is handed to the hook as no row at all, so its + * `approval_status` column does not stand in: a read refused (501), failed, + * answering `null` (a row the reader cannot read) or not yet asked leaves + * Edit where the menu had it. An answer arriving re-renders the grid. The + * select-first cells read the same hook with the column fallback; the menu + * offers what the server is known to refuse, never less on a guess. + */ + const approvalLockAnswered = (row: any): boolean => approvalLocks.isLocked(rowRecordId(row), null); const rowCrudVerdicts = (row: any) => { // [objectui#8674] The CALLER's answer for this one row, ANDed in below. const rowOps = rowOperations?.(row); return { - canEdit: resolveRowRecordCrudAffordance(canEdit && rowOps?.update !== false, recordVerdict(rowRecordId(row), 'update')), + canEdit: resolveRowRecordCrudAffordance( + canEdit && rowOps?.update !== false && !approvalLockAnswered(row), + recordVerdict(rowRecordId(row), 'update'), + ), canDelete: resolveRowRecordCrudAffordance(canDelete && rowOps?.delete !== false, recordVerdict(rowRecordId(row), 'delete')), }; }; @@ -160,7 +186,8 @@ export function resolveObjectGridActionsColumn({ // once a row's actions are reached for — this is the one channel both // menus and the cell signal it through — and an item whose answer is // still on the wire shows inert rather than clickable. - onActionsDemand: recordVerdict.requestVerdicts, + // objectstack#36911 — the same demand also asks the page's approval locks. + onActionsDemand: demandRowActions, crudVerdictPending: recordVerdict.pending ? { edit: recordVerdict(rowRecordId(row), 'update') === undefined, From 2f9deb374d03c4fd45fc28287747803dd3a2c1c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 19:04:21 +0000 Subject: [PATCH 2/4] chore(changeset): plugin-grid row menu approval lock Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .changeset/36911-row-menu-approval-lock.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/36911-row-menu-approval-lock.md diff --git a/.changeset/36911-row-menu-approval-lock.md b/.changeset/36911-row-menu-approval-lock.md new file mode 100644 index 00000000000..e025dda59f7 --- /dev/null +++ b/.changeset/36911-row-menu-approval-lock.md @@ -0,0 +1,10 @@ +--- +'@object-ui/plugin-grid': patch +--- + +fix(plugin-grid): the row menu offers no Edit on a row held by a locking approval + +Clause-②: no +Metadata-protocol: none + +A grid row whose record is held by a pending approval with `lockRecord: true` is refused `RECORD_LOCKED` when it is updated. Its row menu still offered Edit, on the list page and on a record page's related tab. The menu now reads the same lock the grid's cells read (`POST /api/v1/approvals/records/:object/locks`), once per page, when a row's actions are first reached for. A row the lock read answered as locked offers no Edit, as the record page offers none. Delete stays, because deleting a locked record is allowed and cancels its request. When the lock cannot be read, the menu stays as it was: no approvals service (501), a row the reader cannot read, a failed read, or a read not yet asked. From abbeea23f8cd7a4fde2754b6990347c0b4de9da6 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 19:27:31 +0000 Subject: [PATCH 3/4] test(plugin-grid): explain fakes answer the approval lock door apart Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .../__tests__/inlineEditRecordVerdict-27365.test.tsx | 11 +++++++++++ .../src/__tests__/rowRecordCrudVerdict.test.tsx | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx b/ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx index 500d43effb0..54709597d03 100644 --- a/ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx @@ -94,6 +94,17 @@ const server = { }; const apiFetch = async (_input: RequestInfo | URL, init?: RequestInit): Promise => { + // objectstack#36911 — reaching a row's actions also reads the page's approval + // locks. This fake serves the explain engine: the lock door answers every row + // unlocked and is not counted among the explain calls these pins count. + if (String(_input).includes('/approvals/records/')) { + const ids: string[] = JSON.parse(String(init?.body ?? '{}')).recordIds ?? []; + return { + ok: true, + status: 200, + json: async () => ({ records: ids.map((recordId) => ({ recordId, locked: false })) }), + } as unknown as Response; + } const body = JSON.parse(String(init?.body ?? '{}')) as { object?: string; operation?: Operation; recordIds?: string[] }; server.calls.push(body); if (!server.network) throw new TypeError('Failed to fetch'); diff --git a/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx b/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx index d03ef015f5f..dafa34dbe6d 100644 --- a/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx @@ -138,6 +138,17 @@ const server = { }; const apiFetch = async (_input: RequestInfo | URL, init?: RequestInit): Promise => { + // objectstack#36911 — reaching a row's actions also reads the page's approval + // locks. This fake serves the explain engine: the lock door answers every row + // unlocked and is not counted among the explain calls these pins count. + if (String(_input).includes('/approvals/records/')) { + const ids: string[] = JSON.parse(String(init?.body ?? '{}')).recordIds ?? []; + return { + ok: true, + status: 200, + json: async () => ({ records: ids.map((recordId) => ({ recordId, locked: false })) }), + } as unknown as Response; + } const body = JSON.parse(String(init?.body ?? '{}')) as ExplainCall; server.calls.push(body); if (!server.network) throw new TypeError('Failed to fetch'); From 4c64a0a109d1612eea4221d31ad4822210eb65ec Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 22:14:01 +0000 Subject: [PATCH 4/4] test(plugin-grid): pin the list page selection bar and the read in flight; narrow the Delete claim Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .changeset/36911-row-menu-approval-lock.md | 2 +- ui/packages/plugin-grid/src/ObjectGrid.tsx | 5 +- .../rowMenuApprovalLock-36911.test.tsx | 94 ++++++++++++++++++- .../src/objectGridActionsColumn.tsx | 11 ++- 4 files changed, 103 insertions(+), 9 deletions(-) diff --git a/.changeset/36911-row-menu-approval-lock.md b/.changeset/36911-row-menu-approval-lock.md index e025dda59f7..3015f5d0933 100644 --- a/.changeset/36911-row-menu-approval-lock.md +++ b/.changeset/36911-row-menu-approval-lock.md @@ -7,4 +7,4 @@ fix(plugin-grid): the row menu offers no Edit on a row held by a locking approva Clause-②: no Metadata-protocol: none -A grid row whose record is held by a pending approval with `lockRecord: true` is refused `RECORD_LOCKED` when it is updated. Its row menu still offered Edit, on the list page and on a record page's related tab. The menu now reads the same lock the grid's cells read (`POST /api/v1/approvals/records/:object/locks`), once per page, when a row's actions are first reached for. A row the lock read answered as locked offers no Edit, as the record page offers none. Delete stays, because deleting a locked record is allowed and cancels its request. When the lock cannot be read, the menu stays as it was: no approvals service (501), a row the reader cannot read, a failed read, or a read not yet asked. +A grid row whose record is held by its own pending approval with `lockRecord: true` is refused `RECORD_LOCKED` when it is updated. Its row menu still offered Edit, on the list page and on a record page's related tab. The menu now reads the same lock the grid's cells read (`POST /api/v1/approvals/records/:object/locks`), once per page, when a row's actions are first reached for. A row the lock read answered as locked offers no Edit, as the record page offers none. Delete stays, because a record held by its own approval may be deleted, and the delete cancels the request. The lock read does not report a detail line held because its master is held, so such lines keep both Edit and Delete in this menu, and the server refuses both. When the lock cannot be read, the menu stays as it was: no approvals service (501), a row the reader cannot read, a failed read, or a read not yet asked. diff --git a/ui/packages/plugin-grid/src/ObjectGrid.tsx b/ui/packages/plugin-grid/src/ObjectGrid.tsx index 05144f17170..5b8decfe247 100644 --- a/ui/packages/plugin-grid/src/ObjectGrid.tsx +++ b/ui/packages/plugin-grid/src/ObjectGrid.tsx @@ -1488,8 +1488,9 @@ export const ObjectGrid: React.FC = ({ // // objectstack#36911 — the row menu reads the same locks: a row an approval // locks offers no Edit, as the record page offers none (objectstack#35593). - // Delete stays: the server lets a locked record be deleted and cancels its - // request. So the hook also runs on a grid whose rows offer Edit. It still + // Delete stays for a record held by its own approval: the server deletes it + // and cancels its request. (The batch read reports only that case today, not + // a line held because its master is held, which refuses delete too; #37041.) So the hook also runs on a grid whose rows offer Edit. It still // reads nothing until it is asked: by a cell being selected, or by a row's // actions being reached for (`demandRowActions` below). const rowMenuOffersEdit = canEdit && !!onEdit; diff --git a/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx b/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx index c83873d6be2..f563b3cd8ab 100644 --- a/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx @@ -24,7 +24,7 @@ */ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; -import { render, screen, waitFor, cleanup, act } from '@testing-library/react'; +import { render, screen, waitFor, cleanup, act, fireEvent, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import '@testing-library/jest-dom'; import React from 'react'; @@ -48,6 +48,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => { import { ObjectGrid } from '../ObjectGrid'; import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts'; import { __resetApprovalsServiceLatch } from '../hooks/useRowApprovalLocks'; +import { useListPageScope } from '../listPageScope'; import { registerAllFields } from '@object-ui/fields'; import { ActionProvider, SchemaRendererProvider } from '@object-ui/react'; @@ -70,7 +71,17 @@ const server = { door: { kind: 'answers', locked: {} } as LockDoor, lockCalls: [] as Array<{ recordIds: string[] }>, responses: [] as Promise[], + /** Set by {@link hold}: lock answers wait here until `release` is called. */ + gate: null as Promise | null, + release: () => {}, + hold() { + server.gate = new Promise((resolve) => { + server.release = () => resolve(); + }); + }, reset() { + server.gate = null; + server.release = () => {}; server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false } }; server.lockCalls = []; server.responses = []; @@ -88,6 +99,7 @@ const apiFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise> = [LOCKED_ROW, OPEN_ROW]) { +/** The fixture page bar: it registers its page column as a list page scope. */ +const PageBar: React.FC = () => { + const [scope, setScope] = React.useState(null); + useListPageScope(scope); + return
setScope(el?.parentElement ?? null)} data-testid="page-bar" />; +}; + +function renderGrid( + rows: Array> = [LOCKED_ROW, OPEN_ROW], + { listPage = false }: { listPage?: boolean } = {}, +) { const dataSource: any = { getObjectSchema: async (name: string) => ({ name, @@ -126,11 +148,15 @@ function renderGrid(rows: Array> = [LOCKED_ROW, OPEN_ROW columns: [{ field: 'name', label: 'Name' }], data: { provider: 'value', items: rows }, pageSize: 500, + ...(listPage ? { selection: { type: 'multiple' } } : {}), }; return render( - {}} onDelete={() => {}} /> +
+ {listPage && } + {}} onDelete={() => {}} /> +
, ); @@ -229,3 +255,65 @@ describe('objectstack#36911 — the row menu follows the approval lock', () => { expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); }); }); + +/** + * The list page draws no "⋮" column (objectstack#35554): one selected record's + * actions are offered by the selection bar, which resolves them from the same + * row menu props. Edit is a bar button there; Delete is a button or behind + * 「More」. + */ +async function selectionBarOffers(label: string): Promise<{ edit: boolean; delete: boolean }> { + const row = screen.getByText(label).closest('tr')!; + fireEvent.click(within(row).getByRole('checkbox')); + const bar = await screen.findByTestId('bulk-actions-bar'); + await settleReads(); + const offers = () => ({ + edit: within(bar).queryByTestId('selection-action-edit') !== null + || screen.queryAllByTestId('row-action-builtin-edit').length > 0, + delete: within(bar).queryByTestId('selection-action-delete') !== null + || screen.queryAllByTestId('row-action-builtin-delete').length > 0, + }); + const more = within(bar).queryByTestId('selection-actions-more'); + if (more) await userEvent.click(more); + const answer = offers(); + if (more) await userEvent.keyboard('{Escape}'); + fireEvent.click(within(row).getByRole('checkbox')); + await waitFor(() => expect(screen.queryByTestId('bulk-actions-bar')).toBeNull()); + return answer; +} + +describe('objectstack#36911 — the list page selection bar follows the approval lock', () => { + it('a selected locked row offers no Edit and keeps Delete; a selected unlocked sibling keeps Edit', async () => { + const { container } = renderGrid([LOCKED_ROW, OPEN_ROW], { listPage: true }); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + // The list page scope: no Actions column, so the bar is the row's actions. + expect(container.querySelector('th[data-column-key="_actions"]')).toBeNull(); + expect(server.lockCalls).toHaveLength(0); + // CONTROL first: the unlocked row offers Edit through the bar, so the pin + // below observes the lock, not a bar that never shows Edit. + expect(await selectionBarOffers(OPEN_ROW.name)).toEqual({ edit: true, delete: true }); + expect(server.lockCalls).toHaveLength(1); + expect(await selectionBarOffers(LOCKED_ROW.name)).toEqual({ edit: false, delete: true }); + expect(server.lockCalls).toHaveLength(1); + }); +}); + +describe('objectstack#36911 — the read in flight', () => { + it('Edit shows while the lock read is on the wire, and leaves the open menu when it answers locked', async () => { + server.hold(); + renderGrid(); + await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); + const row = screen.getByText(LOCKED_ROW.name).closest('tr')!; + await userEvent.click(row.querySelector('[data-testid="row-action-trigger"]')!); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + // Unanswered: the menu is the one it always was. + expect(screen.getAllByTestId('row-action-builtin-edit').length).toBeGreaterThan(0); + expect(screen.getAllByTestId('row-action-builtin-delete').length).toBeGreaterThan(0); + await act(async () => { + server.release(); + await Promise.allSettled(server.responses); + }); + await waitFor(() => expect(screen.queryAllByTestId('row-action-builtin-edit')).toHaveLength(0)); + expect(screen.getAllByTestId('row-action-builtin-delete').length).toBeGreaterThan(0); + }); +}); diff --git a/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx b/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx index 2c0f37efe68..c420482ddd3 100644 --- a/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx +++ b/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx @@ -49,7 +49,11 @@ export function resolveObjectGridActionsColumn({ /** * objectstack#36911 — the approval locks of the rows on screen, the read the * select-first cells ask (`useRowApprovalLocks`). A row a read ANSWERED as - * locked offers no Edit; Delete is untouched. + * locked offers no Edit. Delete is untouched, which is right only while the + * read answers for a record held by ITS OWN approval: the server deletes such + * a record and cancels its request. A line held because its MASTER is held + * refuses delete too; if the read ever reports those lines, it must tell + * the two apart before this menu reads it (#37041). */ approvalLocks: RowApprovalLocks; /** @@ -99,8 +103,9 @@ export function resolveObjectGridActionsColumn({ // NON-AUTHOR SURFACE — see the `maxInlineActions` prop below. const maxInlineRowActions: number = foldInlineRowActions ? 0 : ((schema as any).maxInlineRowActions ?? 1); /** - * objectstack#36911 — is this row held by a locking approval, by a lock read - * that ANSWERED? The row is handed to the hook as no row at all, so its + * objectstack#36911 — is this row held by its own locking approval, by a lock + * read that ANSWERED? (The batch read answers for the record's own approval + * only, not for a line under a held master; see `approvalLocks` above.) The row is handed to the hook as no row at all, so its * `approval_status` column does not stand in: a read refused (501), failed, * answering `null` (a row the reader cannot read) or not yet asked leaves * Edit where the menu had it. An answer arriving re-renders the grid. The