Skip to content

Commit d88c41e

Browse files
fix(plugin-grid): the row menu offers no Delete on a line whose master is held (#37296)
Fixes #37231 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:列表页和相关列表里,主单正在审批中的明细行(如费用报销明细),行菜单和选中栏不再出现「删除」;自身在审批中的记录仍可删除。 - 为什么做:审批锁定的列表收口工作的一部分,服务端早已拒绝这种删除,界面现在提前不提供。 - 出错会怎样:最坏情况是某行该删的「删除」被隐藏或仍然出现;只影响按钮显示,不写数据,可直接撤回。 - 要你做什么:无 ## What changes - `useRowApprovalLocks` now keeps the batch lock door's `lockSource` (`'record'` or `'master'`) for a row answered `locked: true`, and exposes `heldByMaster(recordId)`. It answers `true` only for a row a read answered `lockSource: 'master'`. A 501, a `null` entry, a failed or unasked read, and a record-held row all answer `false`. - The grid's row CRUD verdict (`objectGridActionsColumn.tsx`) ANDs `!heldByMaster` into `canDelete`. The row menu, the row context menu and the list page's single-row selection bar all read the same `rowActionMenuProps`, so they all drop Delete on a master-held line. A record-held row keeps Delete and loses Edit, as before (#13568). - `ObjectGrid.tsx`: the lock hook is also enabled, and the demand probe also sent, on a grid whose rows offer Delete but no Edit (`rowMenuReadsLocks = (canEdit && onEdit) || (canDelete && onDelete)`). Without this, a Delete-only grid never read the lock and kept Delete on a master-held line. The read is still sent only on demand, never on first paint. - The column docblock and the `ObjectGrid.tsx` hook comment no longer say that a master-held line keeps Edit and Delete. - One `patch` changeset for `@object-ui/plugin-grid`. Read first, in order of risk: 1. `ui/packages/plugin-grid/src/ObjectGrid.tsx`, the `rowMenuReadsLocks` hunk: a Delete-only grid now sends a lock read when a row's actions are reached for. 2. `ui/packages/plugin-grid/src/hooks/useRowApprovalLocks.ts`, the `answered.set` hunk: `lockSource` is kept only on a `locked: true` entry, and only for one of the two values. 3. `ui/packages/plugin-grid/src/objectGridActionsColumn.tsx`, the `canDelete` line. Two-minute check: `cd ui && pnpm exec vitest run packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx` should report 10 passed, including the three tests under `objectstack#37231`. ## Tests The new pins are a top-level `describe` in the existing harness `rowMenuApprovalLock-36911.test.tsx`: - A master-held line offers neither Edit nor Delete. A record-held sibling offers no Edit and keeps Delete. An open sibling offers both (the control). - A grid with `onDelete` and no `onEdit` reads the lock on demand and drops Delete on the master-held line. The open row keeps Delete. - On the list page selection bar, a master-held line offers neither. A record-held sibling keeps Delete, and there is one lock read in total. - The 501, `null` and failed-read controls now include a master-held line, and each leaves its menu unchanged. ## Acceptance notes - The cell-select path (`describeCell` → `approvalLocked`) still reads only the boolean. Both lock kinds refuse an update, so the boolean is enough there. - A `locked: true` entry with no `lockSource` (an older server) reads as record-held, which is the behaviour before this PR. - Not measured in a browser against the showcase expense lines. The pins drive the real `ObjectGrid` against a fake lock door. - The ablation proves only the master arm in the column verdict. The `rowMenuReadsLocks` widening has no ablation of its own. Its pin is the Delete-only test, which went red under the column ablation only because that ablation removes the downstream effect. ## Verification All readings below were taken at commit 929d5f0 in objectstack. <details><summary>Harness file, plugin-grid suite, type-check</summary> ```text harness: cd ui && vitest run packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx Test Files 1 passed (1) Tests 10 passed (10) os-verify-lock: VERDICT command-exit 0 plugin-grid suite: cd ui && vitest run --maxWorkers=2 packages/plugin-grid/ Test Files 313 passed (313) Tests 2786 passed (2786) os-verify-lock: VERDICT command-exit 0 pnpm --filter @object-ui/plugin-grid type-check os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation: drop the master arm</summary> ```text node scripts/ablation-replace.mjs --file ui/packages/plugin-grid/src/objectGridActionsColumn.tsx --anchor " && !heldByMasterAnswered(row)" --delete -- (vitest on the harness file) ablation-replace: ok mutation landed: anchor 1 -> 0, blob d9d2a54 -> 2fcebc3668cf x a master-held line offers neither Edit nor Delete; a record-held sibling offers no Edit and keeps Delete x a grid whose rows offer Delete but no Edit still reads the lock, and drops Delete on the master-held line x the list page selection bar: a selected master-held line offers neither; a selected record-held sibling keeps Delete Tests 3 failed | 7 passed (10) ablation-replace: ok restored: blob == HEAD (d9d2a54) and `git diff HEAD` is empty ``` Two earlier attempts were refused or invalid and are not counted. The first used the anchor with a trailing comma and the replacement `,`: the tool refused it as a no-op and restored the file before any test ran. The second deleted the comma along with the anchor: that broke the syntax, so the file collected no tests. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 59a53a6 commit d88c41e

5 files changed

Lines changed: 148 additions & 28 deletions

File tree

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): the row menu offers no Delete on a line whose master is held
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The grid row menu reads the batch approval-lock door (`POST /api/v1/approvals/records/:object/locks`) when a row's actions are reached for, and a row the door answers as locked offers no Edit. The door also says which approval holds the row, in `lockSource`: `'record'` (its own approval) or `'master'` (for a master-detail line, its master's approval). The menu read only the boolean, so a line whose master is held kept Delete, and the server refused that delete with `RECORD_LOCKED`.
11+
12+
The menu now reads `lockSource`. A row answered `lockSource: 'master'` offers neither Edit nor Delete. A row answered `lockSource: 'record'` offers no Edit and keeps Delete, as before: the server deletes such a record and cancels its request. The list page's single-row selection bar reads the same row props, so it follows. A 501, a `null` entry, a failed read or a read not yet asked leaves the menu as it was.
13+
14+
A grid whose rows offer Delete but no Edit now also reads the locks when a row's actions are reached for, so the rule holds there too. The read is still never sent on first paint.

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,12 +1489,14 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
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).
14911491
// 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
1492+
// and cancels its request. objectstack#37231 — a master-detail line held
1493+
// because its MASTER is held (the read's `lockSource: 'master'`) offers no
1494+
// Delete either: the detail-row lock hook refuses it with `RECORD_LOCKED`.
1495+
// So the hook also runs on a grid whose rows offer Edit or Delete. It still
14941496
// reads nothing until it is asked: by a cell being selected, or by a row's
14951497
// actions being reached for (`demandRowActions` below).
1496-
const rowMenuOffersEdit = canEdit && !!onEdit;
1497-
const approvalLocks = useRowApprovalLocks(hostCellSelection || rowMenuOffersEdit ? objectName : undefined);
1498+
const rowMenuReadsLocks = (canEdit && !!onEdit) || (canDelete && !!onDelete);
1499+
const approvalLocks = useRowApprovalLocks(hostCellSelection || rowMenuReadsLocks ? objectName : undefined);
14981500
/**
14991501
* objectstack#36911 — what reaching for a row's actions asks
15001502
* (`RowActionMenuProps.onActionsDemand`, objectstack#34208): the
@@ -1506,8 +1508,8 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
15061508
const probeApprovalLocks = approvalLocks.probe;
15071509
const demandRowActions = useCallback(() => {
15081510
requestRecordVerdicts();
1509-
if (rowMenuOffersEdit) probeApprovalLocks(pageRecordIds);
1510-
}, [requestRecordVerdicts, probeApprovalLocks, rowMenuOffersEdit, pageRecordIds]);
1511+
if (rowMenuReadsLocks) probeApprovalLocks(pageRecordIds);
1512+
}, [requestRecordVerdicts, probeApprovalLocks, rowMenuReadsLocks, pageRecordIds]);
15111513
// objectstack#35956 — a cell change that makes other fields required asks
15121514
// for them first, and saves them with it (`./objectGridRequiredPrompt`).
15131515
const fieldLabelOf = (field: string): string => {

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

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
* are reached for, never on first paint (objectstack#35795). Only an ANSWERED
2222
* lock hides Edit: a 501, a `null` entry, a failed read or a read not yet
2323
* asked leaves the menu as it was.
24+
*
25+
* objectstack#37231 — the read says which approval holds a locked row
26+
* (`lockSource`). A master-detail line held because its MASTER is held
27+
* (`'master'`) offers no Delete either: the detail-row lock hook refuses that
28+
* delete with `RECORD_LOCKED`. A row held by its own approval (`'record'`)
29+
* keeps Delete.
2430
*/
2531

