diff --git a/.changeset/34208-row-verdicts-on-first-use.md b/.changeset/34208-row-verdicts-on-first-use.md new file mode 100644 index 00000000000..00700d19832 --- /dev/null +++ b/.changeset/34208-row-verdicts-on-first-use.md @@ -0,0 +1,14 @@ +--- +'@object-ui/plugin-grid': patch +--- + +fix(plugin-grid): a list asks for its rows' Edit / Delete verdicts when the row actions are first used, not on first paint + +Clause-②: no +Metadata-protocol: none + +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. + +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. + +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. diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index 325a339cf7f..29c39fb02ea 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -175,6 +175,16 @@ caller's **delete** or **update** grant. A closed row removes the button, and with it the dialog, its undo and its retry. `custom` entries are unchanged. With no permission provider mounted both read open. +Edit and Delete also fold the server's verdict on each row: `writeScope`, +sharing rules and row-level security can refuse a record the object grant +allows. The grid asks for that verdict (`POST /api/v1/security/explain`, one +batch per operation for the rows on the page) when a row's actions are first +reached for — a pointer or the focus on the actions cell, or a row menu opening +— and never on the list's first paint. Until the answer lands every row keeps +the object-level verdict, and an open menu shows Edit and Delete inert; an item +the answer refuses then goes. A failed or missing answer keeps the object-level +verdict. + ### Row callbacks are component props `onRowClick`, `onRowSelect`, `onCellChange`, `onRowSave`, `onBatchSave`, diff --git a/ui/packages/plugin-grid/README.md b/ui/packages/plugin-grid/README.md index cc072094159..c5cd0fda3ad 100644 --- a/ui/packages/plugin-grid/README.md +++ b/ui/packages/plugin-grid/README.md @@ -791,6 +791,16 @@ const schema: ObjectGridBlockNode = { }; ``` +Edit and Delete also fold the server's verdict on each row: `writeScope`, +sharing rules and row-level security can refuse a record the object grant +allows. The grid asks for that verdict (`POST /api/v1/security/explain`, one +batch per operation for the rows on the page) when a row's actions are first +reached for — a pointer or the focus on the actions cell, or a row menu opening +— and never on the list's first paint. Until the answer lands every row keeps +the object-level verdict, and an open menu shows Edit and Delete inert; an item +the answer refuses then goes. A failed or missing answer keeps the object-level +verdict. + ### Row callbacks are component props `onRowClick`, `onRowSelect`, `onCellChange`, `onRowSave`, `onBatchSave`, `onEdit`, diff --git a/ui/packages/plugin-grid/src/ObjectGrid.tsx b/ui/packages/plugin-grid/src/ObjectGrid.tsx index a4af40e0efd..ace4f03a25a 100644 --- a/ui/packages/plugin-grid/src/ObjectGrid.tsx +++ b/ui/packages/plugin-grid/src/ObjectGrid.tsx @@ -1096,6 +1096,8 @@ export const ObjectGrid: React.FC = ({ recordIds: pageRecordIds, update: canEdit || inlineEditable, delete: canDelete, + // objectstack#34208 — inline cells read `update` while rendering, before any row action is used. + updateOnMount: inlineEditable, }); // The projection keys and the filter, sort, search and server-paging state, diff --git a/ui/packages/plugin-grid/src/__tests__/askedRecordCrudVerdicts.ts b/ui/packages/plugin-grid/src/__tests__/askedRecordCrudVerdicts.ts new file mode 100644 index 00000000000..8cbec3667a7 --- /dev/null +++ b/ui/packages/plugin-grid/src/__tests__/askedRecordCrudVerdicts.ts @@ -0,0 +1,33 @@ +/** + * 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. + */ + +/** + * `useRecordCrudVerdicts` as a list whose row actions have been reached for. + * + * The hook asks the explain engine nothing until a row-action surface calls + * `requestVerdicts` (objectstack#34208): the first paint of a list sends no + * explain request. The suites that pin what the hook does ONCE it asks — the + * batching, the cap, the cache, the re-checks after a change, the principal + * scope — render it through this, which asks on mount, so each of them keeps + * pinning the behaviour it was written for. What the hook does BEFORE anyone + * asks is pinned where the asking happens: `rowRecordCrudVerdict.test.tsx`. + */ +import * as React from 'react'; +import { useRecordCrudVerdicts } from '../hooks/useRecordCrudVerdicts'; + +export function useAskedRecordCrudVerdicts( + opts: Parameters[0], +): ReturnType { + const verdicts = useRecordCrudVerdicts(opts); + const { requestVerdicts } = verdicts; + // A repeat call is free, so a new callback identity costs nothing here. + React.useEffect(() => { + requestVerdicts(); + }, [requestVerdicts]); + return verdicts; +} 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 7b454980914..ac6d0334e4d 100644 --- a/ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/inlineEditRecordVerdict-27365.test.tsx @@ -276,3 +276,27 @@ describe('fail OPEN — no answer keeps the object-level behaviour (objectstack# expect(await clickOpensEditor(OTHER_ROW.name)).toBe(false); }); }); + +/** + * [objectstack#34208] A list asks the record verdicts only once its row actions + * are reached for — but the inline cells read `update` while they render, so an + * inline-editable grid still asks `update` when its rows arrive. `delete` is + * read only by the row menus, and waits for them. + */ +describe('[objectstack#34208] an inline-editable grid asks `update` on first render, `delete` on first use', () => { + it('the first paint asks `update` for the page and nothing else; opening a kebab then asks `delete` once', async () => { + renderGrid(); + await settle(); + await act(async () => { + await new Promise((resolve) => setTimeout(resolve, 50)); + }); + expect(server.calls.map((call) => call.operation)).toEqual(['update']); + expect([...(server.calls[0].recordIds ?? [])].sort()).toEqual([OTHER_ROW.id, OWN_ROW.id].sort()); + + expect(await kebabOffersEdit(OWN_ROW.name)).toBe(true); + await act(async () => { + await Promise.allSettled(server.responses); + }); + expect(server.calls.map((call) => call.operation)).toEqual(['update', 'delete']); + }); +}); diff --git a/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx b/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx index 11aed818c43..d03ef015f5f 100644 --- a/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/rowRecordCrudVerdict.test.tsx @@ -38,7 +38,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { EXPLAIN_BATCH_MAX_RECORD_IDS } from '@objectstack/spec/security'; -import { render, screen, waitFor, cleanup, act } from '@testing-library/react'; +import { render, screen, waitFor, cleanup, act, fireEvent } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import '@testing-library/jest-dom'; import React from 'react'; @@ -72,7 +72,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => { import { ObjectGrid } from '../ObjectGrid'; import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts'; import { registerAllFields } from '@object-ui/fields'; -import { ActionProvider, SchemaRendererProvider } from '@object-ui/react'; +import { ActionProvider, SchemaRendererProvider, notifyDataChanged } from '@object-ui/react'; // READ-ONLY reference to the OTHER surface's real implementation. The agreement // pin is worth nothing against a local re-statement of the detail header's // 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 return answer; } +/** + * [objectstack#34208] Reach for a row's actions the way a pointer does — + * hover the "⋮" — which is when the grid asks for the record verdicts. The + * first paint asks nothing; every pin below that reads a verdict reaches first. + */ +async function reachRowActions() { + const trigger = screen.getAllByTestId('row-action-trigger')[0]; + await userEvent.hover(trigger); +} + beforeEach(() => { server.reset(); __clearRecordCrudVerdictCache(); @@ -273,6 +283,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => { // Pre-fix this returned `{ edit: true, delete: true }` — the whole card. renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: false, delete: false }); }); @@ -283,6 +294,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => { // wearing a bug fix's clothes. renderGrid(); await waitFor(() => expect(screen.getByText(OWN_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); expect(await rowKebab(OWN_ROW.name)).toEqual({ edit: true, delete: true }); }); @@ -293,6 +305,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => { // ONE decision, so a row with nothing left must not sprout an empty menu. renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); const deniedRow = screen.getByText(OTHER_ROW.name).closest('tr'); expect(deniedRow?.querySelector('[data-testid="row-action-trigger"]')).toBeNull(); @@ -306,6 +319,7 @@ describe('[#4296] the row kebab folds the record-level verdict', () => { server.verdicts.set(OTHER_ROW.id, { update: false, delete: true }); renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: false, delete: true }); }); @@ -328,6 +342,7 @@ describe('[#4296] kebab answer == detail-header answer, for the same record and }); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); // 2 batch calls (one per operation, for the page) + 4 singular probes. + await reachRowActions(); await settle(6); // 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 server.ok = false; renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true }); }); @@ -379,6 +395,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi server.network = false; renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true }); }); @@ -387,6 +404,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi server.answersBatch = false; renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(2); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true }); }); @@ -408,6 +426,7 @@ describe('[#4296] degradation — an unanswered row keeps the object-level verdi server.hold(); renderGrid(); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await waitFor(() => expect(server.calls.length).toBe(2)); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true }); // …and once the verdict lands, the entries go. @@ -435,6 +454,7 @@ describe('[#4296] one batched call per (object, operation) per page', () => { // text is no readiness signal: on this many rows the settled re-render // outran the wait. The rows being on screen is: count them. await waitFor(() => expect(container.querySelectorAll('tbody tr')).toHaveLength(rows.length)); + await reachRowActions(); await settle(2); expect(server.calls.length).toBe(2); @@ -470,6 +490,7 @@ describe('[#4296] one batched call per (object, operation) per page', () => { // text is no readiness signal: on this many rows the settled re-render // outran the wait. The rows being on screen is: count them. await waitFor(() => expect(container.querySelectorAll('tbody tr')).toHaveLength(rows.length)); + await reachRowActions(); await settle(4); expect(server.calls.length).toBe(4); @@ -506,6 +527,7 @@ describe('[#4296] the record layer intersects, never unions', () => { server.verdicts.set(OTHER_ROW.id, { update: true, delete: true }); renderGrid({ permDelete: false }); await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await reachRowActions(); await settle(1); expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: false }); expect(server.calls.map((c) => c.operation)).toEqual(['update']); @@ -519,3 +541,128 @@ describe('[#4296] the record layer intersects, never unions', () => { expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: false, delete: false }); }); }); + +/** + * [objectstack#34208] The verdicts are asked when a row's actions are reached + * for, never on first paint. Each batch costs the server tens of milliseconds + * and dozens of queries, and the answer only matters to items a row shows + * inside its menus — so the list paints without asking, and the first reach + * for a row's actions asks once for the whole page. + */ +describe('[objectstack#34208] verdicts are asked on first use of the row actions, not on first paint', () => { + /** Let every effect the first paint scheduled run and every read it started land. */ + async function firstPaintSettled() { + await waitFor(() => expect(screen.getByText(OTHER_ROW.name)).toBeInTheDocument()); + await act(async () => { + await new Promise((resolve) => setTimeout(resolve, 50)); + }); + } + + const triggerOf = (label: string) => + screen.getByText(label).closest('tr')!.querySelector('[data-testid="row-action-trigger"]')!; + + it('the first paint of a list with rows sends no explain request, and rows keep the object-level verdict', async () => { + renderGrid(); + await firstPaintSettled(); + expect(server.calls).toEqual([]); + // Fail open meanwhile: the server would refuse this row, nobody asked yet. + const deniedRow = screen.getByText(OTHER_ROW.name).closest('tr'); + expect(deniedRow?.querySelector('[data-testid="row-action-trigger"]')).not.toBeNull(); + }); + + it('opening a row\'s "⋮" asks once for the page — one batch per operation — and the open menu narrows to the answer', async () => { + server.hold(); + renderGrid(); + await firstPaintSettled(); + expect(server.calls).toEqual([]); + + // Open the menu without a hover first (a keyboard press on the trigger). + triggerOf(OTHER_ROW.name).focus(); + await userEvent.keyboard('{Enter}'); + await waitFor(() => expect(server.calls).toHaveLength(2)); + expect(server.calls.map((c) => c.operation).sort()).toEqual(['delete', 'update']); + for (const call of server.calls) expect(call.recordIds).toEqual(ROWS.map((r) => r.id)); + + // While the answer is on the wire the items show, inert: neither can be + // clicked into a write the answer is about to refuse. + const edit = screen.getByTestId('row-action-builtin-edit'); + const del = screen.getByTestId('row-action-builtin-delete'); + expect(edit).toHaveAttribute('aria-disabled', 'true'); + expect(del).toHaveAttribute('aria-disabled', 'true'); + expect(edit).toHaveAttribute('aria-busy', 'true'); + + server.release(); + await settle(2); + // The answer refuses both, so the open menu has nothing left and the row + // grows no "⋮" (#3562's invariant, unchanged). + await waitFor(() => expect(screen.queryByTestId('row-action-builtin-edit')).toBeNull()); + expect(screen.queryByTestId('row-action-builtin-delete')).toBeNull(); + expect(screen.getByText(OTHER_ROW.name).closest('tr')?.querySelector('[data-testid="row-action-trigger"]')).toBeNull(); + }); + + it('a second row\'s menu sends nothing new, and a permitted row\'s items are live once answered', async () => { + server.hold(); + renderGrid(); + await firstPaintSettled(); + // The first row's menu, opened while the answer is on the wire. + expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true }); + server.release(); + await settle(2); + + const ownTrigger = triggerOf(OWN_ROW.name); + await userEvent.click(ownTrigger); + const edit = screen.getByTestId('row-action-builtin-edit'); + expect(edit).not.toHaveAttribute('aria-disabled'); + expect(edit).not.toHaveAttribute('aria-busy'); + await userEvent.keyboard('{Escape}'); + expect(server.calls).toHaveLength(2); + }); + + it('a pointer reaching the actions cell asks before the menu opens, so the answer can be in hand by the click', async () => { + renderGrid(); + await firstPaintSettled(); + await userEvent.hover(triggerOf(OWN_ROW.name)); + await settle(2); + // Answered before any menu opened: the denied row's "⋮" is already gone. + expect(screen.getByText(OTHER_ROW.name).closest('tr')?.querySelector('[data-testid="row-action-trigger"]')).toBeNull(); + }); + + it('the row context menu is a use of the row actions too', async () => { + renderGrid(); + await firstPaintSettled(); + const cell = screen.getByText(OWN_ROW.name).closest('td')!; + act(() => { + fireEvent.contextMenu(cell, { button: 2, clientX: 40, clientY: 60 }); + }); + await settle(2); + }); + + it('a data change before any use asks nothing; after the first use it re-asks the changed row', async () => { + renderGrid(); + await firstPaintSettled(); + act(() => notifyDataChanged({ objectName: OBJECT, recordId: OTHER_ROW.id })); + await act(async () => { + await new Promise((resolve) => setTimeout(resolve, 50)); + }); + expect(server.calls).toEqual([]); + + await reachRowActions(); + await settle(2); + act(() => notifyDataChanged({ objectName: OBJECT, recordId: OWN_ROW.id })); + await settle(4); + expect(server.calls.slice(2).map((c) => c.recordIds)).toEqual([[OWN_ROW.id], [OWN_ROW.id]]); + }); + + it('CONTROL: a non-OK answer to the first use keeps the object-level items, live (fail open)', async () => { + server.ok = false; + renderGrid(); + await firstPaintSettled(); + await reachRowActions(); + await settle(2); + expect(await rowKebab(OTHER_ROW.name)).toEqual({ edit: true, delete: true }); + await userEvent.click(triggerOf(OTHER_ROW.name)); + expect(screen.getByTestId('row-action-builtin-edit')).not.toHaveAttribute('aria-disabled'); + expect(screen.getByTestId('row-action-builtin-delete')).not.toHaveAttribute('aria-disabled'); + await userEvent.keyboard('{Escape}'); + }); +}); diff --git a/ui/packages/plugin-grid/src/__tests__/serverGroupedVerdictProbe-32627.test.tsx b/ui/packages/plugin-grid/src/__tests__/serverGroupedVerdictProbe-32627.test.tsx index b10d6c95489..4a8f6c5d1b3 100644 --- a/ui/packages/plugin-grid/src/__tests__/serverGroupedVerdictProbe-32627.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/serverGroupedVerdictProbe-32627.test.tsx @@ -25,7 +25,8 @@ * the list's own budget and not a smaller number reached by asking nothing. */ import { describe, it, expect, vi, afterEach, beforeAll, beforeEach } from 'vitest'; -import { render, cleanup } from '@testing-library/react'; +import { render, cleanup, screen, act } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import '@testing-library/jest-dom'; import React from 'react'; @@ -105,6 +106,19 @@ async function settled(ds: ReturnType, finds: number) { await new Promise((resolve) => setTimeout(resolve, 15 * PERIODS.length + 200)); } +/** + * objectstack#34208 — the grid asks nothing until a row's actions are reached + * for, so each pin first holds that the paint asked nothing, then reaches for + * the first row's "⋮" and counts what that one use costs. + */ +async function reachRowActions() { + expect(explainAsks(calls)).toEqual([]); + await userEvent.hover(screen.getAllByTestId('row-action-trigger')[0]); + await act(async () => { + await new Promise((resolve) => setTimeout(resolve, 50)); + }); +} + let calls: ExplainDoubleCall[]; beforeEach(() => { __clearRecordCrudVerdictCache(); @@ -120,6 +134,7 @@ describe('a grouped grid asks the row write verdict once per operation (objectst const ds = makeDataSource(); renderGrid(ds, { grouping: { fields: [{ field: 'period_label' }] } }); await settled(ds, PERIODS.length); + await reachRowActions(); expect(explainAsks(calls)).toEqual([ { operation: 'update', ids: ALL_IDS }, @@ -131,6 +146,7 @@ describe('a grouped grid asks the row write verdict once per operation (objectst const ds = makeDataSource(); renderGrid(ds, {}); await settled(ds, 1); + await reachRowActions(); expect(explainAsks(calls)).toEqual([ { operation: 'update', ids: ALL_IDS }, diff --git a/ui/packages/plugin-grid/src/components/RowActionMenu.tsx b/ui/packages/plugin-grid/src/components/RowActionMenu.tsx index 9976197a404..d08785a2b95 100644 --- a/ui/packages/plugin-grid/src/components/RowActionMenu.tsx +++ b/ui/packages/plugin-grid/src/components/RowActionMenu.tsx @@ -162,6 +162,21 @@ export interface RowActionMenuProps { * `record.owner == os.user.id` can be true (see `toPredicateRecord`). */ objectFields?: unknown; + /** + * This row's actions are about to be used (objectstack#34208): called when a + * pointer or the focus reaches the row's actions cell, when its "⋮" opens, + * and when any menu holding its items mounts (the row context menu among + * them). The grid asks the record-grained Edit / Delete verdicts only from + * here, never on first paint; a call after the first is free. + */ + onActionsDemand?: () => void; + /** + * The record-grained verdict for the built-in item is on its way + * (objectstack#34208). The item still shows — the object-level verdict + * stands until the answer lands — but inert, so it cannot be clicked into a + * write the answer is about to refuse. + */ + crudVerdictPending?: { edit?: boolean; delete?: boolean }; } // --------------------------------------------------------------------------- @@ -467,7 +482,9 @@ export const BuiltinRowActionItem: React.FC<{ className?: string; objectFields?: unknown; onSelect: (row: any) => void; -}> = ({ name, predicates, row, icon, label, className, objectFields, onSelect }) => { + /** The record-grained verdict is on its way: shown, but inert (objectstack#34208). */ + verdictPending?: boolean; +}> = ({ name, predicates, row, icon, label, className, objectFields, onSelect, verdictPending = false }) => { // `visibleWhen` is read through the shared `isBuiltinRowActionVisible`, the // same function the "⋮" guard counts with — see objectui#3562. const scope = usePredicateScope(); @@ -482,10 +499,11 @@ export const BuiltinRowActionItem: React.FC<{ fields: objectFields, }); if (!isVisible) return null; - const disabled = predicates?.disabledWhen != null && isDisabled; + const disabled = verdictPending || (predicates?.disabledWhen != null && isDisabled); return ( { if (!disabled) onSelect(row); }} data-testid={`row-action-builtin-${name}`} className={className} @@ -672,7 +690,16 @@ export const RowActionMenuItems: React.FC<{ props: RowActionMenuProps; }> = ({ plan, props }) => { const t = useRowActionTranslation(); - const { row, editPredicates, deletePredicates, objectFields, onEdit, onDelete, onAction, onActionDef } = props; + const { + row, editPredicates, deletePredicates, objectFields, onEdit, onDelete, onAction, onActionDef, crudVerdictPending, + } = props; + // [objectstack#34208] A menu showing this row's items is the row's actions + // in use — whichever menu hosts them. A repeat call is free, so a new + // callback identity re-running this costs nothing. + const { onActionsDemand } = props; + React.useEffect(() => { + onActionsDemand?.(); + }, [onActionsDemand]); return ( <> {/* Rendered off the PLAN, the same object the trigger's existence @@ -687,6 +714,7 @@ export const RowActionMenuItems: React.FC<{ icon={} label={t('grid.edit')} objectFields={objectFields} + verdictPending={!!crudVerdictPending?.edit} onSelect={(r) => onEdit?.(r)} /> )} @@ -698,6 +726,7 @@ export const RowActionMenuItems: React.FC<{ icon={} label={t('grid.delete')} objectFields={objectFields} + verdictPending={!!crudVerdictPending?.delete} onSelect={(r) => onDelete?.(r)} /> )} @@ -724,7 +753,7 @@ export const RowActionMenuItems: React.FC<{ }; export const RowActionMenu: React.FC = (props) => { - const { row, objectFields, onActionDef, maxInlineActions = 1 } = props; + const { row, objectFields, onActionDef, onActionsDemand, maxInlineActions = 1 } = props; const t = useRowActionTranslation(); // The one resolver both of this row's menus read (objectstack#28434). const plan = useRowActionPlan(props, maxInlineActions); @@ -735,7 +764,15 @@ export const RowActionMenu: React.FC = (props) => { // a grid with no actions at all has always produced. const hasMenu = plan.menuCount > 0; return ( -
e.stopPropagation()}> +
e.stopPropagation()} + // [objectstack#34208] Reaching the cell is the earliest sign the row's + // actions are wanted: asking here usually lands the answer before the + // "⋮" opens. Focus covers the keyboard, pointer covers mouse and touch. + onPointerEnter={onActionsDemand} + onFocus={onActionsDemand} + > {plan.inline.map(def => ( = (props) => { /> ))} {hasMenu && ( - + { if (open) onActionsDemand?.(); }}>