You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 22bcc76
Browse filesBrowse the repository at this point in the historyBrowse 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>
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.
0 commit comments