2632
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
@@ -60,10 +66,15 @@ const LOCKS_PATH = `/api/v1/approvals/records/${OBJECT}/locks`;
6066
const LOCKED_ROW = { id: 'p_locked', name: 'Data Centre Build' };
6167
/** Its sibling on the same page, with no approval running. */
6268
const OPEN_ROW = { id: 'p_open', name: 'Office Refresh' };
69+
/** A master-detail line whose MASTER is under a locking approval. */
70+
const MASTER_HELD_ROW = { id: 'p_line', name: 'Rack Delivery' };
6371

64-
/** What the lock door answers, per id; `undefined` is the read's `null` entry. */
72+
/**
73+
* What the lock door answers, per id; `undefined` is the read's `null` entry.
74+
* `sources` is the `lockSource` a locked entry carries.
75+
*/
6576
type LockDoor =
66-
| { kind: 'answers'; locked: Record<string, boolean | null> }
77+
| { kind: 'answers'; locked: Record<string, boolean | null>; sources?: Record<string, 'record' | 'master'> }
6778
| { kind: 'status'; status: number }
6879
| { kind: 'network' };
6980

@@ -82,7 +93,11 @@ const server = {
8293
reset() {
8394
server.gate = null;
8495
server.release = () => {};
85-
server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false } };
96+
server.door = {
97+
kind: 'answers',
98+
locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false, [MASTER_HELD_ROW.id]: true },
99+
sources: { [LOCKED_ROW.id]: 'record', [MASTER_HELD_ROW.id]: 'master' },
100+
};
86101
server.lockCalls = [];
87102
server.responses = [];
88103
},
@@ -110,7 +125,13 @@ const apiFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<R
110125
const ids: string[] = body.recordIds ?? [];
111126
return respond(200, {
112127
success: true,
113-
data: { records: ids.map((recordId) => ({ recordId, locked: door.locked[recordId] ?? null })) },
128+
data: {
129+
records: ids.map((recordId) => ({
130+
recordId,
131+
locked: door.locked[recordId] ?? null,
132+
...(door.sources?.[recordId] ? { lockSource: door.sources[recordId] } : {}),
133+
})),
134+
},
114135
});
115136
}
116137
// `security/explain`: every row may be written, so only the lock can take Edit away.
@@ -134,7 +155,7 @@ const PageBar: React.FC = () => {
134155

135156
function renderGrid(
136157
rows: Array<Record<string, unknown>> = [LOCKED_ROW, OPEN_ROW],
137-
{ listPage = false }: { listPage?: boolean } = {},
158+
{ listPage = false, edit = true }: { listPage?: boolean; edit?: boolean } = {},
138159
) {
139160
const dataSource: any = {
140161
getObjectSchema: async (name: string) => ({
@@ -155,7 +176,7 @@ function renderGrid(
155176
<SchemaRendererProvider dataSource={dataSource} apiFetch={apiFetch}>
156177
<div data-testid="page-column">
157178
{listPage && <PageBar />}
158-
<ObjectGrid schema={schema} dataSource={dataSource} onEdit={() => {}} onDelete={() => {}} />
179+
<ObjectGrid schema={schema} dataSource={dataSource} onEdit={edit ? () => {} : undefined} onDelete={() => {}} />
159180
</div>
160181
</SchemaRendererProvider>
161182
</ActionProvider>,
@@ -224,35 +245,42 @@ describe('objectstack#36911 — the row menu follows the approval lock', () => {
224245

225246
it('a 501 (no approvals service) leaves the menu as it was, even over an approval_status column', async () => {
226247
server.door = { kind: 'status', status: 501 };
227-
renderGrid([{ ...LOCKED_ROW, approval_status: 'pending' }, OPEN_ROW]);
248+
renderGrid([{ ...LOCKED_ROW, approval_status: 'pending' }, OPEN_ROW, MASTER_HELD_ROW]);
228249
await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument());
229250
await reachRowActions();
230251
await waitFor(() => expect(server.lockCalls).toHaveLength(1));
231252
await settleReads();
232253
expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true });
233254
expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: true, delete: true });
255+
expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true });
234256
});
235257

236258
it('a null entry (a row the reader cannot read) leaves Edit where it was', async () => {
237-
server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: null, [OPEN_ROW.id]: false } };
238-
renderGrid();
259+
server.door = {
260+
kind: 'answers',
261+
locked: { [LOCKED_ROW.id]: null, [OPEN_ROW.id]: false, [MASTER_HELD_ROW.id]: null },
262+
};
263+
renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW]);
239264
await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument());
240265
await reachRowActions();
241266
await waitFor(() => expect(server.lockCalls).toHaveLength(1));
242267
await settleReads();
243268
expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true });
269+
expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true });
244270
});
245271

