From 1a9f6f562e371f96e90dffe1b7bda8733daf234d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 22:04:59 +0000 Subject: [PATCH 1/5] test(plugin-form): pin a parent's whole-record hand lock over its inline lines Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8 Co-authored-by: Claude --- ...erDetailForm.parentHandLock-38249.test.tsx | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx diff --git a/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx b/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx new file mode 100644 index 00000000000..d3a1c7ec4cf --- /dev/null +++ b/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx @@ -0,0 +1,150 @@ +/** + * 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. + */ + +/** + * objectstack#38249 — a parent's whole-record hand lock (object-level + * `uiReadonlyWhen`) covers its inline master-detail lines in the edit form. + * + * While the predicate holds over the parent record, a person adds, + * duplicates, removes, reorders and edits no line by hand. A child field that + * declares a hand lock of its own (`uiReadonly: true` or a `uiReadonlyWhen`) + * is judged by that declaration instead, the same override the object level + * reads (`effectiveUiReadonlyWhen`): `uiReadonlyWhen: 'false'` keeps that one + * cell editable on a locked document. A create is not judged. + * + * Measured through the REAL `MasterDetailForm` and `GridField`. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, waitFor, cleanup } from '@testing-library/react'; +import React from 'react'; + +import { registerAllFields } from '@object-ui/fields'; +import { MasterDetailForm } from './MasterDetailForm'; + +registerAllFields(); +afterEach(cleanup); + +const PARENT = 'sales_order'; +const CHILD = 'sales_order_line'; +const LINE = { id: 'L1', order: 'SO1', qty: 3, note: 'gift wrap' }; + +const PARENT_SCHEMA = { + name: PARENT, + uiReadonlyWhen: "record.status == 'confirmed'", + fields: { ref: { type: 'text', label: 'Ref' }, status: { type: 'text', label: 'Status' } }, +}; + +const childSchema = (note: Record) => ({ + name: CHILD, + fields: { + order: { type: 'master_detail', reference: PARENT, label: 'Order' }, + qty: { type: 'number', label: 'Qty' }, + note: { type: 'text', label: 'Note', ...note }, + }, +}); + +function makeDS(status: string, note: Record = {}) { + return { + getObjectSchema: vi.fn(async (obj: string) => + obj === PARENT ? PARENT_SCHEMA : obj === CHILD ? childSchema(note) : null, + ), + findOne: vi.fn().mockResolvedValue({ id: 'SO1', ref: 'SO-1', status }), + find: vi.fn().mockResolvedValue({ data: [LINE] }), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + batchTransaction: vi.fn().mockResolvedValue({ results: [] }), + }; +} + +/** Untyped authored columns: the child schema is read and each column hydrated from its field. */ +const DERIVED = [{ childObject: CHILD, relationshipField: 'order', columns: [{ name: 'qty', label: 'Qty' }, { name: 'note', label: 'Note' }] }]; +/** A fully configured entry: typed columns and the FK, so no child schema is read. */ +const CONFIGURED = [{ childObject: CHILD, relationshipField: 'order', columns: [{ name: 'qty', label: 'Qty', type: 'number' }] }]; + +function mount(ds: ReturnType, details = DERIVED, mode: 'edit' | 'create' = 'edit') { + return render( + , + ); +} + +const offered = () => ({ + add: screen.queryByTestId('line-items-add') !== null, + duplicate: screen.queryAllByRole('button', { name: 'Duplicate row' }).length > 0, + remove: screen.queryAllByRole('button', { name: 'Remove row' }).length > 0, + reorder: screen.queryByTestId('line-items-drag-0') !== null, +}); + +/** Wait until the stored line is drawn and the header record has landed. */ +async function lineLoaded(ds: ReturnType) { + await waitFor(() => expect(screen.getByDisplayValue('3')).toBeTruthy()); + await waitFor(() => expect(ds.findOne).toHaveBeenCalled()); + await waitFor(() => expect(screen.getByDisplayValue('SO-1')).toBeTruthy()); +} + +const qtyCell = () => screen.getByDisplayValue('3') as HTMLInputElement; +const noteCell = () => screen.getByDisplayValue('gift wrap') as HTMLInputElement; + +describe('MasterDetailForm: the parent object\'s uiReadonlyWhen hand-locks its inline lines (objectstack#38249)', () => { + it('a locked parent offers no add, duplicate, remove or reorder of a line, and locks a line cell that declares no hand lock of its own', async () => { + const ds = makeDS('confirmed'); + mount(ds); + await lineLoaded(ds); + await waitFor(() => expect(qtyCell().disabled).toBe(true)); + expect(offered()).toEqual({ add: false, duplicate: false, remove: false, reorder: false }); + }); + + it("a child field whose own uiReadonlyWhen is 'false' stays editable on a locked parent; its siblings stay locked", async () => { + const ds = makeDS('confirmed', { uiReadonlyWhen: 'false' }); + mount(ds); + await lineLoaded(ds); + await waitFor(() => expect(qtyCell().disabled).toBe(true)); + expect(noteCell().disabled).toBe(false); + expect(offered().add).toBe(false); + }); + + it('a child field with uiReadonly: true stays locked on a locked parent (its own declaration locks it)', async () => { + const ds = makeDS('confirmed', { uiReadonly: true }); + mount(ds); + await lineLoaded(ds); + await waitFor(() => expect(qtyCell().disabled).toBe(true)); + expect(noteCell().disabled).toBe(true); + }); + + it('a fully configured entry (no child schema read) locks every line cell on a locked parent', async () => { + const ds = makeDS('confirmed'); + mount(ds, CONFIGURED); + await lineLoaded(ds); + await waitFor(() => expect(qtyCell().disabled).toBe(true)); + expect(offered()).toEqual({ add: false, duplicate: false, remove: false, reorder: false }); + }); + + it('CONTROL: while the parent predicate does not hold, the lines are edited as before', async () => { + const ds = makeDS('draft'); + mount(ds); + await lineLoaded(ds); + expect(qtyCell().disabled).toBe(false); + expect(noteCell().disabled).toBe(false); + expect(offered()).toEqual({ add: true, duplicate: true, remove: true, reorder: true }); + }); + + it('CONTROL: a create form is not judged — lines are added on an object that carries the lock', async () => { + const ds = makeDS('confirmed'); + mount(ds, DERIVED, 'create'); + await waitFor(() => expect(screen.getByTestId('line-items-add')).toBeTruthy()); + }); +}); From 5cda505743d5c6f8407b9f4fec78a0f686b30c72 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 22:12:42 +0000 Subject: [PATCH 2/5] fix(console): a parent's whole-record hand lock locks its inline lines in the edit form The edit dialog's master-detail lines now follow the parent object's uiReadonlyWhen: while it holds, no line is added, duplicated, removed, reordered or opened in the row editor, and every line cell whose child field owns no hand lock is locked. A child field that declares its own (uiReadonly: true or a uiReadonlyWhen) is judged by it, so uiReadonlyWhen 'false' keeps that cell editable. The record page's Edit greys when the lock holds and no child field can open a line. Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8 Co-authored-by: Claude --- .../src/utils/editFormLockedByState.test.ts | 51 ++++++++++++ .../src/utils/editFormLockedByState.ts | 34 +++++++- .../app-shell/src/views/RecordDetailView.tsx | 12 ++- ...erDetailForm.parentHandLock-38249.test.tsx | 3 +- .../plugin-form/src/MasterDetailForm.tsx | 59 +++++++++++-- .../__tests__/dialogHandLock-36806.test.ts | 74 ++++++++++++++++- ui/packages/plugin-form/src/core.ts | 2 +- .../plugin-form/src/deriveMasterDetail.ts | 82 ++++++++++++++++++- ui/packages/plugin-form/src/index.tsx | 2 +- 9 files changed, 298 insertions(+), 21 deletions(-) diff --git a/ui/packages/app-shell/src/utils/editFormLockedByState.test.ts b/ui/packages/app-shell/src/utils/editFormLockedByState.test.ts index 844fa387267..c3f5f3a5a29 100644 --- a/ui/packages/app-shell/src/utils/editFormLockedByState.test.ts +++ b/ui/packages/app-shell/src/utils/editFormLockedByState.test.ts @@ -118,3 +118,54 @@ describe('editFormLockedByState reads the object-level uiReadonlyWhen (#37402)', expect(editFormLockedByState(order({}), { ...CONFIRMED, status: 'draft' })).toBe(false); }); }); + +/** + * #38249 — an object's whole-record hand lock locks its inline lines too, so + * an object that places a child collection greys Edit when the lock holds and + * no field of the child can open a line cell. Without the child's definition, + * or when a child field owns a lock that could open, Edit stays live. + */ +describe('editFormLockedByState with inline lines under the object-level uiReadonlyWhen (#38249)', () => { + const CONFIRMED = { id: 'o1', status: 'confirmed', amount: 1 }; + const order = { + name: 'order', + uiReadonlyWhen: "record.status == 'confirmed'", + fields: { status: { type: 'text' }, amount: { type: 'number' } }, + groupSubforms: [{ childObject: 'order_line', relationshipField: 'order' }], + }; + const line = (qty: Record = {}) => ({ + name: 'order_line', + fields: { order: { type: 'master_detail', reference: 'order' }, qty: { type: 'number', ...qty } }, + }); + const defs = (child: unknown) => (name: string) => (name === 'order_line' ? (child as any) : undefined); + + it('is true when the object lock holds and no child field can open a line cell', () => { + expect(editFormLockedByState(order, CONFIRMED, undefined, defs(line()))).toBe(true); + }); + + it("is false when a child field keeps its cell editable with its own uiReadonlyWhen 'false'", () => { + expect(editFormLockedByState(order, CONFIRMED, undefined, defs(line({ uiReadonlyWhen: 'false' })))).toBe(false); + }); + + it('is true when the child field owns only a static lock', () => { + expect(editFormLockedByState(order, CONFIRMED, undefined, defs(line({ uiReadonly: true })))).toBe(true); + }); + + it('is false while the object predicate does not hold', () => { + expect(editFormLockedByState(order, { ...CONFIRMED, status: 'draft' }, undefined, defs(line()))).toBe(false); + }); + + it('is false when the header is locked only field by field: that leaves the lines open', () => { + const { uiReadonlyWhen: _drop, ...plain } = order; + const byField = { + ...plain, + fields: { status: { type: 'text', readonlyWhen: "record.status == 'confirmed'" }, amount: { type: 'number', readonlyWhen: "record.status == 'confirmed'" } }, + }; + expect(editFormLockedByState(byField, CONFIRMED, undefined, defs(line()))).toBe(false); + }); + + it("fails open without the child object's definition", () => { + expect(editFormLockedByState(order, CONFIRMED)).toBe(false); + expect(editFormLockedByState(order, CONFIRMED, undefined, () => undefined)).toBe(false); + }); +}); diff --git a/ui/packages/app-shell/src/utils/editFormLockedByState.ts b/ui/packages/app-shell/src/utils/editFormLockedByState.ts index e1de5822dff..2928a3063a8 100644 --- a/ui/packages/app-shell/src/utils/editFormLockedByState.ts +++ b/ui/packages/app-shell/src/utils/editFormLockedByState.ts @@ -29,14 +29,20 @@ * so a writable field anywhere keeps Edit live; * - the object's field groups place no inline child collection * (`recordFormSubforms`, objectstack-ai/objectstack#36425), whose rows the - * form still edits whatever the header fields say. + * form still edits whatever the header fields say — unless the object's + * whole-record hand lock (`uiReadonlyWhen`) holds over the record, which + * locks those rows too (objectstack#38249), and no field of any placed + * child object owns a hand lock that could open a line cell + * (`childLinesOpenUnderParentHandLock`). That needs each child object's + * definition, from `childObjectDef`; without it, or for a child it cannot + * answer, Edit stays live. * * A predicate that faults resolves to its fail-open verdict (writable), as in * the form, so a broken rule never greys Edit. */ -import { effectiveUiReadonlyWhen, isExpressionComputedField, resolveFieldRuleState, type ObjectHandLockDef } from '@object-ui/core'; -import { filterSystemFields, isAutoGeneratedFieldType } from '@object-ui/plugin-form/core'; +import { effectiveUiReadonlyWhen, fieldReadOnlyByHand, isExpressionComputedField, resolveFieldRuleState, type ObjectHandLockDef } from '@object-ui/core'; +import { childLinesOpenUnderParentHandLock, filterSystemFields, isAutoGeneratedFieldType } from '@object-ui/plugin-form/core'; import type { FormField } from '@object-ui/types'; import { recordFormSubforms, type ObjectDefinitionForRecordForm } from './recordFormNavigation.js'; @@ -66,9 +72,11 @@ export function editFormLockedByState( objectDef: EditFormLockObject | null | undefined, record: Record | null | undefined, scope?: Record, + childObjectDef?: (name: string) => { fields?: Record } | null | undefined, ): boolean { if (!objectDef || !record) return false; - if (recordFormSubforms(objectDef)) return false; + const subforms = recordFormSubforms(objectDef); + if (subforms && !childObjectDef) return false; const declared = fieldEntries(objectDef.fields); // The fields the form draws: the form's own system-field pass drops the @@ -87,6 +95,24 @@ export function editFormLockedByState( for (const { name } of declared) ruleRecord[name] = null; for (const [k, v] of Object.entries(record)) if (v !== undefined) ruleRecord[k] = v; + if (subforms) { + // objectstack#38249 — the lines are locked only by the object's own + // whole-record hand lock (a field-level lock on the header leaves them + // open), judged by the one hand-lock verdict over the stored row. + const objectLockHolds = fieldReadOnlyByHand({}, ruleRecord, { + object: objectDef, + previous: ruleRecord, + scope, + fieldContext: 'object uiReadonlyWhen', + }); + if (!objectLockHolds) return false; + for (const subform of subforms) { + const childObject = typeof subform?.childObject === 'string' ? subform.childObject : undefined; + const child = childObject ? childObjectDef?.(childObject) : undefined; + if (!child || childLinesOpenUnderParentHandLock(child)) return false; + } + } + let shown = 0; let lockedByRule = 0; for (const { name, def } of entries) { diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index 4abea6292ce..8f271c606b1 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -3108,8 +3108,16 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri // goes off exactly when the form would open with no control. const predicateScope = usePredicateScope(); const editLockedByState = useMemo( - () => editFormLockedByState(objectDef as any, pageRecord as Record | null | undefined, predicateScope), - [objectDef, pageRecord, predicateScope], + () => editFormLockedByState( + objectDef as any, + pageRecord as Record | null | undefined, + predicateScope, + // The placed child objects' definitions: a parent's whole-record hand + // lock locks its inline lines too, unless a child field owns a lock + // that could open one (objectstack#38249). + (name) => objects.find((o: any) => o?.name === name), + ), + [objectDef, pageRecord, predicateScope, objects], ); // ── Audit history fetch ──────────────────────────────────────────── diff --git a/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx b/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx index d3a1c7ec4cf..6c7788cc57b 100644 --- a/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx +++ b/ui/packages/plugin-form/src/MasterDetailForm.parentHandLock-38249.test.tsx @@ -93,7 +93,8 @@ const offered = () => ({ async function lineLoaded(ds: ReturnType) { await waitFor(() => expect(screen.getByDisplayValue('3')).toBeTruthy()); await waitFor(() => expect(ds.findOne).toHaveBeenCalled()); - await waitFor(() => expect(screen.getByDisplayValue('SO-1')).toBeTruthy()); + // A locked header field draws its read face, an open one its input. + await waitFor(() => expect(screen.queryByDisplayValue('SO-1') ?? screen.queryByText('SO-1')).toBeTruthy()); } const qtyCell = () => screen.getByDisplayValue('3') as HTMLInputElement; diff --git a/ui/packages/plugin-form/src/MasterDetailForm.tsx b/ui/packages/plugin-form/src/MasterDetailForm.tsx index 94027885ddc..91e74bda150 100644 --- a/ui/packages/plugin-form/src/MasterDetailForm.tsx +++ b/ui/packages/plugin-form/src/MasterDetailForm.tsx @@ -33,7 +33,7 @@ import React, { startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'; import { createPortal } from 'react-dom'; import type { BatchTransactionOperation, DataSource, GridFieldMetadata, I18nLabel } from '@object-ui/types'; -import { resolveAffordance, runBatchTransaction } from '@object-ui/core'; +import { fieldReadOnlyByHand, resolveAffordance, runBatchTransaction } from '@object-ui/core'; import { isUntouchedNewRow, LineItemsField, preloadGridField, lookupAutofillByField, columnHelpByField, UNTOUCHED_NEW_ROW, useBooleanValueLabel, type BooleanValueLabel, type ColumnHelp, type GridColumn, type LookupAutofillByField } from '@object-ui/fields'; import { Button, Card, CardContent, CardHeader, CardTitle, cn, toast } from '@object-ui/components'; import { @@ -45,7 +45,7 @@ import { useObjectTranslation, } from '@object-ui/i18n'; import { usePermissions } from '@object-ui/permissions'; -import { dataChangeMatches, extractFieldErrors, subscribeDataChanges } from '@object-ui/react'; +import { dataChangeMatches, extractFieldErrors, subscribeDataChanges, usePredicateScope } from '@object-ui/react'; import { ObjectForm } from './ObjectForm'; import { applyColumnPermissions } from './fieldWriteGate'; import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate'; @@ -65,7 +65,7 @@ import { import { isSameStoredValue } from './sanitize'; import { resolveInitialRecord } from './initialRecord'; import { sectionEntryName } from './sectionFields'; -import { deriveDetail } from './deriveMasterDetail'; +import { deriveDetail, lockColumnsByParentHandLock } from './deriveMasterDetail'; import { schemaDefaultValues } from './schemaDefaults'; import { currencyFieldDefsOf, parentCurrencyFieldsOf, followedColumnCurrencies } from './parentCurrencyColumns'; // objectui#11428 — the per-row form's offer test is the spec's rule. @@ -681,13 +681,19 @@ interface HeaderRecordFeed { record: Record; /** The header object's field names, once its schema read has answered. */ objectFields: readonly string[] | null; + /** + * The header object's whole-record hand lock (`ObjectSchema.uiReadonlyWhen`), + * landed with its field names (objectstack#38249); `undefined` until then or + * when the object declares none. + */ + objectHandLock: unknown; /** Bumped per header record read started, so only the newest answer lands. */ seq: number; listeners: Set<(landed: 'record' | 'objectFields') => void>; } function createHeaderRecordFeed(opening: Record): HeaderRecordFeed { - return { record: opening, objectFields: null, seq: 0, listeners: new Set() }; + return { record: opening, objectFields: null, objectHandLock: undefined, seq: 0, listeners: new Set() }; } /** @@ -743,8 +749,10 @@ function observeHeaderReads( const answer = call(args); if (args[0] === objectName) { observe(answer, (objectSchema) => { - const fields = (objectSchema as { fields?: Record } | null)?.fields; + const served = objectSchema as { fields?: Record; uiReadonlyWhen?: unknown } | null; + const fields = served?.fields; feed.objectFields = fields ? Object.keys(fields) : []; + feed.objectHandLock = served?.uiReadonlyWhen ?? undefined; feed.listeners.forEach((listener) => listener('objectFields')); }); } @@ -1053,6 +1061,7 @@ const MasterDetailLines: React.FC = ({ // it, so a header that answers late still locks a paid invoice's lines. const [loadedRecord, setLoadedRecord] = useState>(headerRecord.record); const [objectFields, setObjectFields] = useState(headerRecord.objectFields); + const [parentHandLock, setParentHandLock] = useState(headerRecord.objectHandLock); // The user's edits, scraped from the host on its input/change events; null // until the first one. A landing record replaces the form's values, so it // drops them. @@ -1063,6 +1072,7 @@ const MasterDetailLines: React.FC = ({ const land = (landed: 'record' | 'objectFields') => { if (landed === 'objectFields') { setObjectFields(headerRecord.objectFields); + setParentHandLock(headerRecord.objectHandLock); return; } editedKeyRef.current = ''; @@ -1115,6 +1125,29 @@ const MasterDetailLines: React.FC = ({ [loadedRecord, editedRecord], ); + // objectstack#38249 — the PARENT's whole-record hand lock covers its lines. + // Judged as the header's own fields judge it: over the live header record + // (every header field seeded `null`, as the form seeds it), the stored one + // as `previous`, in the host's predicate scope, through the one hand-lock + // verdict (`fieldReadOnlyByHand` of a field that declares nothing, i.e. the + // object's lock itself, failing closed on a fault). A create is not judged. + // While it holds, no line is added, duplicated, removed, reordered or opened + // in the row editor, and every cell whose child field owns no hand lock is + // locked (`lockColumnsByParentHandLock`). + const predicateScope = usePredicateScope(); + const parentHandLocked = useMemo(() => { + if (formMode !== 'edit' || parentHandLock == null) return false; + const ruleRecord: Record = {}; + for (const name of objectFields ?? []) ruleRecord[name] = null; + for (const [k, v] of Object.entries(parentRecord)) if (v !== undefined) ruleRecord[k] = v; + return fieldReadOnlyByHand({}, ruleRecord, { + object: { uiReadonlyWhen: parentHandLock }, + previous: loadedRecord, + scope: predicateScope, + fieldContext: `object '${parentObjectName}' uiReadonlyWhen`, + }); + }, [formMode, parentHandLock, objectFields, parentRecord, loadedRecord, predicateScope, parentObjectName]); + // Document totals: Subtotal (Σ line amounts) → Tax (header rate %) → Total. // Shown only when the header carries the tax-rate field AND a detail has an // amount column; otherwise each grid keeps its own footer total. @@ -1284,7 +1317,9 @@ const MasterDetailLines: React.FC = ({ // redundant expand button. The test is `@objectstack/spec`'s // `isInlineRowFormOffered` (objectui#11428), asked with the // collection's RESOLVED form factor and lists, authored or derived. - {...(isInlineRowFormOffered({ inlineMode: d.inlineMode, formFields: d.formFields, columns: d.columns }) + // No row editor under the parent's hand lock (objectstack#38249): + // it edits every child field, owned lock or not. + {...(!parentHandLocked && isInlineRowFormOffered({ inlineMode: d.inlineMode, formFields: d.formFields, columns: d.columns }) ? { onRowExpand: (rowIdx: number) => onRowExpand(entry.id, rowIdx) } : {})} displayMode={d.inlineMode === 'form' ? 'list' : 'grid'} @@ -1295,7 +1330,10 @@ const MasterDetailLines: React.FC = ({ // the record-form containers share: a child column the caller // may not read is omitted, and one they may read but not edit // renders its cells locked (objectui#10163). - columns: applyColumnPermissions(d.columns, { perms, objectName: d.childObject, mode: formMode }), + columns: applyColumnPermissions( + parentHandLocked ? lockColumnsByParentHandLock(d.columns) : d.columns, + { perms, objectName: d.childObject, mode: formMode }, + ), // Show the per-grid running total whenever an amount column is // set — unless the document totals stack below subsumes it. // The grid's `totalField` names the CHILD column summed (this @@ -1307,8 +1345,11 @@ const MasterDetailLines: React.FC = ({ maxRows: d.maxRows, // The map rows above: the grid's Add and Duplicate follow // `allowAdd`, its per-row Remove `allowDelete`. - allowAdd: lineAddGranted, - allowDelete: lineRemoveGranted, + // The parent's hand lock withholds all three, and reorder + // (objectstack#38249). + allowAdd: lineAddGranted && !parentHandLocked, + allowDelete: lineRemoveGranted && !parentHandLocked, + ...(parentHandLocked ? { allowReorder: false } : {}), addLabel: d.inlineMode === 'form' ? (d.addLabel || t('detail.add')) : d.addLabel, // Checked against the grid's published type (objectui#11610), so // a key the grid does not declare, or one of its retired diff --git a/ui/packages/plugin-form/src/__tests__/dialogHandLock-36806.test.ts b/ui/packages/plugin-form/src/__tests__/dialogHandLock-36806.test.ts index c67c5639bc9..b669e7eb6e8 100644 --- a/ui/packages/plugin-form/src/__tests__/dialogHandLock-36806.test.ts +++ b/ui/packages/plugin-form/src/__tests__/dialogHandLock-36806.test.ts @@ -17,7 +17,13 @@ import { describe, it, expect } from 'vitest'; import { filterCreateModeFields, filterSystemFields } from '../autoLayout'; import { sanitizeFormData } from '../sanitize'; import { fromObjectSchema, type SectionFieldsContext } from '../sectionFields'; -import { deriveColumns, hydrateColumns } from '../deriveMasterDetail'; +import { + childFieldOwnsHandLock, + childLinesOpenUnderParentHandLock, + deriveColumns, + hydrateColumns, + lockColumnsByParentHandLock, +} from '../deriveMasterDetail'; import type { FormField } from '@object-ui/types'; const objectSchema = { @@ -88,3 +94,69 @@ describe('the dialog and line-item fields carry the object-level hand lock (#374 expect((authored[0] as any).uiReadonlyWhen).toBe(LOCK); }); }); + +/** + * #38249 — a parent's whole-record hand lock reaches its inline lines: every + * line column whose child field owns no hand lock is locked; a child field + * that declares one (`uiReadonly: true` or a `uiReadonlyWhen`) keeps its own + * verdict, the same override the object level reads. `uiReadonly: false` is + * not such a declaration. + */ +describe("a parent's whole-record hand lock over its line columns (#38249)", () => { + const line = { + name: 'order_line', + fields: { + parent: { type: 'master_detail', reference: 'order' }, + qty: { type: 'number' }, + notes: { type: 'text', uiReadonlyWhen: 'false' }, + sku: { type: 'text', uiReadonly: false }, + tag: { type: 'text', uiReadonlyWhen: "record.qty > 5" }, + }, + }; + const label = { booleanLabel: (v: boolean) => String(v) } as never; + const byName = (cols: any[], n: string) => cols.find((c) => c.name === n); + + it('childFieldOwnsHandLock reads the one override rule', () => { + expect(childFieldOwnsHandLock({ uiReadonlyWhen: 'false' })).toBe(true); + expect(childFieldOwnsHandLock({ uiReadonlyWhen: "record.qty > 5" })).toBe(true); + expect(childFieldOwnsHandLock({ uiReadonly: true })).toBe(true); + expect(childFieldOwnsHandLock({ uiReadonly: false })).toBe(false); + expect(childFieldOwnsHandLock({ readonly: true, readonlyWhen: 'true' })).toBe(false); + expect(childFieldOwnsHandLock({})).toBe(false); + expect(childFieldOwnsHandLock(undefined)).toBe(false); + }); + + it('derived columns: a field that owns no hand lock is locked; one that owns one keeps its own verdict', () => { + const locked = lockColumnsByParentHandLock(deriveColumns(line, { ...(label as object), relationshipField: 'parent' } as never)); + expect(byName(locked, 'qty')?.uiReadonly).toBe(true); + expect(byName(locked, 'sku')?.uiReadonly).toBe(true); + expect(byName(locked, 'notes')?.uiReadonly).toBeUndefined(); + expect(byName(locked, 'notes')?.uiReadonlyWhen).toBe('false'); + expect(byName(locked, 'tag')?.uiReadonly).toBeUndefined(); + }); + + it('authored columns: typed and untyped alike carry the mark from the child field', () => { + const cols = hydrateColumns( + [{ name: 'qty', type: 'number' }, { name: 'notes', type: 'text' }, { name: 'tag' }] as never, + line, + label, + ); + const locked = lockColumnsByParentHandLock(cols); + expect(byName(locked, 'qty')?.uiReadonly).toBe(true); + expect(byName(locked, 'notes')?.uiReadonly).toBeUndefined(); + expect(byName(locked, 'tag')?.uiReadonly).toBeUndefined(); + }); + + it('a column no child schema was read for carries no mark and is locked (fails closed)', () => { + const locked = lockColumnsByParentHandLock([{ name: 'notes', type: 'text' }] as never); + expect((locked[0] as any).uiReadonly).toBe(true); + }); + + it('childLinesOpenUnderParentHandLock: true only when some child field owns a lock that is not static', () => { + expect(childLinesOpenUnderParentHandLock(line)).toBe(true); + expect(childLinesOpenUnderParentHandLock({ fields: { qty: { type: 'number' }, sku: { type: 'text', uiReadonly: false } } })).toBe(false); + expect(childLinesOpenUnderParentHandLock({ fields: { qty: { type: 'number', uiReadonly: true } } })).toBe(false); + expect(childLinesOpenUnderParentHandLock({ fields: { qty: { type: 'number', readonly: true, uiReadonlyWhen: 'false' } } })).toBe(false); + expect(childLinesOpenUnderParentHandLock(undefined)).toBe(false); + }); +}); diff --git a/ui/packages/plugin-form/src/core.ts b/ui/packages/plugin-form/src/core.ts index f8cb42c3954..cc7cb659c96 100644 --- a/ui/packages/plugin-form/src/core.ts +++ b/ui/packages/plugin-form/src/core.ts @@ -31,7 +31,7 @@ export { sectionedGridLayout, } from './autoLayout'; export type { SectionedGridLayout } from './autoLayout'; -export { resolveInlineMode } from './deriveMasterDetail'; +export { childLinesOpenUnderParentHandLock, resolveInlineMode } from './deriveMasterDetail'; export type { InlineMode } from './deriveMasterDetail'; export { omitServerResolvedDefaults, optionListDefault } from './schemaDefaults'; export type { FieldDefaultsSchemaLike, OptionListFieldLike } from './schemaDefaults'; diff --git a/ui/packages/plugin-form/src/deriveMasterDetail.ts b/ui/packages/plugin-form/src/deriveMasterDetail.ts index 72aca4055a4..7cf189a457e 100644 --- a/ui/packages/plugin-form/src/deriveMasterDetail.ts +++ b/ui/packages/plugin-form/src/deriveMasterDetail.ts @@ -22,7 +22,7 @@ import { deriveInlineRowFormFields, } from '@objectstack/spec/data'; import { summaryDeclaresCurrency, type BooleanValueLabel, type GridColumn } from '@object-ui/fields'; -import { effectiveUiReadonlyWhen, isExpressionComputedField } from '@object-ui/core'; +import { effectiveUiReadonlyWhen, fieldStaticallyReadOnlyByHand, isExpressionComputedField } from '@object-ui/core'; /** * Minimal shape of a MASTER-DETAIL CHILD object's schema, as returned by @@ -322,6 +322,7 @@ function deriveColumn( // no hand lock of its own carries the child object's whole-record one. const handLockWhen = effectiveUiReadonlyWhen(d, childSchema); if (handLockWhen) (col as { uiReadonlyWhen?: unknown }).uiReadonlyWhen = handLockWhen; + markOwnHandLock(col, d); if (d?.requiredWhen) col.requiredWhen = d.requiredWhen; // A field carrying an arithmetic `expression` (e.g. amount = quantity * // unit_price) becomes a live read-only computed column. The expression may @@ -482,14 +483,91 @@ function withHandLock( // The EFFECTIVE predicate (objectstack#37402): the field's own, else the // child object's whole-record `uiReadonlyWhen`. const lockWhen = effectiveUiReadonlyWhen(d, childSchema); - if (!lockStatic && lockWhen == null) return col; + const ownsLock = childFieldOwnsHandLock(d); + if (!lockStatic && lockWhen == null && !ownsLock) return col; const next = { ...col } as GridColumn & { uiReadonly?: boolean; uiReadonlyWhen?: unknown }; if (lockStatic) next.uiReadonly = true; // The FIELD's predicate, never a column's own: the column may not open it. if (lockWhen != null) next.uiReadonlyWhen = lockWhen; + markOwnHandLock(next, d); return next; } +/** + * The PARENT's whole-record hand lock over its inline lines + * (objectstack#38249): while the parent object's `uiReadonlyWhen` holds over + * the parent record, a person adds, duplicates, removes, reorders and edits no + * line of it by hand. The lines are records of the CHILD object, whose own + * predicates cannot read the parent's columns, so the parent's lock reaches + * them here, as one more default under the same override the object level + * reads (`effectiveUiReadonlyWhen`, `@object-ui/core` `handLock.ts`): a child + * field that declares a hand lock of its own — `uiReadonly: true` or a + * `uiReadonlyWhen` — is judged by that declaration instead, so + * `uiReadonlyWhen: P\`false\`` keeps that one cell editable on a locked + * document; `uiReadonly: false` is not such a declaration. + * + * Declared writes (REST, import, actions, flows) are untouched: nothing on the + * server reads either key. + */ + +/** + * The in-memory mark a derived or hydrated column carries when its child field + * declares a hand lock of its own, so the parent's lock does not reach it. + * Never an authored `inlineColumns` key: an authored column with no child + * schema read carries no mark, and the parent's lock then locks it (the hand + * lock fails closed). + */ +const OWN_HAND_LOCK = 'uiReadonlyOwn'; + +/** Probe object for {@link childFieldOwnsHandLock}: its predicate is a value no field can declare. */ +const OBJECT_DEFAULT_PROBE = { uiReadonlyWhen: Object.freeze({}) }; + +/** + * True when a child field declares a hand lock of its own and is therefore + * judged by it rather than by any object-level default — the child object's or + * the parent's. Asked of `effectiveUiReadonlyWhen` itself, so this reads the + * one override rule rather than restating it. + */ +export function childFieldOwnsHandLock(def: Record | null | undefined): boolean { + if (!def) return false; + return effectiveUiReadonlyWhen(def, OBJECT_DEFAULT_PROBE) !== OBJECT_DEFAULT_PROBE.uiReadonlyWhen; +} + +function markOwnHandLock(col: GridColumn, d: Record | null | undefined): void { + if (childFieldOwnsHandLock(d)) (col as Record)[OWN_HAND_LOCK] = true; +} + +/** + * A collection's columns under its parent's whole-record hand lock: every + * column whose child field does not own a hand lock is locked on every row + * (`uiReadonly: true`, the in-memory carry `GridFieldWidget` judges first); a + * column whose field owns one keeps its own verdict. + */ +export function lockColumnsByParentHandLock(columns: readonly GridColumn[]): GridColumn[] { + return columns.map((col) => + (col as Record)[OWN_HAND_LOCK] === true + ? col + : ({ ...col, uiReadonly: true } as GridColumn), + ); +} + +/** + * Whether a line of this child object may still be edited by hand under its + * parent's whole-record hand lock: some child field owns a hand lock that is + * not static (`uiReadonly: true` / `readonly: true` still lock it), so its + * cell is judged by its own predicate. Read over the whole field map, not the + * drawn columns, so the answer fails open: a caller that greys a form's Edit on + * it keeps Edit live whenever any line cell might open. + */ +export function childLinesOpenUnderParentHandLock(childSchema: ChildObjectSchemaLike | null | undefined): boolean { + const fields = childSchema?.fields; + if (!fields || typeof fields !== 'object') return false; + return Object.values(fields).some( + (d) => !!d && typeof d === 'object' && childFieldOwnsHandLock(d as Record) + && !fieldStaticallyReadOnlyByHand(d as Record), + ); +} + /** * Field names for a child's full "row form" (the per-row expand editor) — the * form an inline master-detail collection opens when its author listed no diff --git a/ui/packages/plugin-form/src/index.tsx b/ui/packages/plugin-form/src/index.tsx index b48a9224bf3..5478a6fdc63 100644 --- a/ui/packages/plugin-form/src/index.tsx +++ b/ui/packages/plugin-form/src/index.tsx @@ -86,7 +86,7 @@ export type { BodyTableSnapshot, BodyTableRowError, } from './RecordBodyTableEditor'; -export { deriveDetail, deriveColumns, deriveFormFields, findRelationshipField, resolveInlineMode } from './deriveMasterDetail'; +export { childLinesOpenUnderParentHandLock, deriveDetail, deriveColumns, deriveFormFields, findRelationshipField, resolveInlineMode } from './deriveMasterDetail'; export type { DerivedDetail, InlineMode, ChildObjectSchemaLike } from './deriveMasterDetail'; /** From 81f9ef2c7687eddd3c80f3ed942f14de54e20eb7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 22:15:12 +0000 Subject: [PATCH 3/5] chore(changeset): plugin-form and app-shell for the inline-lines hand lock Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8 Co-authored-by: Claude --- .../38249-inline-lines-hand-lock-edit-state.md | 10 ++++++++++ .changeset/38249-inline-lines-hand-lock-form.md | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .changeset/38249-inline-lines-hand-lock-edit-state.md create mode 100644 .changeset/38249-inline-lines-hand-lock-form.md diff --git a/.changeset/38249-inline-lines-hand-lock-edit-state.md b/.changeset/38249-inline-lines-hand-lock-edit-state.md new file mode 100644 index 00000000000..923e430baf0 --- /dev/null +++ b/.changeset/38249-inline-lines-hand-lock-edit-state.md @@ -0,0 +1,10 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): the record page greys Edit on a hand-locked document whose inline lines are locked too + +Clause-②: no +Metadata-protocol: none + +The record page's Edit was always live on an object whose field groups place an inline child collection, because the edit form still edited its lines. Now that a parent's whole-record hand lock (`uiReadonlyWhen`) locks those lines as well, Edit goes off with the state-lock reason when the lock holds over the record, every header field the form draws is read-only, and no field of any placed child object owns a hand lock that could open a line cell. Without a child object's definition, or when a child field declares a `uiReadonlyWhen` of its own, Edit stays live as before. diff --git a/.changeset/38249-inline-lines-hand-lock-form.md b/.changeset/38249-inline-lines-hand-lock-form.md new file mode 100644 index 00000000000..69cbd70f5fa --- /dev/null +++ b/.changeset/38249-inline-lines-hand-lock-form.md @@ -0,0 +1,12 @@ +--- +'@object-ui/plugin-form': patch +--- + +fix(plugin-form): a parent's whole-record hand lock locks its inline master-detail lines in the edit form + +Clause-②: no +Metadata-protocol: none + +The master-detail edit form now reads the parent object's `uiReadonlyWhen` (the whole-record hand lock) over its lines too. While it holds over the parent record, a person adds, duplicates, removes or reorders no line, the per-row editor is not offered, and every line cell is locked unless its child field declares a hand lock of its own (`uiReadonly: true` or a `uiReadonlyWhen`), which then judges that cell instead — the same override the object level already reads. So a child field whose own `uiReadonlyWhen` is the constant `false` keeps that one cell editable on a confirmed order; `uiReadonly: false` is not such a declaration. A create is not judged. A fully configured entry (typed columns and the relationship field, so no child schema is read) has every line cell locked while the parent lock holds. REST, import, action and flow writes are unchanged: nothing on the server reads either key. + +New export `childLinesOpenUnderParentHandLock`, from the package root and from `@object-ui/plugin-form/core`: whether a child object's lines can still be edited under a locked parent (some child field owns a hand lock that is not static). From 9166fa4018f0c948320b11eceb91836f1097ca0c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 22:49:01 +0000 Subject: [PATCH 4/5] test(app-shell): pin the record page's Edit on a hand-locked document with inline lines Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8 Co-authored-by: Claude --- ...etailView.editLockedByState-32756.test.tsx | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/ui/packages/app-shell/src/views/RecordDetailView.editLockedByState-32756.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.editLockedByState-32756.test.tsx index c6c113fd3ee..d93c37781cf 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.editLockedByState-32756.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.editLockedByState-32756.test.tsx @@ -133,8 +133,8 @@ function stateLockBadge(): HTMLElement | null { } /** Mount the console record page and wait for the record read and the header. */ -async function mountRecordPage(record: Record, fields: Record) { - const objects = [objectDef(fields)]; +async function mountRecordPage(record: Record, fields: Record, served?: any[]) { + const objects = served ?? [objectDef(fields)]; const dataSource = makeDataSource(record); render( @@ -245,3 +245,48 @@ describe('console record header — a record whose state locks every edit-form f expect(stateLockBadge()).toBeNull(); }); }); + +/** + * objectstack#38249 — an object whose whole-record hand lock (`uiReadonlyWhen`) + * holds locks its inline lines in the edit form too, so the record page greys + * Edit even though its field groups place a child collection — unless a child + * field owns a hand lock that could open a line cell. + */ +describe('console record header — a hand-locked document with inline lines (objectstack#38249)', () => { + const LINE_OBJECT = 'ebqu_claim_line'; + const parent = { + ...objectDef({ + id: { type: 'text', label: 'Id' }, + name: { type: 'text', label: 'Title' }, + status: { type: 'text', label: 'Status' }, + }), + uiReadonlyWhen: "record.status == 'approved'", + groupSubforms: [{ childObject: LINE_OBJECT, relationshipField: 'claim' }], + }; + const line = (amount: Record = {}) => ({ + name: LINE_OBJECT, + label: 'Claim line', + fields: { + claim: { type: 'master_detail', label: 'Claim', reference: OBJECT_NAME }, + amount: { type: 'currency', label: 'Amount', ...amount }, + }, + }); + + it('draws Edit disabled when the object lock holds and no line cell can open', async () => { + await mountRecordPage(APPROVED, {}, [parent, line()]); + await waitFor(() => expect(headerEditButton()).toBeDisabled()); + expect(stateLockBadge()).toBeInTheDocument(); + }); + + it("CONTROL: a child field whose own uiReadonlyWhen is 'false' keeps Edit enabled", async () => { + await mountRecordPage(APPROVED, {}, [parent, line({ uiReadonlyWhen: 'false' })]); + expect(headerEditButton()).not.toBeDisabled(); + expect(stateLockBadge()).toBeNull(); + }); + + it('CONTROL: a state the object lock does not hold keeps Edit enabled', async () => { + await mountRecordPage(DRAFT, {}, [parent, line()]); + expect(headerEditButton()).not.toBeDisabled(); + expect(stateLockBadge()).toBeNull(); + }); +}); From 68f8bbbd65f882cfd1a13a0bcd3f10bb5836ad3b Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 23:51:18 +0000 Subject: [PATCH 5/5] chore(changeset): declare the inline-lines hand lock as a widening MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new plugin-form export and the optional editFormLockedByState argument widen published surface: Clause-② yes (widening), patch, protocol none. Claude-Session: https://claude.ai/code/session_017xRBcSPkRxFWubkD5XfiDh Co-authored-by: Claude --- .changeset/38249-inline-lines-hand-lock-edit-state.md | 4 +++- .changeset/38249-inline-lines-hand-lock-form.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.changeset/38249-inline-lines-hand-lock-edit-state.md b/.changeset/38249-inline-lines-hand-lock-edit-state.md index 923e430baf0..701b2421593 100644 --- a/.changeset/38249-inline-lines-hand-lock-edit-state.md +++ b/.changeset/38249-inline-lines-hand-lock-edit-state.md @@ -4,7 +4,9 @@ fix(app-shell): the record page greys Edit on a hand-locked document whose inline lines are locked too -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none The record page's Edit was always live on an object whose field groups place an inline child collection, because the edit form still edited its lines. Now that a parent's whole-record hand lock (`uiReadonlyWhen`) locks those lines as well, Edit goes off with the state-lock reason when the lock holds over the record, every header field the form draws is read-only, and no field of any placed child object owns a hand lock that could open a line cell. Without a child object's definition, or when a child field declares a `uiReadonlyWhen` of its own, Edit stays live as before. + +Additive: the exported `editFormLockedByState` takes an optional fourth argument, `childObjectDef` (a child object name to its served definition); callers that omit it behave as before. diff --git a/.changeset/38249-inline-lines-hand-lock-form.md b/.changeset/38249-inline-lines-hand-lock-form.md index 69cbd70f5fa..54bbab75f31 100644 --- a/.changeset/38249-inline-lines-hand-lock-form.md +++ b/.changeset/38249-inline-lines-hand-lock-form.md @@ -4,7 +4,7 @@ fix(plugin-form): a parent's whole-record hand lock locks its inline master-detail lines in the edit form -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none The master-detail edit form now reads the parent object's `uiReadonlyWhen` (the whole-record hand lock) over its lines too. While it holds over the parent record, a person adds, duplicates, removes or reorders no line, the per-row editor is not offered, and every line cell is locked unless its child field declares a hand lock of its own (`uiReadonly: true` or a `uiReadonlyWhen`), which then judges that cell instead — the same override the object level already reads. So a child field whose own `uiReadonlyWhen` is the constant `false` keeps that one cell editable on a confirmed order; `uiReadonly: false` is not such a declaration. A create is not judged. A fully configured entry (typed columns and the relationship field, so no child schema is read) has every line cell locked while the parent lock holds. REST, import, action and flow writes are unchanged: nothing on the server reads either key.