Skip to content

Commit 4c64a0a

Browse files
committed
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 <noreply@anthropic.com>
1 parent d4f56f4 commit 4c64a0a

4 files changed

Lines changed: 103 additions & 9 deletions

File tree

‎.changeset/36911-row-menu-approval-lock.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ fix(plugin-grid): the row menu offers no Edit on a row held by a locking approva
77
Clause-②: no
88
Metadata-protocol: none
99

10-
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.
10+
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.

‎ui/packages/plugin-grid/src/ObjectGrid.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,8 +1488,9 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
14881488
//
14891489
// objectstack#36911 — the row menu reads the same locks: a row an approval
14901490
// locks offers no Edit, as the record page offers none (objectstack#35593).
1491-
// Delete stays: the server lets a locked record be deleted and cancels its
1492-
// request. So the hook also runs on a grid whose rows offer Edit. It still
1491+
// Delete stays for a record held by its own approval: the server deletes it
1492+
// and cancels its request. (The batch read reports only that case today, not
1493+
// 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
14931494
// reads nothing until it is asked: by a cell being selected, or by a row's
14941495
// actions being reached for (`demandRowActions` below).
14951496
const rowMenuOffersEdit = canEdit && !!onEdit;

‎ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx‎

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
27-
import { render, screen, waitFor, cleanup, act } from '@testing-library/react';
27+
import { render, screen, waitFor, cleanup, act, fireEvent, within } from '@testing-library/react';
2828
import userEvent from '@testing-library/user-event';
2929
import '@testing-library/jest-dom';
3030
import React from 'react';
@@ -48,6 +48,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
4848
import { ObjectGrid } from '../ObjectGrid';
4949
import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts';
5050
import { __resetApprovalsServiceLatch } from '../hooks/useRowApprovalLocks';
51+
import { useListPageScope } from '../listPageScope';
5152
import { registerAllFields } from '@object-ui/fields';
5253
import { ActionProvider, SchemaRendererProvider } from '@object-ui/react';
5354

@@ -70,7 +71,17 @@ const server = {
7071
door: { kind: 'answers', locked: {} } as LockDoor,
7172
lockCalls: [] as Array<{ recordIds: string[] }>,
7273
responses: [] as Promise<unknown>[],
74+
/** Set by {@link hold}: lock answers wait here until `release` is called. */
75+
gate: null as Promise<void> | null,
76+
release: () => {},
77+
hold() {
78+
server.gate = new Promise<void>((resolve) => {
79+
server.release = () => resolve();
80+
});
81+
},
7382
reset() {
83+
server.gate = null;
84+
server.release = () => {};
7485
server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false } };
7586
server.lockCalls = [];
7687
server.responses = [];
@@ -88,6 +99,7 @@ const apiFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<R
8899
};
89100
if (url === LOCKS_PATH) {
90101
server.lockCalls.push(body);
102+
if (server.gate) await server.gate;
91103
const door = server.door;
92104
if (door.kind === 'network') {
93105
const failed = Promise.reject(new TypeError('Failed to fetch'));
@@ -113,7 +125,17 @@ const apiFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<R
113125
});
114126
};
115127