246272
it('a read that fails, or that never answered, leaves Edit where it was', async () => {
247273
server.door = { kind: 'network' };
248-
renderGrid();
274+
renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW]);
249275
await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument());
250276
// Not asked yet: the menu is the one it always was.
251277
expect(server.lockCalls).toHaveLength(0);
278+
expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true });
252279
await reachRowActions();
253280
await waitFor(() => expect(server.lockCalls).toHaveLength(1));
254281
await settleReads();
255282
expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true });
283+
expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true });
256284
});
257285
});
258286

@@ -317,3 +345,39 @@ describe('objectstack#36911 — the read in flight', () => {
317345
expect(screen.getAllByTestId('row-action-builtin-delete').length).toBeGreaterThan(0);
318346
});
319347
});
348+
349+
describe('objectstack#37231 — a line whose master is held offers no Delete', () => {
350+
it('a master-held line offers neither Edit nor Delete; a record-held sibling offers no Edit and keeps Delete', async () => {
351+
renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW]);
352+
await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name)).toBeInTheDocument());
353+
await reachRowActions();
354+
await waitFor(() => expect(server.lockCalls).toHaveLength(1));
355+
await settleReads();
356+
// CONTROL: the open sibling offers both, so the pins observe the lock.
357+
expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: true, delete: true });
358+
await waitFor(async () => expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: false, delete: false }));
359+
expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: false, delete: true });
360+
});
361+
362+
it('a grid whose rows offer Delete but no Edit still reads the lock, and drops Delete on the master-held line', async () => {
363+
renderGrid([OPEN_ROW, MASTER_HELD_ROW], { edit: false });
364+
await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name)).toBeInTheDocument());
365+
expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: false, delete: true });
366+
await waitFor(() => expect(server.lockCalls).toHaveLength(1));
367+
await settleReads();
368+
await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name).closest('tr')
369+
?.querySelector('[data-testid="row-action-trigger"]') ?? null).toBeNull());
370+
expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: false, delete: false });
371+
expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: false, delete: true });
372+
});
373+
374+
it('the list page selection bar: a selected master-held line offers neither; a selected record-held sibling keeps Delete', async () => {
375+
renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW], { listPage: true });
376+
await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name)).toBeInTheDocument());
377+
expect(await selectionBarOffers(OPEN_ROW.name)).toEqual({ edit: true, delete: true });
378+
expect(server.lockCalls).toHaveLength(1);
379+
expect(await selectionBarOffers(MASTER_HELD_ROW.name)).toEqual({ edit: false, delete: false });
380+
expect(await selectionBarOffers(LOCKED_ROW.name)).toEqual({ edit: false, delete: true });
381+
expect(server.lockCalls).toHaveLength(1);
382+
});
383+
});

