Repository navigation
Commit 40e22f1
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu3ktGWQBYiYJq1ThpuDKTbF)_
repo:objectstack#1 · os-sales · session_01L6bhgXSK9qt8je9QbZvhKb
Fixes #35795
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 列表里直接改格子时:如果这条记录「是否被审批锁住」或「我能不能改这条」还没查回来,双击、回车、F2
或直接打字都不会立刻弹出编辑框,格子上先显示「正在确认这条记录能否编辑…」;答案一回来,没锁就自动打开编辑框(打的那个字也保留),锁了就显示「此记录正在审批中,已锁定。」。不会再出现「能进编辑、保存才被拒」。
-
查询中点了别的格子,就放弃这次等待,不会突然在别处弹出编辑框。查询中点开关、粘贴、清空:同样先提示正在确认,答案回来没锁才写入,锁了就不写并说明原因。
- 一页数据只发一个锁查询:第一次点格子时把整页的锁一起问;之后用方向键走动不再发请求。新增服务端批量接口 `POST
/api/v1/approvals/records/:object/locks`(一次最多 200 条,读不到的记录和不存在的一样答
null),SDK 有对应方法。
- 风险:查询很慢时,用户第一次操作要等一下才出编辑框;没装审批服务的部署照旧(501 后不再问)。可直接撤回本 PR 回到原样。
- 需要你决定的:无。
## What changes
**Server (new route, contract, SDK).**
- `IApprovalService.getRecordLocks?(object, recordIds, context)`
(`packages/spec/src/contracts/approval-service.ts`, optional like
`getRecordLock`): entry `i` answers `recordIds[i]` exactly as
`getRecordLock` answers it (`{ locked }`, or `null` for an unreadable or
missing record, never told apart). New export
`APPROVAL_RECORD_LOCKS_MAX_RECORD_IDS = 200` (the explain batch's cap,
so a page splits the same way for both reads).
`api-surface/contracts.json` and `export-origins/contracts.json`
regenerated.
- `ApprovalService.getRecordLocks` (plugin-approvals): two engine reads
whatever the page size: the caller's `id $in` read of the ids (the same
anchor `getRecordLock` reads as the caller), then one pending-request
lookup judged by the record-lock hook's own judgement through the new
`recordsHeldByLockingApproval` (`lifecycle-hooks.ts`, the many-record
form of `recordHeldByLockingApproval` over the same
`lockingRequestsForRecords`).
- `POST /api/v1/approvals/records/:object/locks`
(`approvals-routes.ts`): body `{ "recordIds": [...] }` answers `{
success: true, data: { records: [{ recordId, locked }] } }` in order,
`locked: null` where the single read answers 404. Closed query set EMPTY
(`APPROVAL_RECORD_LOCKS_PARAMS`); the body is closed too
(`readRecordLocksBody`): any other key, a non-list, a non-string or
blank id, an empty list or more than the cap is refused whole with `400
VALIDATION_ERROR`, the service never asked. A service without
`getRecordLocks` answers 501, never one `getRecordLock` per id. Route
ledger row `sdk` → `client.approvals.getRecordLocks(object, recordIds)`.
**List grid.**
- `useRowApprovalLocks` asks the locks of the page in one request per
`APPROVAL_RECORD_LOCKS_MAX_RECORD_IDS` ids when a cell is first selected
(`ObjectGrid`'s `onCellSelect` passes the selected row plus the page's
ids); rows already asked are not asked again, rows a later page brings
are asked on the next select. It exposes `settling(recordId)`: the read
the row waits on while it is on the wire.
- `useRecordCrudVerdicts` exposes `settling()`: the explain questions on
the wire as one promise (read from a ref, so it sees a question sent
since the last render).
- `ObjectGrid.describeCell`: when the cell has no read-only reason yet
but the row's lock read, or its `update` verdict (when still unknown),
is on the wire, the facts carry `checking: { text, settled }`.
- `@object-ui/components` `GridCellFacts.checking` (optional, new):
`data-table`'s `attemptEdit` shows `text` on the cell, remembers the
edit (with its typed seed) and asks it again when `settled` settles,
unless another cell was selected, a newer edit was asked or an editor is
open by then. A toggle, paste or clear asked meanwhile shows `text` and
writes nothing (an intrinsic refusal such as "required" is still said
first).
- i18n: `grid.readOnlyReason.checking` in all 11 locales plus the
plugin's English fallback.
Docs: `content/docs/automation/approvals.mdx` ("Reading the locks of a
page of records"). Changeset
`.changeset/35795-batched-record-lock-read.md` (patch on the seven
packages the diff moves; `Metadata-protocol: none` ⇒ patch).
## Why
PR #35747 read a row's lock with one `GET …/:recordId/lock` per selected
row, sent on a double-click's first press and needed on its second. A
slower answer let the editor open on a locked record and only the save
was refused; the record verdict had the same window, and arrow keys sent
one read per row (the L2 record 7034067196, S3 and N2). #35684 rules out
「能进编辑、保存被拒」.
**Batch route over projection** (premise, accepted by the seat with the
claim 7072869185): the lock is the approvals plugin's own judgement;
projecting it into `GET /data/:object` would teach the data layer about
approvals or add a virtual-field protocol and charge every list read,
while a batch route is the same shape as the explain batch the list
already sends, asked only when the reader first acts on a cell.
## Small calls made in this thread (Sales 22:19:27Z: listed here)
- **Wait, then open** (the card's first arm) rather than "open nothing,
say checking": the premise proposed the latter; building it showed that
a real double-click on a fresh page (and every Playwright `dblclick`)
would then always need a second double-click. The waiting edit is
dropped by selecting another cell, so nothing opens elsewhere.
- The lock and verdict of a page are asked on the first cell select
(lazy, the #34208 posture), not on first paint.
- The same cap as explain (200); a body with any other key is refused,
like an unknown query name.
- A row the caller cannot read (`locked: null`) and a failed read fall
back to the `approval_status` column (fail open, as before; the server
still refuses a locked write).
- No principal key on the lock answers (unchanged from #35747): they are
dropped on any data change of the object and on unmount.
## Verification
Each new pin was run against the fix, then with the fix ablated.
- `ObjectGrid.cellSelection-35684.test.tsx`, new top-level `describe`
"an edit waits for the row's lock and verdict (objectstack#35795)", 7
cases with fake timers for the slow reads: a slow lock read on a locked
row says checking for 1999 ms and then locked, never an editor; on an
unlocked row the editor opens by itself when it answers; a key typed
while checking is the editor's value; a slow verdict holds it the same
way; selecting another cell drops the wait; a page sends one lock read
and the arrow keys send none (lock or explain); a 501 deployment is
asked once and edits. The existing lock case now reads the page in one
request. Ablating the `checking` branch of `attemptEdit`: 5 of the 7
red, restored.
- `rest-approvals-record-lock-route.test.ts`, new top-level `describe`
for the route: preservation (service asked once with the ids in order
and the caller; one entry per id; a full page at the cap), nine refusal
shapes (400 + nested `VALIDATION_ERROR` + service never called), the
empty closed query set, 501 when only `getRecordLock` exists (and it is
not called), a read refusal relayed at its own status.
- `record-lock-read.integration.test.ts` (real ObjectQL + better-sqlite3
+ `ApprovalsServicePlugin.start()`), new top-level `describe`: for each
of submitter, approver and a non-participant reader, the page answer
equals `getRecordLock` per id (repeated ids, unreadable, missing); two
engine reads for a page of three; an outsider is refused 403 as for one
record; a blank id answers null; deciding unlocks the page as the hook
does.
- `client.test.ts`: one POST, object segment encoded, body `{ recordIds
}`.
- Local runs on the merged tree: see the next section.
**Local runs** (merged tree, main `a5a5312f` + this branch, after `pnpm
install --frozen-lockfile && pnpm build`):
- `@objectstack/plugin-approvals` test: 126 files / 1,812 passed.
`@objectstack/client`: 59 / 820 passed. `@objectstack/spec`: 869 files /
27,877 passed. `@objectstack/rest`: first run 2 red (the two write-route
ledgers had no row for the new POST route); rows added (`no-record-echo`
in the #8497 tripwire, a driven `approvals.getRecordLocks` row in the
hook-refusal ledger), both files now 737 / 737.
- Typecheck clean: rest, plugin-approvals, client, spec, ui plugin-grid,
components, i18n.
- UI (`packages/plugin-grid/ components/ plugin-list/ plugin-detail/
i18n/`): first run 18 red in 4 files: a paste / toggle / digit was
dropped while checking (fixed: those writes now wait too, as the edit
does), and `zh-Hant.ts` was not regenerated (fixed with `gen:zh-hant`).
The six affected files then 102 / 102. A second full run of these
packages is in progress; its result goes on this PR.
- `spec check:generated`: `api-surface` and `export-origins` regenerated
(one line each). `overlap-check.mjs`: clean against main and every open
PR sharing a file (#36135, #36144, #36208).
- Added after the seat's ask: `ObjectGrid.autosave-35685.test.tsx`, new
top-level `describe` (2 cases, fake timers): a paste is not written for
1999 ms of a slow lock read and is written when it answers unlocked; on
a locked answer it is never written and the cell says why. Ablating the
wait in `writeCell`: both red, restored.
## Acceptance notes
- **#36135** (draft) makes `getRecordLock` also answer `true` for a
`master_detail` line of a locked record. This PR's batch answers the
record half only. Whichever lands second carries the other half into
`getRecordLocks` (the line half batched: one FK read of the page, one
lookup per master object). `overlap-check.mjs` reads this branch clean
against #36135 (it was moved off the lines #36135 edits).
- The notice text stays on the cell until the answer arrives or the
reader moves; it is not a toast.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(a contract interface member and a constant)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
maintainer's summary, in the maintainer's language).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgXSK9qt8je9QbZvhKb)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgXSK9qt8je9QbZvhKb
<!-- signed: repo:objectstack#1 · os-sales ·
session_01L6bhgXSK9qt8je9QbZvhKb -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent d8599c2 commit 40e22f1
34 files changed
Lines changed: 910 additions & 64 deletions
File tree
- .changeset
- content/docs/automation
- packages
- client/src
- plugins/plugin-approvals/src
- rest/src
- spec
- api-surface
- export-origins
- src/contracts
- ui/packages
- components/src
- context
- renderers/complex
- i18n/src/locales
- plugin-grid/src
- __tests__
- hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
432 | 455 | | |
433 | 456 | | |
434 | 457 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
766 | 766 | | |
767 | 767 | | |
768 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
769 | 781 | | |
770 | 782 | | |
771 | 783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7095 | 7095 | | |
7096 | 7096 | | |
7097 | 7097 | | |
| 7098 | + | |
| 7099 | + | |
| 7100 | + | |
| 7101 | + | |
| 7102 | + | |
| 7103 | + | |
| 7104 | + | |
| 7105 | + | |
| 7106 | + | |
| 7107 | + | |
| 7108 | + | |
| 7109 | + | |
| 7110 | + | |
| 7111 | + | |
| 7112 | + | |
| 7113 | + | |
| 7114 | + | |
| 7115 | + | |
| 7116 | + | |
| 7117 | + | |
7098 | 7118 | | |
7099 | 7119 | | |
7100 | 7120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
10992 | 10993 | | |
10993 | 10994 | | |
10994 | 10995 | | |
| 10996 | + | |
| 10997 | + | |
| 10998 | + | |
| 10999 | + | |
| 11000 | + | |
| 11001 | + | |
| 11002 | + | |
| 11003 | + | |
| 11004 | + | |
| 11005 | + | |
| 11006 | + | |
| 11007 | + | |
| 11008 | + | |
| 11009 | + | |
| 11010 | + | |
| 11011 | + | |
| 11012 | + | |
| 11013 | + | |
| 11014 | + | |
| 11015 | + | |
| 11016 | + | |
| 11017 | + | |
| 11018 | + | |
| 11019 | + | |
| 11020 | + | |
| 11021 | + | |
| 11022 | + | |
| 11023 | + | |
| 11024 | + | |
| 11025 | + | |
| 11026 | + | |
10995 | 11027 | | |
10996 | 11028 | | |
10997 | 11029 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
529 | 546 | | |
530 | 547 | | |
531 | 548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
181 | 231 | | |
182 | 232 | | |
183 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
82 | 132 | | |
83 | 133 | | |
84 | 134 | | |
| |||
466 | 516 | | |
467 | 517 | | |
468 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
469 | 556 | | |
470 | 557 | | |
471 | 558 | | |
| |||
0 commit comments