From c5113a49a2252859841bda0ca83a8e50cb28cd3a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 12:32:21 +0000 Subject: [PATCH 1/2] fix(plugin-grid): the row menu drops Delete on a line whose master is held Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- ui/packages/plugin-grid/src/ObjectGrid.tsx | 14 ++-- .../rowMenuApprovalLock-36911.test.tsx | 84 ++++++++++++++++--- .../src/hooks/useRowApprovalLocks.ts | 35 +++++++- .../src/objectGridActionsColumn.tsx | 29 +++++-- 4 files changed, 134 insertions(+), 28 deletions(-) diff --git a/ui/packages/plugin-grid/src/ObjectGrid.tsx b/ui/packages/plugin-grid/src/ObjectGrid.tsx index 149687ef191..5049f60b2c5 100644 --- a/ui/packages/plugin-grid/src/ObjectGrid.tsx +++ b/ui/packages/plugin-grid/src/ObjectGrid.tsx @@ -1489,12 +1489,14 @@ export const ObjectGrid: React.FC = ({ // objectstack#36911 — the row menu reads the same locks: a row an approval // locks offers no Edit, as the record page offers none (objectstack#35593). // Delete stays for a record held by its own approval: the server deletes it - // and cancels its request. (The batch read reports only that case today, not - // 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 + // and cancels its request. objectstack#37231 — a master-detail line held + // because its MASTER is held (the read's `lockSource: 'master'`) offers no + // Delete either: the detail-row lock hook refuses it with `RECORD_LOCKED`. + // So the hook also runs on a grid whose rows offer Edit or Delete. It still // reads nothing until it is asked: by a cell being selected, or by a row's // actions being reached for (`demandRowActions` below). - const rowMenuOffersEdit = canEdit && !!onEdit; - const approvalLocks = useRowApprovalLocks(hostCellSelection || rowMenuOffersEdit ? objectName : undefined); + const rowMenuReadsLocks = (canEdit && !!onEdit) || (canDelete && !!onDelete); + const approvalLocks = useRowApprovalLocks(hostCellSelection || rowMenuReadsLocks ? objectName : undefined); /** * objectstack#36911 — what reaching for a row's actions asks * (`RowActionMenuProps.onActionsDemand`, objectstack#34208): the @@ -1506,8 +1508,8 @@ export const ObjectGrid: React.FC = ({ const probeApprovalLocks = approvalLocks.probe; const demandRowActions = useCallback(() => { requestRecordVerdicts(); - if (rowMenuOffersEdit) probeApprovalLocks(pageRecordIds); - }, [requestRecordVerdicts, probeApprovalLocks, rowMenuOffersEdit, pageRecordIds]); + if (rowMenuReadsLocks) probeApprovalLocks(pageRecordIds); + }, [requestRecordVerdicts, probeApprovalLocks, rowMenuReadsLocks, pageRecordIds]); // objectstack#35956 — a cell change that makes other fields required asks // for them first, and saves them with it (`./objectGridRequiredPrompt`). const fieldLabelOf = (field: string): string => { diff --git a/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx b/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx index f563b3cd8ab..189519b98b0 100644 --- a/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/rowMenuApprovalLock-36911.test.tsx @@ -21,6 +21,12 @@ * are reached for, never on first paint (objectstack#35795). Only an ANSWERED * lock hides Edit: a 501, a `null` entry, a failed read or a read not yet * asked leaves the menu as it was. + * + * objectstack#37231 — the read says which approval holds a locked row + * (`lockSource`). A master-detail line held because its MASTER is held + * (`'master'`) offers no Delete either: the detail-row lock hook refuses that + * delete with `RECORD_LOCKED`. A row held by its own approval (`'record'`) + * keeps Delete. */ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; @@ -60,10 +66,15 @@ const LOCKS_PATH = `/api/v1/approvals/records/${OBJECT}/locks`; const LOCKED_ROW = { id: 'p_locked', name: 'Data Centre Build' }; /** Its sibling on the same page, with no approval running. */ const OPEN_ROW = { id: 'p_open', name: 'Office Refresh' }; +/** A master-detail line whose MASTER is under a locking approval. */ +const MASTER_HELD_ROW = { id: 'p_line', name: 'Rack Delivery' }; -/** What the lock door answers, per id; `undefined` is the read's `null` entry. */ +/** + * What the lock door answers, per id; `undefined` is the read's `null` entry. + * `sources` is the `lockSource` a locked entry carries. + */ type LockDoor = - | { kind: 'answers'; locked: Record } + | { kind: 'answers'; locked: Record; sources?: Record } | { kind: 'status'; status: number } | { kind: 'network' }; @@ -82,7 +93,11 @@ const server = { reset() { server.gate = null; server.release = () => {}; - server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false } }; + server.door = { + kind: 'answers', + locked: { [LOCKED_ROW.id]: true, [OPEN_ROW.id]: false, [MASTER_HELD_ROW.id]: true }, + sources: { [LOCKED_ROW.id]: 'record', [MASTER_HELD_ROW.id]: 'master' }, + }; server.lockCalls = []; server.responses = []; }, @@ -110,7 +125,13 @@ const apiFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise ({ recordId, locked: door.locked[recordId] ?? null })) }, + data: { + records: ids.map((recordId) => ({ + recordId, + locked: door.locked[recordId] ?? null, + ...(door.sources?.[recordId] ? { lockSource: door.sources[recordId] } : {}), + })), + }, }); } // `security/explain`: every row may be written, so only the lock can take Edit away. @@ -134,7 +155,7 @@ const PageBar: React.FC = () => { function renderGrid( rows: Array> = [LOCKED_ROW, OPEN_ROW], - { listPage = false }: { listPage?: boolean } = {}, + { listPage = false, edit = true }: { listPage?: boolean; edit?: boolean } = {}, ) { const dataSource: any = { getObjectSchema: async (name: string) => ({ @@ -155,7 +176,7 @@ function renderGrid(
{listPage && } - {}} onDelete={() => {}} /> + {} : undefined} onDelete={() => {}} />
, @@ -224,35 +245,42 @@ describe('objectstack#36911 — the row menu follows the approval lock', () => { it('a 501 (no approvals service) leaves the menu as it was, even over an approval_status column', async () => { server.door = { kind: 'status', status: 501 }; - renderGrid([{ ...LOCKED_ROW, approval_status: 'pending' }, OPEN_ROW]); + renderGrid([{ ...LOCKED_ROW, approval_status: 'pending' }, OPEN_ROW, MASTER_HELD_ROW]); await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); await reachRowActions(); await waitFor(() => expect(server.lockCalls).toHaveLength(1)); await settleReads(); expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: true, delete: true }); + expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true }); }); it('a null entry (a row the reader cannot read) leaves Edit where it was', async () => { - server.door = { kind: 'answers', locked: { [LOCKED_ROW.id]: null, [OPEN_ROW.id]: false } }; - renderGrid(); + server.door = { + kind: 'answers', + locked: { [LOCKED_ROW.id]: null, [OPEN_ROW.id]: false, [MASTER_HELD_ROW.id]: null }, + }; + renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW]); await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); await reachRowActions(); await waitFor(() => expect(server.lockCalls).toHaveLength(1)); await settleReads(); expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); + expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true }); }); it('a read that fails, or that never answered, leaves Edit where it was', async () => { server.door = { kind: 'network' }; - renderGrid(); + renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW]); await waitFor(() => expect(screen.getByText(LOCKED_ROW.name)).toBeInTheDocument()); // Not asked yet: the menu is the one it always was. expect(server.lockCalls).toHaveLength(0); + expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true }); await reachRowActions(); await waitFor(() => expect(server.lockCalls).toHaveLength(1)); await settleReads(); expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: true, delete: true }); + expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: true, delete: true }); }); }); @@ -317,3 +345,39 @@ describe('objectstack#36911 — the read in flight', () => { expect(screen.getAllByTestId('row-action-builtin-delete').length).toBeGreaterThan(0); }); }); + +describe('objectstack#37231 — a line whose master is held offers no Delete', () => { + it('a master-held line offers neither Edit nor Delete; a record-held sibling offers no Edit and keeps Delete', async () => { + renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW]); + await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name)).toBeInTheDocument()); + await reachRowActions(); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + await settleReads(); + // CONTROL: the open sibling offers both, so the pins observe the lock. + expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: true, delete: true }); + await waitFor(async () => expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: false, delete: false })); + expect(await rowMenu(LOCKED_ROW.name)).toEqual({ edit: false, delete: true }); + }); + + it('a grid whose rows offer Delete but no Edit still reads the lock, and drops Delete on the master-held line', async () => { + renderGrid([OPEN_ROW, MASTER_HELD_ROW], { edit: false }); + await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name)).toBeInTheDocument()); + expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: false, delete: true }); + await waitFor(() => expect(server.lockCalls).toHaveLength(1)); + await settleReads(); + await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name).closest('tr') + ?.querySelector('[data-testid="row-action-trigger"]') ?? null).toBeNull()); + expect(await rowMenu(MASTER_HELD_ROW.name)).toEqual({ edit: false, delete: false }); + expect(await rowMenu(OPEN_ROW.name)).toEqual({ edit: false, delete: true }); + }); + + it('the list page selection bar: a selected master-held line offers neither; a selected record-held sibling keeps Delete', async () => { + renderGrid([LOCKED_ROW, OPEN_ROW, MASTER_HELD_ROW], { listPage: true }); + await waitFor(() => expect(screen.getByText(MASTER_HELD_ROW.name)).toBeInTheDocument()); + expect(await selectionBarOffers(OPEN_ROW.name)).toEqual({ edit: true, delete: true }); + expect(server.lockCalls).toHaveLength(1); + expect(await selectionBarOffers(MASTER_HELD_ROW.name)).toEqual({ edit: false, delete: false }); + expect(await selectionBarOffers(LOCKED_ROW.name)).toEqual({ edit: false, delete: true }); + expect(server.lockCalls).toHaveLength(1); + }); +}); diff --git a/ui/packages/plugin-grid/src/hooks/useRowApprovalLocks.ts b/ui/packages/plugin-grid/src/hooks/useRowApprovalLocks.ts index 271953e6457..ac42fcb3881 100644 --- a/ui/packages/plugin-grid/src/hooks/useRowApprovalLocks.ts +++ b/ui/packages/plugin-grid/src/hooks/useRowApprovalLocks.ts @@ -34,6 +34,13 @@ * grid already says of the selected cell (its `aria-readonly`) follows the * lock without waiting for the reader to move: `isLocked`, and the value this * hook returns, are new exactly when the answers it reads changed. + * + * The door also says WHICH approval holds a locked row (`lockSource`): its own + * (`'record'`), or, for a master-detail line, its master's (`'master'`, which + * wins when both hold). `heldByMaster` reads that bit for the row menu: the + * server deletes a record held by its own approval and cancels the request, + * but the detail-row lock hook refuses a line's delete while its master is + * held (objectstack#37231). */ import * as React from 'react'; import { APPROVAL_RECORD_LOCKS_MAX_RECORD_IDS } from '@objectstack/spec/contracts'; @@ -53,7 +60,10 @@ export function __resetApprovalsServiceLatch(): void { * back to its `approval_status` column (fail open: the server still refuses a * write to a locked record). */ -type LockAnswer = { locked: boolean } | 'asking' | 'unanswered'; +type LockAnswer = { locked: boolean; lockSource?: ApprovalLockSource } | 'asking' | 'unanswered'; + +/** Which approval holds a locked row: its own, or its master's (a master-detail line). */ +export type ApprovalLockSource = 'record' | 'master'; export interface RowApprovalLocks { /** @@ -63,6 +73,13 @@ export interface RowApprovalLocks { probe: (recordIds: readonly unknown[]) => void; /** Whether the row is locked by an approval, from what has answered so far. */ isLocked: (recordId: unknown, row: any) => boolean; + /** + * Whether a read ANSWERED the row as held by its master's approval + * (`lockSource: 'master'`). Only an answer says so: a read refused (501), + * failed, answering `null`, or not yet asked answers `false`, and so does a + * row held by its own approval. + */ + heldByMaster: (recordId: unknown) => boolean; /** The row's lock read while it is on the wire (it settles when it answers or fails), else `null`. */ settling: (recordId: unknown) => Promise | null; } @@ -121,7 +138,10 @@ export function useRowApprovalLocks(objectName: string | undefined): RowApproval chunk.forEach((id, index) => { const entry = records[index]; if (entry && entry.recordId === id && typeof entry.locked === 'boolean') { - answered.set(id, { locked: entry.locked }); + const lockSource = entry.locked && (entry.lockSource === 'record' || entry.lockSource === 'master') + ? entry.lockSource as ApprovalLockSource + : undefined; + answered.set(id, lockSource ? { locked: entry.locked, lockSource } : { locked: entry.locked }); } }); } @@ -154,10 +174,19 @@ export function useRowApprovalLocks(objectName: string | undefined): RowApproval }).locked; }, [answerSeq]); + const heldByMaster = React.useCallback((recordId: unknown) => { + void answerSeq; + const answer = recordId == null ? undefined : answersRef.current.get(String(recordId)); + return typeof answer === 'object' && answer.locked && answer.lockSource === 'master'; + }, [answerSeq]); + const settling = React.useCallback( (recordId: unknown) => (recordId == null ? null : wiresRef.current.get(String(recordId)) ?? null), [], ); - return React.useMemo(() => ({ probe, isLocked, settling }), [probe, isLocked, settling]); + return React.useMemo( + () => ({ probe, isLocked, heldByMaster, settling }), + [probe, isLocked, heldByMaster, settling], + ); } diff --git a/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx b/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx index c420482ddd3..d9d2a5403f5 100644 --- a/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx +++ b/ui/packages/plugin-grid/src/objectGridActionsColumn.tsx @@ -49,11 +49,12 @@ export function resolveObjectGridActionsColumn({ /** * objectstack#36911 — the approval locks of the rows on screen, the read the * select-first cells ask (`useRowApprovalLocks`). A row a read ANSWERED as - * locked offers no Edit. Delete is untouched, which is right only while the - * read answers for a record held by ITS OWN approval: the server deletes such - * a record and cancels its request. A line held because its MASTER is held - * refuses delete too; if the read ever reports those lines, it must tell - * the two apart before this menu reads it (#37041). + * locked offers no Edit. objectstack#37231 — the read says which approval + * holds it (`lockSource`): a record held by ITS OWN approval keeps Delete, + * because the server deletes such a record and cancels its request; a + * master-detail line held because its MASTER is held (`lockSource: + * 'master'`) offers no Delete either, because the detail-row lock hook + * refuses that delete with `RECORD_LOCKED`. */ approvalLocks: RowApprovalLocks; /** @@ -103,9 +104,9 @@ export function resolveObjectGridActionsColumn({ // NON-AUTHOR SURFACE — see the `maxInlineActions` prop below. const maxInlineRowActions: number = foldInlineRowActions ? 0 : ((schema as any).maxInlineRowActions ?? 1); /** - * objectstack#36911 — is this row held by its own locking approval, by a lock - * read that ANSWERED? (The batch read answers for the record's own approval - * 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 + * objectstack#36911 — is this row held by a locking approval (its own, or, + * for a master-detail line, its master's), by a lock read that ANSWERED? The + * row is handed to the hook as no row at all, so its * `approval_status` column does not stand in: a read refused (501), failed, * answering `null` (a row the reader cannot read) or not yet asked leaves * Edit where the menu had it. An answer arriving re-renders the grid. The @@ -113,6 +114,13 @@ export function resolveObjectGridActionsColumn({ * offers what the server is known to refuse, never less on a guess. */ const approvalLockAnswered = (row: any): boolean => approvalLocks.isLocked(rowRecordId(row), null); + /** + * objectstack#37231 — and is the lock its MASTER's (`lockSource: 'master'`)? + * Then Delete goes too: the server refuses a line's delete while its master + * is held. A row held by its own approval keeps Delete; only an answer takes + * it away, as above. + */ + const heldByMasterAnswered = (row: any): boolean => approvalLocks.heldByMaster(rowRecordId(row)); const rowCrudVerdicts = (row: any) => { // [objectui#8674] The CALLER's answer for this one row, ANDed in below. const rowOps = rowOperations?.(row); @@ -121,7 +129,10 @@ export function resolveObjectGridActionsColumn({ canEdit && rowOps?.update !== false && !approvalLockAnswered(row), recordVerdict(rowRecordId(row), 'update'), ), - canDelete: resolveRowRecordCrudAffordance(canDelete && rowOps?.delete !== false, recordVerdict(rowRecordId(row), 'delete')), + canDelete: resolveRowRecordCrudAffordance( + canDelete && rowOps?.delete !== false && !heldByMasterAnswered(row), + recordVerdict(rowRecordId(row), 'delete'), + ), }; }; const rowOffersAction = (row: any): boolean => { From 929d5f0d6865c50aa8c0715d2028b8f369638a20 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 12:51:52 +0000 Subject: [PATCH 2/2] chore(changeset): plugin-grid master-held line drops Delete Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .changeset/37231-grid-master-held-hide-delete.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .changeset/37231-grid-master-held-hide-delete.md diff --git a/.changeset/37231-grid-master-held-hide-delete.md b/.changeset/37231-grid-master-held-hide-delete.md new file mode 100644 index 00000000000..a4fca29d2a1 --- /dev/null +++ b/.changeset/37231-grid-master-held-hide-delete.md @@ -0,0 +1,14 @@ +--- +'@object-ui/plugin-grid': patch +--- + +fix(plugin-grid): the row menu offers no Delete on a line whose master is held + +Clause-②: no +Metadata-protocol: none + +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`. + +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. + +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.