‎ui/packages/plugin-grid/src/hooks/useRowApprovalLocks.ts‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
* grid already says of the selected cell (its `aria-readonly`) follows the
3535
* lock without waiting for the reader to move: `isLocked`, and the value this
3636
* hook returns, are new exactly when the answers it reads changed.
37+
*
38+
* The door also says WHICH approval holds a locked row (`lockSource`): its own
39+
* (`'record'`), or, for a master-detail line, its master's (`'master'`, which
40+
* wins when both hold). `heldByMaster` reads that bit for the row menu: the
41+
* server deletes a record held by its own approval and cancels the request,
42+
* but the detail-row lock hook refuses a line's delete while its master is
43+
* held (objectstack#37231).
3744
*/
3845
import * as React from 'react';
3946
import { APPROVAL_RECORD_LOCKS_MAX_RECORD_IDS } from '@objectstack/spec/contracts';
@@ -53,7 +60,10 @@ export function __resetApprovalsServiceLatch(): void {
5360
* back to its `approval_status` column (fail open: the server still refuses a
5461
* write to a locked record).
5562
*/
56-
type LockAnswer = { locked: boolean } | 'asking' | 'unanswered';
63+
type LockAnswer = { locked: boolean; lockSource?: ApprovalLockSource } | 'asking' | 'unanswered';
64+
65+
/** Which approval holds a locked row: its own, or its master's (a master-detail line). */
66+
export type ApprovalLockSource = 'record' | 'master';
5767

5868
export interface RowApprovalLocks {
5969
/**
@@ -63,6 +73,13 @@ export interface RowApprovalLocks {
6373
probe: (recordIds: readonly unknown[]) => void;
6474
/** Whether the row is locked by an approval, from what has answered so far. */
6575
isLocked: (recordId: unknown, row: any) => boolean;
76+
/**
77+
* Whether a read ANSWERED the row as held by its master's approval
78+
* (`lockSource: 'master'`). Only an answer says so: a read refused (501),
79+
* failed, answering `null`, or not yet asked answers `false`, and so does a
80+
* row held by its own approval.
81+
*/
82+
heldByMaster: (recordId: unknown) => boolean;
6683
/** The row's lock read while it is on the wire (it settles when it answers or fails), else `null`. */
6784
settling: (recordId: unknown) => Promise<void> | null;
6885
}
@@ -121,7 +138,10 @@ export function useRowApprovalLocks(objectName: string | undefined): RowApproval
121138
chunk.forEach((id, index) => {
122139
const entry = records[index];
123140
if (entry && entry.recordId === id && typeof entry.locked === 'boolean') {
124-
answered.set(id, { locked: entry.locked });
141+
const lockSource = entry.locked && (entry.lockSource === 'record' || entry.lockSource === 'master')
142+
? entry.lockSource as ApprovalLockSource
143+
: undefined;
144+
answered.set(id, lockSource ? { locked: entry.locked, lockSource } : { locked: entry.locked });
125145
}
126146
});
127147
}
@@ -154,10 +174,19 @@ export function useRowApprovalLocks(objectName: string | undefined): RowApproval
154174
}).locked;
155175
}, [answerSeq]);
156176