116-
function renderGrid(rows: Array<Record<string, unknown>> = [LOCKED_ROW, OPEN_ROW]) {
128+
/** The fixture page bar: it registers its page column as a list page scope. */
129+
const PageBar: React.FC = () => {
130+
const [scope, setScope] = React.useState<HTMLElement | null>(null);
131+
useListPageScope(scope);
132+
return <div ref={(el) => setScope(el?.parentElement ?? null)} data-testid="page-bar" />;
133+
};
134+
135+
function renderGrid(
136+
rows: Array<Record<string, unknown>> = [LOCKED_ROW, OPEN_ROW],
137+
{ listPage = false }: { listPage?: boolean } = {},
138+
) {
117139
const dataSource: any = {
118140
getObjectSchema: async (name: string) => ({
119141
name,
@@ -126,11 +148,15 @@ function renderGrid(rows: Array<Record<string, unknown>> = [LOCKED_ROW, OPEN_ROW
126148
columns: [{ field: 'name', label: 'Name' }],
127149
data: { provider: 'value', items: rows },
128150
pageSize: 500,
151+
...(listPage ? { selection: { type: 'multiple' } } : {}),
129152
};
130153
return render(
131154
<ActionProvider>
132155
<SchemaRendererProvider dataSource={dataSource} apiFetch={apiFetch}>
133-
<ObjectGrid schema={schema} dataSource={dataSource} onEdit={() => {}} onDelete={() => {}} />
156+
<div data-testid="page-column">
157+
{listPage && <PageBar />}
158+
<ObjectGrid schema={schema} dataSource={dataSource} onEdit={() => {}} onDelete={() => {}} />
159+
</div>
134160
</SchemaRendererProvider>
135161
</ActionProvider>,
136162
);
@@ -229,3 +255,65 @@ describe('objectstack#36911 — the row menu follows the approval lock', () => {
229255
expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true });
230256
});
231257
});
258+
259+
/**
260+
* The list page draws no "⋮" column (objectstack#35554): one selected record's
261+
* actions are offered by the selection bar, which resolves them from the same
262+
* row menu props. Edit is a bar button there; Delete is a button or behind
263+
* 「More」.
264+
*/
265+
async function selectionBarOffers(label: string): Promise<{ edit: boolean; delete: boolean }> {
266+
const row = screen.getByText(label).closest('tr')!;
267+
fireEvent.click(within(row).getByRole('checkbox'));
268+
const bar = await screen.findByTestId('bulk-actions-bar');
269+
await settleReads();
270+
const offers = () => ({
271+
edit: within(bar).queryByTestId('selection-action-edit') !== null
272+
|| screen.queryAllByTestId('row-action-builtin-edit').length > 0,
273+
delete: within(bar).queryByTestId('selection-action-delete') !== null
274+
|| screen.queryAllByTestId('row-action-builtin-delete').length > 0,
275+
});
276+
const more = within(bar).queryByTestId('selection-actions-more');
277+
if (more) await userEvent.click(more);
278+
const answer = offers();
279+
if (more) await userEvent.keyboard('{Escape}');
280+
fireEvent.click(within(row).getByRole('checkbox'));
281+
await waitFor(() => expect(screen.queryByTestId('bulk-actions-bar')).toBeNull());
282+
return answer;
283+
}
284+
285+
describe('objectstack#36911 — the list page selection bar follows the approval lock', () => {
286+
it('a selected locked row offers no Edit and keeps Delete; a selected unlocked sibling keeps Edit', async () => {
287+
const { container } = renderGrid([LOCKED_ROW, OPEN_ROW], { listPage: true });
288+
await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument());
289+
// The list page scope: no Actions column, so the bar is the row's actions.
290+
expect(container.querySelector('th[data-column-key="_actions"]')).toBeNull();
291+
expect(server.lockCalls).toHaveLength(0);
292+
// CONTROL first: the unlocked row offers Edit through the bar, so the pin
293+
// below observes the lock, not a bar that never shows Edit.
294+
expect(await selectionBarOffers(OPEN_ROW.name)).toEqual({ edit: true, delete: true });
295+
expect(server.lockCalls).toHaveLength(1);
296+
expect(await selectionBarOffers(LOCKED_ROW.name)).toEqual({ edit: false, delete: true });
297+
expect(server.lockCalls).toHaveLength(1);
298+
});
299+
});
300+
301+
describe('objectstack#36911 — the read in flight', () => {
302+
it('Edit shows while the lock read is on the wire, and leaves the open menu when it answers locked', async () => {
303+
server.hold();
304+
renderGrid();
305+
await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument());
306+
const row = screen.getByText(LOCKED_ROW.name).closest('tr')!;
307+
await userEvent.click(row.querySelector('[data-testid="row-action-trigger"]')!);
308+
await waitFor(() => expect(server.lockCalls).toHaveLength(1));
309+
// Unanswered: the menu is the one it always was.
310+
expect(screen.getAllByTestId('row-action-builtin-edit').length).toBeGreaterThan(0);
311+
expect(screen.getAllByTestId('row-action-builtin-delete').length).toBeGreaterThan(0);
312+
await act(async () => {
313+
server.release();
314+
await Promise.allSettled(server.responses);
315+
});
316+
await waitFor(() => expect(screen.queryAllByTestId('row-action-builtin-edit')).toHaveLength(0));
317+
expect(screen.getAllByTestId('row-action-builtin-delete').length).toBeGreaterThan(0);
318+
});
319+
});

‎ui/packages/plugin-grid/src/objectGridActionsColumn.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export function resolveObjectGridActionsColumn({
4949
/**
5050
* objectstack#36911 — the approval locks of the rows on screen, the read the
5151
* select-first cells ask (`useRowApprovalLocks`). A row a read ANSWERED as
52-
* locked offers no Edit; Delete is untouched.
52+
* locked offers no Edit. Delete is untouched, which is right only while the
53+
* read answers for a record held by ITS OWN approval: the server deletes such
54+
* a record and cancels its request. A line held because its MASTER is held
55+
* refuses delete too; if the read ever reports those lines, it must tell
56+
* the two apart before this menu reads it (#37041).
5357
*/
5458
approvalLocks: RowApprovalLocks;
5559
/**
@@ -99,8 +103,9 @@ export function resolveObjectGridActionsColumn({
99103
// NON-AUTHOR SURFACE — see the `maxInlineActions` prop below.
100104
const maxInlineRowActions: number = foldInlineRowActions ? 0 : ((schema as any).maxInlineRowActions ?? 1);
101105
/**
102-
* objectstack#36911 — is this row held by a locking approval, by a lock read
103-
* that ANSWERED? The row is handed to the hook as no row at all, so its
106+
* objectstack#36911 — is this row held by its own locking approval, by a lock
107+
* read that ANSWERED? (The batch read answers for the record's own approval
108+
* 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
104109
* `approval_status` column does not stand in: a read refused (501), failed,
105110
* answering `null` (a row the reader cannot read) or not yet asked leaves
106111
* Edit where the menu had it. An answer arriving re-renders the grid. The

0 commit comments

Comments
 (0)