Skip to content

Commit 22bcc76

Browse files
fix(plugin-grid): ask row Edit/Delete verdicts when the row actions are first used, not on first paint (#34227)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi99LmuSk7wcyTfqmb94dVfij)_ Fixes #34208 Clause-②: no Metadata-protocol: none `ui/packages/plugin-grid/src/ObjectGrid.tsx` carries one added line (the hook call gains `updateOnMount: inlineEditable,`), added after #34213 merged (main 31eb2ae merged into this branch). ## 维护者速读 - 改了什么:列表首屏不再发 `POST /api/v1/security/explain`;用户第一次触及某行的操作(鼠标或焦点到操作格、打开「⋮」或右键菜单)时,整页一次性按操作各发一批。 - 为什么改:每个有行的列表首屏都多发两次 explain(各约 45 ms、50–60 条查询),是托管页加载的最后一层。 - 风险与回滚:答案到达前行沿用对象级判定(与今天答案到达前一致);菜单若在等答期间打开,Edit/Delete 显示为不可点;行内可编辑网格(opt-in)首屏仍发 1 次 `update`。首次使用发 2 次(update、delete 各一),卡上验收写「至多一次」,合成一次要改 spec 与服务端,不在本卡。回滚即 revert 本 PR。 - 先看:`ui/packages/plugin-grid/src/hooks/useRecordCrudVerdicts.ts`(`demanded` 与 `toAskFor`)、`ui/packages/plugin-grid/src/components/RowActionMenu.tsx`(触发点与 `verdictPending`)、`ui/packages/plugin-grid/src/ObjectGrid.tsx`(`updateOnMount: inlineEditable` 一行)。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx`,预期 22/22 通过,其中 `[objectstack#34208]` 一组 7 条。 - 需要你做的:无,席位落地。 ## What changes - `useRecordCrudVerdicts` asks nothing until a row-action surface calls `requestVerdicts()` (now carried on the returned lookup, beside `pending`). The first call asks once for the page, one batch per operation under the server's cap; later calls are free. Once asked, the list keeps its verdicts current as before (a new page, a data change re-asks the changed rows). Before the first ask, verdicts the module cache already holds are still published, and a data change asks nothing. - New option `updateOnMount` asks `update` when the rows arrive, for a surface that reads it while rendering. The inline-editable cells (objectstack#27365) are that surface; `ObjectGrid.tsx` passes `updateOnMount: inlineEditable`. - `RowActionMenu` gains two optional props. `onActionsDemand` is called on pointer-enter and focus of the actions cell, when the "⋮" opens, and when `RowActionMenuItems` mounts, which covers the row context menu too (it renders the same items). `crudVerdictPending` renders the built-in Edit or Delete as disabled with `aria-busy` while that row's answer is on the wire, so it cannot be clicked into a write the answer is about to refuse. - `objectGridActionsColumn.tsx` wires both from the hook's lookup into the props both menus read. - Request count on first use: **two** (one `update`, one `delete`), both lazily, on the first use only; zero at first paint; a second row's menu sends nothing. One request for both operations needs `operations: [...]` on the explain route, a spec and server change outside this card. - First open without a prior hover (keyboard): the menu shows Edit / Delete inert, then they become live or go when the answer lands. With a pointer the request leaves on hover, so it is usually answered before the click. - Docs: the plugin-grid README and `content/docs/frontend/plugins/plugin-grid.mdx` say when the verdict is asked. ## Tests New pins in `rowRecordCrudVerdict.test.tsx`, a top-level `describe('[objectstack#34208] …')` in the existing harness: - the first paint of a list with rows sends no explain request, and rows keep the object-level verdict; - opening a row's "⋮" by keyboard asks once for the page, one batch per operation, items are inert while the answer is held, and the open menu narrows to the answer; - a second row's menu sends nothing new, and a permitted row's items are live once answered; - a pointer reaching the actions cell asks before the menu opens; - the row context menu is a use of the row actions too; - a data change before any use asks nothing; after the first use it re-asks the changed row; - CONTROL: a non-OK answer to the first use keeps the object-level items, live (fail open). Forced test edits (each now reaches for the row actions, or asks through a helper, before reading a verdict; no assertion changed meaning): - `rowRecordCrudVerdict.test.tsx`: the existing pins call a new `reachRowActions()` (hover the first "⋮") before `settle(N)`; the pre-answer-window pin reaches before its held answer. - `serverGroupedVerdictProbe-32627.test.tsx`: both pins assert zero asks after the groups settle, then reach for the first row's "⋮" and count the same two requests over every row. - `hooks/useRecordCrudVerdicts.{afterAction-13341,batchCap,invalidation,principalScope}.test.tsx`: render the hook through the new `__tests__/askedRecordCrudVerdicts.ts` helper, which calls `requestVerdicts()` on mount. `inlineEditRecordVerdict-27365.test.tsx`: its 8 existing cases are unchanged (they were red on this branch until the `ObjectGrid.tsx` line landed, which is what they guard); a new top-level `describe('[objectstack#34208] …')` pins that an inline-editable grid's first paint asks `update` for the page and nothing else, and that opening a kebab then asks `delete` once. ## Acceptance notes - After the first use a list stays asked: paging to a new page asks for the new rows with that page's paint. The card's acceptance is about the list's first paint; this keeps the verdicts current for a user who has shown they act on rows here. - Grids that are inline-editable (`editable: true`, opt-in) will still send one explain request (`update`) after their rows arrive, because their cells read it while rendering. ## Verification Final head `1ca52c3e` (main 31eb2ae merged; install and the `@object-ui/plugin-grid^...` closure rebuilt after the merge). <details><summary>Local runs on 1ca52c3</summary> - `pnpm --dir ui exec vitest run packages/plugin-grid/` — Test Files 283 passed (283), Tests 2458 passed (2458); lock VERDICT command-exit 0. - `pnpm --filter @object-ui/plugin-grid type-check` — exit 0. </details> <details><summary>Ablations (ablation-replace, restore proven by blob == HEAD)</summary> - Eager fetch restored (`const toAskFor = demanded` replaced with an always-true condition): 7 red, including "the first paint of a list with rows sends no explain request". - Pending rule removed (`const disabled = verdictPending || (` with `false`): 1 red, "opening a row's ⋮ asks once for the page … the open menu narrows to the answer". - `updateOnMount: inlineEditable` replaced with `false` (on 1ca52c3): 9 red, every case of `inlineEditRecordVerdict-27365.test.tsx` including the new first-paint pin. </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` on 1ca52c3: 71 families, every one exit 0. `--ran`: 71 derived, 71 run, 0 NOT-MEASURED, 0 UNRUN. </details> --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRSP3ZjQXiwomqs6D6 <!-- signed: domain:ui#2 · os-steve · session_01ADHkmSzhXR4yUAgwq1bQRi --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a3570bc commit 22bcc76

15 files changed

Lines changed: 442 additions & 51 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
---
4+
5+
fix(plugin-grid): a list asks for its rows' Edit / Delete verdicts when the row actions are first used, not on first paint
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Every list view with rows sent two `POST /api/v1/security/explain` requests right after its data arrived, one for `update` and one for `delete`, to decide whether each row's menu offers Edit and Delete. Each costs the server tens of milliseconds and dozens of queries, and on a hosted page they were the last layer of the page load. The answer only matters to items a row shows inside its menus, so the grid now asks when a row's actions are first reached for: a pointer or the focus on the actions cell, the row's "⋮" opening, or the row context menu opening. That first use asks once for the whole page, one batch per operation. Opening another row's menu asks nothing new. Once asked, the list keeps the verdicts current as before, on a new page or after a data change.
11+
12+
Until the answer lands, every row keeps the object-level verdict, as it did before the answer arrived. A menu opened in that window shows Edit and Delete inert, so neither can be clicked into a write the answer is about to refuse. An item the answer refuses then goes. A failed or missing answer keeps the object-level verdict.
13+
14+
The exported `RowActionMenu` takes two new optional props: `onActionsDemand`, called when the row's actions are reached for, and `crudVerdictPending`, which shows the built-in Edit or Delete inert. A menu that passes neither behaves as before.

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ caller's **delete** or **update** grant. A closed row removes the button, and
175175
with it the dialog, its undo and its retry. `custom` entries are unchanged.
176176
With no permission provider mounted both read open.
177177

178+
Edit and Delete also fold the server's verdict on each row: `writeScope`,
179+
sharing rules and row-level security can refuse a record the object grant
180+
allows. The grid asks for that verdict (`POST /api/v1/security/explain`, one
181+
batch per operation for the rows on the page) when a row's actions are first
182+
reached for — a pointer or the focus on the actions cell, or a row menu opening
183+
— and never on the list's first paint. Until the answer lands every row keeps
184+
the object-level verdict, and an open menu shows Edit and Delete inert; an item
185+
the answer refuses then goes. A failed or missing answer keeps the object-level
186+
verdict.
187+
178188
### Row callbacks are component props
179189

180190
`onRowClick`, `onRowSelect`, `onCellChange`, `onRowSave`, `onBatchSave`,

‎ui/packages/plugin-grid/README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,16 @@ const schema: ObjectGridBlockNode = {
791791
};
792792
```
793793

794+
Edit and Delete also fold the server's verdict on each row: `writeScope`,
795+
sharing rules and row-level security can refuse a record the object grant
796+
allows. The grid asks for that verdict (`POST /api/v1/security/explain`, one
797+
batch per operation for the rows on the page) when a row's actions are first
798+
reached for — a pointer or the focus on the actions cell, or a row menu opening
799+
— and never on the list's first paint. Until the answer lands every row keeps
800+
the object-level verdict, and an open menu shows Edit and Delete inert; an item
801+
the answer refuses then goes. A failed or missing answer keeps the object-level
802+
verdict.
803+
794804
### Row callbacks are component props
795805

796806
`onRowClick`, `onRowSelect`, `onCellChange`, `onRowSave`, `onBatchSave`, `onEdit`,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,8 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
10961096
recordIds: pageRecordIds,
10971097
update: canEdit || inlineEditable,
10981098
delete: canDelete,
1099+
// objectstack#34208 — inline cells read `update` while rendering, before any row action is used.
1100+
updateOnMount: inlineEditable,
10991101
});
11001102

11011103
// The projection keys and the filter, sort, search and server-paging state,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* `useRecordCrudVerdicts` as a list whose row actions have been reached for.
11+
*
12+
* The hook asks the explain engine nothing until a row-action surface calls
13+
* `requestVerdicts` (objectstack#34208): the first paint of a list sends no
14+
* explain request. The suites that pin what the hook does ONCE it asks — the
15+
* batching, the cap, the cache, the re-checks after a change, the principal
16+
* scope — render it through this, which asks on mount, so each of them keeps
17+
* pinning the behaviour it was written for. What the hook does BEFORE anyone
18+
* asks is pinned where the asking happens: `rowRecordCrudVerdict.test.tsx`.
19+
*/
20+
import * as React from 'react';
21+
import { useRecordCrudVerdicts } from '../hooks/useRecordCrudVerdicts';
22+
23+
export function useAskedRecordCrudVerdicts(
24+
opts: Parameters<typeof useRecordCrudVerdicts>[0],
25+
): ReturnType<typeof useRecordCrudVerdicts> {
26+
const verdicts = useRecordCrudVerdicts(opts);
27+
const { requestVerdicts } = verdicts;
28+
// A repeat call is free, so a new callback identity costs nothing here.
29+
React.useEffect(() => {
30+
requestVerdicts();
31+
}, [requestVerdicts]);
32+
return verdicts;
33+
}

‎ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,27 @@ describe('fail OPEN — no answer keeps the object-level behaviour (objectstack#
276276
expect(await clickOpensEditor(OTHER_ROW.name)).toBe(false);
277277
});
278278
});
279+
280+
/**
281+
* [objectstack#34208] A list asks the record verdicts only once its row actions
282+
* are reached for — but the inline cells read `update` while they render, so an
283+
* inline-editable grid still asks `update` when its rows arrive. `delete` is
284+
* read only by the row menus, and waits for them.
285+
*/
286+
describe('[objectstack#34208] an inline-editable grid asks `update` on first render, `delete` on first use', () => {
287+
it('the first paint asks `update` for the page and nothing else; opening a kebab then asks `delete` once', async () => {
288+
renderGrid();
289+
await settle();
290+
await act(async () => {
291+
await new Promise((resolve) => setTimeout(resolve, 50));
292+
});
293+
expect(server.calls.map((call) => call.operation)).toEqual(['update']);
294+
expect([...(server.calls[0].recordIds ?? [])].sort()).toEqual([OTHER_ROW.id, OWN_ROW.id].sort());
295+
296+
expect(await kebabOffersEdit(OWN_ROW.name)).toBe(true);
297+
await act(async () => {
298+
await Promise.allSettled(server.responses);
299+
});
300+
expect(server.calls.map((call) => call.operation)).toEqual(['update', 'delete']);
301+
});
302+
});

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

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
4040
import { EXPLAIN_BATCH_MAX_RECORD_IDS } from '@objectstack/spec/security';
41-
import { render, screen, waitFor, cleanup, act } from '@testing-library/react';
41+
import { render, screen, waitFor, cleanup, act, fireEvent } from '@testing-library/react';
4242
import userEvent from '@testing-library/user-event';
4343
import '@testing-library/jest-dom';
4444
import React from 'react';
@@ -72,7 +72,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
7272
import { ObjectGrid } from '../ObjectGrid';
7373
import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts';
7474
import { registerAllFields } from '@object-ui/fields';
75-
import { ActionProvider, SchemaRendererProvider } from '@object-ui/react';
75+
import { ActionProvider, SchemaRendererProvider, notifyDataChanged } from '@object-ui/react';
7676
// READ-ONLY reference to the OTHER surface's real implementation. The agreement
7777
// pin is worth nothing against a local re-statement of the detail header's
7878
// logic: it has to consume the same hook `RecordDetailView` consumes, unchanged
@@ -257,6 +257,16 @@ async function rowKebab(label: string): Promise<{ edit: boolean; delete: boolean
257257
return answer;
258258
}
259259

260+
/**
261+
* [objectstack#34208] Reach for a row's actions the way a pointer does —
262+
* hover the "⋮" — which is when the grid asks for the record verdicts. The
263+
* first paint asks nothing; every pin below that reads a verdict reaches first.
264+
*/
265+
async function reachRowActions() {
266+
const trigger = screen.getAllByTestId('row-action-trigger')[0];
267+
await userEvent.hover(trigger);
268+
}
269+
260270
beforeEach(() => {
261271
server.reset();
262272
__clearRecordCrudVerdictCache();
@@ -273,6 +283,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => {
273283
// Pre-fix this returned `{ edit: true, delete: true }` — the whole card.
274284
renderGrid();
275285
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
286+
await reachRowActions();
276287
await settle(2);
277288
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: false, delete: false });
278289
});
@@ -283,6 +294,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => {
283294
// wearing a bug fix's clothes.
284295
renderGrid();
285296
await waitFor(() => expect(screen.getByText(OWN_ROW.name)).toBeInTheDocument());
297+
await reachRowActions();
286298
await settle(2);
287299
expect(await rowKebab(OWN_ROW.name)).toEqual({ edit: true, delete: true });
288300
});
@@ -293,6 +305,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => {
293305
// ONE decision, so a row with nothing left must not sprout an empty menu.
294306
renderGrid();
295307
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
308+
await reachRowActions();
296309
await settle(2);
297310
const deniedRow = screen.getByText(OTHER_ROW.name).closest('tr');
298311
expect(deniedRow?.querySelector('[data-testid="row-action-trigger"]')).toBeNull();
@@ -306,6 +319,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => {
306319
server.verdicts.set(OTHER_ROW.id, { update: false, delete: true });
307320
renderGrid();
308321
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
322+
await reachRowActions();
309323
await settle(2);
310324
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: false, delete: true });
311325
});
@@ -328,6 +342,7 @@ describe('[#4296] kebab answer == detail-header answer, for the same record and
328342
});
329343
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
330344
// 2 batch calls (one per operation, for the page) + 4 singular probes.
345+
await reachRowActions();
331346
await settle(6);
332347

333348
// The detail header's own verdicts, measured first and independently.
@@ -371,6 +386,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi
371386
server.ok = false;
372387
renderGrid();
373388
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
389+
await reachRowActions();
374390
await settle(2);
375391
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true });
376392
});
@@ -379,6 +395,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi
379395
server.network = false;
380396
renderGrid();
381397
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
398+
await reachRowActions();
382399
await settle(2);
383400
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true });
384401
});
@@ -387,6 +404,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi
387404
server.answersBatch = false;
388405
renderGrid();
389406
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
407+
await reachRowActions();
390408
await settle(2);
391409
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true });
392410
});
@@ -408,6 +426,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi
408426
server.hold();
409427
renderGrid();
410428
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
429+
await reachRowActions();
411430
await waitFor(() => expect(server.calls.length).toBe(2));
412431
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true });
413432
// …and once the verdict lands, the entries go.
@@ -435,6 +454,7 @@ describe('[#4296] one batched call per (object, operation) per page', () => {
435454
// text is no readiness signal: on this many rows the settled re-render
436455
// outran the wait. The rows being on screen is: count them.
437456
await waitFor(() => expect(container.querySelectorAll('tbody tr')).toHaveLength(rows.length));
457+
await reachRowActions();
438458
await settle(2);
439459

440460
expect(server.calls.length).toBe(2);
@@ -470,6 +490,7 @@ describe('[#4296] one batched call per (object, operation) per page', () => {
470490
// text is no readiness signal: on this many rows the settled re-render
471491
// outran the wait. The rows being on screen is: count them.
472492
await waitFor(() => expect(container.querySelectorAll('tbody tr')).toHaveLength(rows.length));
493+
await reachRowActions();
473494
await settle(4);
474495

475496
expect(server.calls.length).toBe(4);
@@ -506,6 +527,7 @@ describe('[#4296] the record layer intersects, never unions', () => {
506527
server.verdicts.set(OTHER_ROW.id, { update: true, delete: true });
507528
renderGrid({ permDelete: false });
508529
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
530+
await reachRowActions();
509531
await settle(1);
510532
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: false });
511533
expect(server.calls.map((c) => c.operation)).toEqual(['update']);
@@ -519,3 +541,128 @@ describe('[#4296] the record layer intersects, never unions', () => {
519541
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: false, delete: false });
520542
});
521543
});
544+
545+
/**
546+
* [objectstack#34208] The verdicts are asked when a row's actions are reached
547+
* for, never on first paint. Each batch costs the server tens of milliseconds
548+
* and dozens of queries, and the answer only matters to items a row shows
549+
* inside its menus — so the list paints without asking, and the first reach
550+
* for a row's actions asks once for the whole page.
551+
*/
552+
describe('[objectstack#34208] verdicts are asked on first use of the row actions, not on first paint', () => {
553+
/** Let every effect the first paint scheduled run and every read it started land. */
554+
async function firstPaintSettled() {
555+
await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument());
556+
await act(async () => {
557+
await new Promise((resolve) => setTimeout(resolve, 50));
558+
});
559+
}
560+
561+
const triggerOf = (label: string) =>
562+
screen.getByText(label).closest('tr')!.querySelector<HTMLElement>('[data-testid="row-action-trigger"]')!;
563+
564+
it('the first paint of a list with rows sends no explain request, and rows keep the object-level verdict', async () => {
565+
renderGrid();
566+
await firstPaintSettled();
567+
expect(server.calls).toEqual([]);
568+
// Fail open meanwhile: the server would refuse this row, nobody asked yet.
569+
const deniedRow = screen.getByText(OTHER_ROW.name).closest('tr');
570+
expect(deniedRow?.querySelector('[data-testid="row-action-trigger"]')).not.toBeNull();
571+
});
572+
573+
it('opening a row\'s "⋮" asks once for the page — one batch per operation — and the open menu narrows to the answer', async () => {
574+
server.hold();
575+
renderGrid();
576+
await firstPaintSettled();
577+
expect(server.calls).toEqual([]);
578+
579+
// Open the menu without a hover first (a keyboard press on the trigger).
580+
triggerOf(OTHER_ROW.name).focus();
581+
await userEvent.keyboard('{Enter}');
582+
await waitFor(() => expect(server.calls).toHaveLength(2));
583+
expect(server.calls.map((c) => c.operation).sort()).toEqual(['delete', 'update']);
584+
for (const call of server.calls) expect(call.recordIds).toEqual(ROWS.map((r) => r.id));
585+
586+
// While the answer is on the wire the items show, inert: neither can be
587+
// clicked into a write the answer is about to refuse.
588+
const edit = screen.getByTestId('row-action-builtin-edit');
589+
const del = screen.getByTestId('row-action-builtin-delete');
590+
expect(edit).toHaveAttribute('aria-disabled', 'true');
591+
expect(del).toHaveAttribute('aria-disabled', 'true');
592+
expect(edit).toHaveAttribute('aria-busy', 'true');
593+
594+
server.release();
595+
await settle(2);
596+
// The answer refuses both, so the open menu has nothing left and the row
597+
// grows no "⋮" (#3562's invariant, unchanged).
598+
await waitFor(() => expect(screen.queryByTestId('row-action-builtin-edit')).toBeNull());
599+
expect(screen.queryByTestId('row-action-builtin-delete')).toBeNull();
600+
expect(screen.getByText(OTHER_ROW.name).closest('tr')?.querySelector('[data-testid="row-action-trigger"]')).toBeNull();
601+
});
602+
603+
it('a second row\'s menu sends nothing new, and a permitted row\'s items are live once answered', async () => {
604+
server.hold();
605+
renderGrid();
606+
await firstPaintSettled();
607+
// The first row's menu, opened while the answer is on the wire.
608+
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true });
609+
server.release();
610+
await settle(2);
611+
612+
const ownTrigger = triggerOf(OWN_ROW.name);
613+
await userEvent.click(ownTrigger);
614+
const edit = screen.getByTestId('row-action-builtin-edit');
615+
expect(edit).not.toHaveAttribute('aria-disabled');
616+
expect(edit).not.toHaveAttribute('aria-busy');
617+
await userEvent.keyboard('{Escape}');
618+
expect(server.calls).toHaveLength(2);
619+
});
620+
621+
it('a pointer reaching the actions cell asks before the menu opens, so the answer can be in hand by the click', async () => {
622+
renderGrid();
623+
await firstPaintSettled();
624+
await userEvent.hover(triggerOf(OWN_ROW.name));
625+
await settle(2);
626+
// Answered before any menu opened: the denied row's "⋮" is already gone.
627+
expect(screen.getByText(OTHER_ROW.name).closest('tr')?.querySelector('[data-testid="row-action-trigger"]')).toBeNull();
628+
});
629+
630+
it('the row context menu is a use of the row actions too', async () => {
631+
renderGrid();
632+
await firstPaintSettled();
633+
const cell = screen.getByText(OWN_ROW.name).closest('td')!;
634+
act(() => {
635+
fireEvent.contextMenu(cell, { button: 2, clientX: 40, clientY: 60 });
636+
});
637+
await settle(2);
638+
});
639+
640+
it('a data change before any use asks nothing; after the first use it re-asks the changed row', async () => {
641+
renderGrid();
642+
await firstPaintSettled();
643+
act(() => notifyDataChanged({ objectName: OBJECT, recordId: OTHER_ROW.id }));
644+
await act(async () => {
645+
await new Promise((resolve) => setTimeout(resolve, 50));
646+
});
647+
expect(server.calls).toEqual([]);
648+
649+
await reachRowActions();
650+
await settle(2);
651+
act(() => notifyDataChanged({ objectName: OBJECT, recordId: OWN_ROW.id }));
652+
await settle(4);
653+
expect(server.calls.slice(2).map((c) => c.recordIds)).toEqual([[OWN_ROW.id], [OWN_ROW.id]]);
654+
});
655+
656+
it('CONTROL: a non-OK answer to the first use keeps the object-level items, live (fail open)', async () => {
657+
server.ok = false;
658+
renderGrid();
659+
await firstPaintSettled();
660+
await reachRowActions();
661+
await settle(2);
662+
expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true });
663+
await userEvent.click(triggerOf(OTHER_ROW.name));
664+
expect(screen.getByTestId('row-action-builtin-edit')).not.toHaveAttribute('aria-disabled');
665+
expect(screen.getByTestId('row-action-builtin-delete')).not.toHaveAttribute('aria-disabled');
666+
await userEvent.keyboard('{Escape}');
667+
});
668+
});

0 commit comments

Comments
 (0)