177+
const heldByMaster = React.useCallback((recordId: unknown) => {
178+
void answerSeq;
179+
const answer = recordId == null ? undefined : answersRef.current.get(String(recordId));
180+
return typeof answer === 'object' && answer.locked && answer.lockSource === 'master';
181+
}, [answerSeq]);
182+
157183
const settling = React.useCallback(
158184
(recordId: unknown) => (recordId == null ? null : wiresRef.current.get(String(recordId)) ?? null),
159185
[],
160186
);
161187

162-
return React.useMemo(() => ({ probe, isLocked, settling }), [probe, isLocked, settling]);
188+
return React.useMemo(
189+
() => ({ probe, isLocked, heldByMaster, settling }),
190+
[probe, isLocked, heldByMaster, settling],
191+
);
163192
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ export function resolveObjectGridActionsColumn({
5151
/**
5252
* objectstack#36911 — the approval locks of the rows on screen, the read the
5353
* select-first cells ask (`useRowApprovalLocks`). A row a read ANSWERED as
54-
* locked offers no Edit. Delete is untouched, which is right only while the
55-
* read answers for a record held by ITS OWN approval: the server deletes such
56-
* a record and cancels its request. A line held because its MASTER is held
57-
* refuses delete too; if the read ever reports those lines, it must tell
58-
* the two apart before this menu reads it (#37041).
54+
* locked offers no Edit. objectstack#37231 — the read says which approval
55+
* holds it (`lockSource`): a record held by ITS OWN approval keeps Delete,
56+
* because the server deletes such a record and cancels its request; a
57+
* master-detail line held because its MASTER is held (`lockSource:
58+
* 'master'`) offers no Delete either, because the detail-row lock hook
59+
* refuses that delete with `RECORD_LOCKED`.
5960
*/
6061
approvalLocks: RowApprovalLocks;
6162
/**
@@ -105,16 +106,23 @@ export function resolveObjectGridActionsColumn({
105106
// NON-AUTHOR SURFACE — see the `maxInlineActions` prop below.
106107
const maxInlineRowActions: number = foldInlineRowActions ? 0 : ((schema as any).maxInlineRowActions ?? 1);
107108
/**
108-
* objectstack#36911 — is this row held by its own locking approval, by a lock
109-
* read that ANSWERED? (The batch read answers for the record's own approval
110-
* 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
109+
* objectstack#36911 — is this row held by a locking approval (its own, or,
110+
* for a master-detail line, its master's), by a lock read that ANSWERED? The
111+
* row is handed to the hook as no row at all, so its
111112
* `approval_status` column does not stand in: a read refused (501), failed,
112113
* answering `null` (a row the reader cannot read) or not yet asked leaves
113114
* Edit where the menu had it. An answer arriving re-renders the grid. The
114115
* select-first cells read the same hook with the column fallback; the menu
115116
* offers what the server is known to refuse, never less on a guess.
116117
*/
117118
const approvalLockAnswered = (row: any): boolean => approvalLocks.isLocked(rowRecordId(row), null);
119+
/**
120+
* objectstack#37231 — and is the lock its MASTER's (`lockSource: 'master'`)?
121+
* Then Delete goes too: the server refuses a line's delete while its master
122+
* is held. A row held by its own approval keeps Delete; only an answer takes
123+
* it away, as above.
124+
*/
125+
const heldByMasterAnswered = (row: any): boolean => approvalLocks.heldByMaster(rowRecordId(row));
118126
const rowCrudVerdicts = (row: any) => {
119127
// [objectui#8674] The CALLER's answer for this one row, ANDed in below.
120128
const rowOps = rowOperations?.(row);
@@ -123,7 +131,10 @@ export function resolveObjectGridActionsColumn({
123131
canEdit && rowOps?.update !== false && !approvalLockAnswered(row),
124132
recordVerdict(rowRecordId(row), 'update'),
125133
),
126-
canDelete: resolveRowRecordCrudAffordance(canDelete && rowOps?.delete !== false, recordVerdict(rowRecordId(row), 'delete')),
134+
canDelete: resolveRowRecordCrudAffordance(
135+
canDelete && rowOps?.delete !== false && !heldByMasterAnswered(row),
136+
recordVerdict(rowRecordId(row), 'delete'),
137+
),
127138
};
128139
};
129140
const rowOffersAction = (row: any): boolean => {

0 commit comments

Comments
 (0)