Skip to content

Commit 444dce6

Browse files
fix(console): the record edit dialog opens locked with the closed sentence on a closed record (ADR-0162) (#39019)
Fixes #38997 Clause-②: yes (widening) Metadata-protocol: none The widening (L1 7333040997): the exported `lockedBy` prop of `RecordFieldAccessScopeProps` (`@object-ui/permissions`) and of `ModalFormProps` (`@object-ui/plugin-form`) accepts `'closed'` beside `'approval'`. Level stays `patch`. ## 维护者速读 - 控制台里打开已关闭记录(如已付款发票)的完整编辑弹窗时,弹窗直接只读,提示“此记录已关闭,无法更改”,不再提供保存;以前弹窗可编辑,点保存才被服务器拒绝。审批中的记录与今天一样。 - 属于“记录关闭态锁”这一组工作,让编辑弹窗与记录页对已关闭记录给出同一个答案。 - 出错时,已关闭记录的弹窗可能仍可编辑(服务器照旧拒绝保存),或审批中的记录显示成“已关闭”;改动只在控制台,可直接撤回。 - 无 ## What changes Item 2 of the card: the console's full-record edit dialog locks on a closed record. Item 1 (the edit-state save order) landed in #39007. - **Dialog** (`ui/packages/app-shell/src/console/AppContent.tsx`): reads `recordClosedByLock` from the `useRecordApprovals` hook the dialog already uses for its approval lock, and hands `ModalForm` `lockedBy: 'closed'`. Precedence: **closed wins** over an approval hold, as on the record page (`recordClosedByLock` is true for a record both closed and held). An approval-held record that is not closed keeps `lockedBy: 'approval'`, unchanged. - **Scope** (`ui/packages/permissions/src/RecordFieldAccessScope.tsx`): `lockedBy` accepts `'closed'` beside `'approval'`. The row's update is refused with the new reason `record-closed`, and every field of it is not writable, exactly as for `'approval'`. A projection answering `writable: false` keeps its own reason, as it already does over `'approval'`. - **Form gate** (`ui/packages/plugin-form/src/fieldWriteGate.ts`): `record-closed` maps to a new `'closed'` affordance, and `closedForRecord` treats it like `'approval'`, so the dialog (and the drawer) offer no Save. - **Notice** (`closedAffordanceNotice.tsx`): `'closed'` says the record page's closed sentence, `detail.lockedClosedTooltip` ("This record is closed, so it can't be changed."). No new locale key; the provider-less defaults row repeats the en value (`check:i18n-keys` green). - `ModalForm.tsx` and `recordFieldAccess.tsx` widen `lockedBy` to the scope's own prop type. - Changeset: `.changeset/38997-edit-dialog-closed-lock.md` (permissions, plugin-form, app-shell; patch). ## Tests Written first and run red (6 red, 23 existing green), then green after the fix. - `AppContent.editDialogApprovalLock-27138.test.tsx`, new describe: a closed record hands `lockedBy: 'closed'`; a closed record a pending approval also holds hands `'closed'`; a closed record sends exactly the three lock reads an open one sends. The approval-held cases above it are the control and are unchanged (`'approval'`). - `recordFieldAccess.rowWritable-27138.test.tsx`, new describe: `ModalForm` with `lockedBy="closed"`, on a writable row and on a data source without the projection, draws every field read-only, the notice with `data-affordance="closed"` and the closed sentence, and no Save. - `RecordFieldAccessScope.rowWritable-27138.test.tsx`: `lockedBy: 'closed'` refuses the update with `record-closed` before any answer and over `writable: true`; read stays allowed. <details><summary>Ablation (restored, blob equal to HEAD)</summary> - `AppContent.tsx`: the closed test replaced by `false` turns the 3 new dialog cases red; the 6 approval and control cases stay green. </details> ## Acceptance notes - Requests: none added. The dialog reads the hook it already mounted. Over a list it sends the same three lock reads as before (pinned for a closed record too); on a record page the hook joins the page's payload answer. The record page's one-request pins (27627, 28470, 12701, 13010, 28737) pass unedited. - Precedence chosen: closed over approval, the record page's rule; stated in the code comment and the changeset. - The drawer form (`DrawerForm`) shares the gate and would draw the `'closed'` affordance too, but no host passes it a `lockedBy` today; not changed here. ## Verification Two-minute check, from `ui/`: `pnpm exec vitest run packages/app-shell/src/console/__tests__/AppContent.editDialogApprovalLock-27138.test.tsx`: 9 passed, including the three closed cases. Read first: `AppContent.tsx` (the precedence line), then `RecordFieldAccessScope.tsx` (the refusal reason), then `fieldWriteGate.ts`. <details><summary>Local readings, head c564f48</summary> - plugin-form and permissions suites: 272 files, 3,028 passed, 1 skipped. - app-shell: all 55 `AppContent*` files plus the five one-request record-open pin files: 60 files, 626 passed. - `type-check`: permissions, plugin-form and app-shell exit 0 (after rebuilding the permissions and plugin-form dist the downstream tsc reads). - eslint on the nine touched files (package config): 0 errors. With `--no-inline-config` one error stands in `ModalForm.tsx` ("Cannot create components during render"), present at the same place on main. - `dispatch-gates --ran` at c564f48: 38 derived, 38 run, 0 NOT-MEASURED. ui `check:i18n-keys`: exit 0. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ <!-- signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhKEbEnW8pwZRgK2gJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f28c39f commit 444dce6

10 files changed

Lines changed: 144 additions & 27 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/permissions': patch
3+
'@object-ui/plugin-form': patch
4+
'@object-ui/app-shell': patch
5+
---
6+
7+
fix(console): the record edit dialog opens locked with the closed sentence on a closed record
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
The widening: the exported `lockedBy` prop of `RecordFieldAccessScopeProps` (`@object-ui/permissions`) and of `ModalFormProps` (`@object-ui/plugin-form`) accepts `'closed'` beside `'approval'`.
13+
14+
The console's full-record edit dialog now opens read-only on a closed record (one of its object's `closedStates` holds, its own or its master's, ADR-0162). It says "This record is closed, so it can't be changed." (the record page's sentence, `detail.lockedClosedTooltip`) and offers no Save. Before, it opened editable and the server's refusal of the save was the user's first notice.
15+
16+
- The dialog reads the closed state from the data lock the record page reads (`recordClosedByLock` on `useRecordApprovals`). It sends no request of its own: on a record page it uses the page's answer.
17+
- A record that is closed and also held by an approval reads as closed, as on the record page. A record held only by an approval reads as before.
18+
- `RecordFieldAccessScope`, `ModalForm` and `RecordFieldAccessForForm` accept `lockedBy: 'closed'` beside `'approval'`. The scope refuses the row's update with the new reason `record-closed`, and `closedFormAffordance` answers it as the new `'closed'` affordance, which `closedForRecord` treats like `'approval'` (no Save).

‎ui/packages/app-shell/src/console/AppContent.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ConsoleFormOwnerLine } from '../views/consoleFormOwnerLine.js';
1616
import { Empty, EmptyTitle, EmptyDescription, Button, DataErrorState, cn } from '@object-ui/components';
1717
import { toast } from 'sonner';
1818
import { useActionRunner, useGlobalUndo, useMutationInvalidationBridge, notifyDataChanged, FilterScopeProvider, resolveApprovalLock, claimAnswerWarnings, toastRecordSave, type AnswerWarningClaim, type AnsweredLoadFailure, type RecordSaveFeedback } from '@object-ui/react';
19-
import { useRecordApprovals, openApprovalOf } from '../hooks/useRecordApprovals.js';
19+
import { useRecordApprovals, openApprovalOf, recordClosedByLock } from '../hooks/useRecordApprovals.js';
2020
import { useObjectTranslation, useObjectLabel, recordSaveMessage as buildRecordSaveMessage } from '@object-ui/i18n';
2121
import type { AppAccessVerdict, ConnectionState } from '@object-ui/data-objectstack';
2222
import { useAuth, useWorkspaceAdminStatus } from '@object-ui/auth';
@@ -1079,6 +1079,15 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
10791079
openApproval: openApprovalOf(formApprovals),
10801080
recordStatus: undefined,
10811081
}).locked;
1082+
// objectstack#38997 (ADR-0162) — a CLOSED record (a closed state of its
1083+
// object holds, its own or its master's), from the same hook's data lock
1084+
// read (`recordClosedByLock`, the record page's rule), so the dialog asks
1085+
// nothing of its own: on a record page it joins the page's payload answer.
1086+
// It opens read-only with the record page's closed sentence; a record both
1087+
// closed and held reads as closed, as on the record page.
1088+
const formLockedBy: 'closed' | 'approval' | undefined = recordClosedByLock(formApprovals)
1089+
? 'closed'
1090+
: formApprovalLocked ? 'approval' : undefined;
10821091

10831092
// objectstack-ai/objectstack#26172 — a record save names the record it wrote
10841093
// (`ux-conventions.write-feedback`): `Task "Quarterly review" created`. The
@@ -1774,7 +1783,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
17741783
<ConsoleFormOwnerLine>
17751784
<LazyModalForm
17761785
key={`${formObjectDef.name}:${editingRecord?.id || 'new'}`}
1777-
lockedBy={formApprovalLocked ? 'approval' : undefined}
1786+
lockedBy={formLockedBy}
17781787
schema={{
17791788
type: 'object-form',
17801789
formType: 'modal',

‎ui/packages/app-shell/src/console/__tests__/AppContent.editDialogApprovalLock-27138.test.tsx‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
* → `'approval'`; it declares `lockRecord: false` → no lock;
2424
* - CONTROL no approval running → no lock;
2525
* - CONTROL a create dialog asks nothing and is not locked.
26+
*
27+
* objectstack#38997 (ADR-0162) — the same hook's data lock answering
28+
* `lockReason: 'closed_state'` → `lockedBy: 'closed'`, also when an approval
29+
* holds the record as well (closed wins, as on the record page); no read of
30+
* its own beyond the hook's.
2631
*/
2732

2833
import '@testing-library/jest-dom/vitest';
@@ -131,7 +136,7 @@ vi.mock('@object-ui/react', async (importOriginal) => ({
131136
import { AppContent } from '../AppContent';
132137
import { __resetRecordApprovalsStore } from '../../hooks/useRecordApprovals';
133138

134-
type Approvals = { requests: any[]; lock: boolean };
139+
type Approvals = { requests: any[]; lock: boolean; closed?: boolean };
135140

136141
/** What the approvals routes answer; set per test. */
137142
let served: Approvals = { requests: [], lock: false };
@@ -143,7 +148,12 @@ const fetchSpy = vi.fn(async (input: RequestInfo | URL) => {
143148
// objectstack#37773 — the dialog's lock is the data layer's one lock read
144149
// (`/data/:object/:id/lock`), answering `lockReason: 'approval'` here.
145150
const body = /\/data\/[^/]+\/[^/]+\/lock$/.test(url)
146-
? { success: true, data: served.lock ? { locked: true, lockSource: 'record', lockReason: 'approval' } : { locked: false } }
151+
? {
152+
success: true,
153+
data: served.closed
154+
? { locked: true, lockSource: 'record', lockReason: 'closed_state' }
155+
: served.lock ? { locked: true, lockSource: 'record', lockReason: 'approval' } : { locked: false },
156+
}
147157
: url.includes('/approvals/records/')
148158
? { success: true, data: { locked: served.lock } }
149159
: url.includes('/approvals/requests?')
@@ -238,3 +248,30 @@ describe('[#27138] the console edit dialog reads the approvals record lock', ()
238248
expect(approvalReads(fetchSpy)).toEqual([]);
239249
});
240250
});
251+
252+
describe('[#38997] the console edit dialog reads the closed lock (ADR-0162)', () => {
253+
it.each([
254+
['a closed record', { requests: [], lock: false, closed: true }],
255+
['a closed record an approval also holds (closed wins)', { requests: [PENDING], lock: true, closed: true }],
256+
])('%s: the dialog is handed the closed lock', async (_label, approvals) => {
257+
serveApprovals(approvals);
258+
openAt('/apps/crm/crm_contract?form=r1');
259+
await waitFor(() => expect(lastModal()?.schema?.mode).toBe('edit'));
260+
await waitFor(() => expect(lastModal().lockedBy).toBe('closed'));
261+
});
262+
263+
it('a closed record adds no read: the same three lock-ish reads as an open one', async () => {
264+
const fetchSpy = serveApprovals({ requests: [], lock: false, closed: true });
265+
openAt('/apps/crm/crm_contract?form=r1');
266+
await waitFor(() => expect(lastModal()?.lockedBy).toBe('closed'));
267+
await new Promise((r) => setTimeout(r, 20));
268+
const lockishReads = fetchSpy.mock.calls
269+
.map(([u]) => new URL(String(u), 'http://x').pathname)
270+
.filter((u) => u.includes('/approvals/') || u.endsWith('/lock'));
271+
expect(lockishReads.sort()).toEqual([
272+
'/api/v1/approvals/records/crm_contract/r1/lock',
273+
'/api/v1/approvals/requests',
274+
'/api/v1/data/crm_contract/r1/lock',
275+
]);
276+
});
277+
});

‎ui/packages/permissions/src/RecordFieldAccessScope.tsx‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ export interface RecordFieldAccessAnswer {
3535
*
3636
* - `record-not-writable` — the projection answered `writable: false`;
3737
* - `record-locked-by-approval` — the host reported a pending approval that
38-
* locks the record (`lockedBy: 'approval'`).
38+
* locks the record (`lockedBy: 'approval'`);
39+
* - `record-closed` — the host reported the record closed: one of its
40+
* object's closed states holds, its own or its master's (`lockedBy:
41+
* 'closed'`, ADR-0162).
3942
*/
40-
type RecordWriteRefusal = 'record-not-writable' | 'record-locked-by-approval';
43+
type RecordWriteRefusal = 'record-not-writable' | 'record-locked-by-approval' | 'record-closed';
4144

4245
export interface RecordFieldAccessScopeProps {
4346
/** The object the record belongs to. Matched case-insensitively, as `MePermissionsProvider` matches object names. */
@@ -62,11 +65,14 @@ export interface RecordFieldAccessScopeProps {
6265
* A lock on the record that the projection does not judge and the host
6366
* reads from its own door: `'approval'` while a pending approval locks the
6467
* record (the approvals service's record lock, answered to every reader).
65-
* The row then answers as not writable, exactly as `writable: false` does,
66-
* without waiting for the projection. The host passes the verdict it already
67-
* draws its own lock from; the scope never re-derives it.
68+
* `'closed'` while the record is closed (ADR-0162: a closed state of its
69+
* object holds, its own or its master's, as the data layer's lock read
70+
* answers it). The row then answers as not writable, exactly as
71+
* `writable: false` does, without waiting for the projection. The host
72+
* passes the verdict it already draws its own lock from, and decides which
73+
* one when both hold; the scope never re-derives it.
6874
*/
69-
lockedBy?: 'approval';
75+
lockedBy?: 'approval' | 'closed';
7076
children: ReactNode;
7177
}
7278

@@ -168,7 +174,8 @@ function scoped(
168174
const refusal: RecordWriteRefusal | undefined =
169175
answer?.writable === false ? 'record-not-writable'
170176
: lockedBy === 'approval' ? 'record-locked-by-approval'
171-
: undefined;
177+
: lockedBy === 'closed' ? 'record-closed'
178+
: undefined;
172179
const result = refusal ? refusedRow(value, objKey, recordId, refusal) : value;
173180
SCOPE_OF.set(result, key);
174181
byAnswer.set(answerKey, result);
@@ -238,7 +245,8 @@ function refusedRow(
238245
* why. `lockedBy: 'approval'` answers the same way with the reason
239246
* `record-locked-by-approval`: the approvals record lock is judged on the
240247
* values a save sends, so the projection leaves it out, and the host passes
241-
* the lock it already reads. `writable: true` or an absent `writable` changes
248+
* the lock it already reads. `lockedBy: 'closed'` does too, with the reason
249+
* `record-closed` (ADR-0162's closed-state lock, also outside the projection). `writable: true` or an absent `writable` changes
242250
* nothing. Until the answer arrives the row-blind answer stands for the row,
243251
* as it does for the fields.
244252
*

‎ui/packages/permissions/src/__tests__/RecordFieldAccessScope.rowWritable-27138.test.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const PROJECTION = { editable: ['title', 'summary'] };
6666
function mount(
6767
load: (o: string, id: string) => Promise<any>,
6868
{ lockedBy, principal = ANSWER, nestedLock = false }: {
69-
lockedBy?: 'approval';
69+
lockedBy?: 'approval' | 'closed';
7070
principal?: MePermissionsResponse;
7171
nestedLock?: boolean;
7272
} = {},
@@ -137,6 +137,20 @@ describe('[#27138] RecordFieldAccessScope — the row verdict', () => {
137137
expect(writable.last().check('rfa_contract', 'update').reason).toBe('record-locked-by-approval');
138138
});
139139

140+
// objectstack#38997 — ADR-0162: the host's closed lock answers the same way, with its own reason.
141+
it("a host's closed lock refuses the row with record-closed, before any answer and over a writable one", async () => {
142+
let resolve: ((v: any) => void) | undefined;
143+
const pending = mount(() => new Promise((r) => { resolve = r; }), { lockedBy: 'closed' });
144+
await waitFor(() => expect(resolve).toBeTypeOf('function'));
145+
expect(pending.last().check('rfa_contract', 'update')).toEqual({ allowed: false, reason: 'record-closed' });
146+
expect(pending.last().checkField('rfa_contract', 'title', 'write')).toBe(false);
147+
expect(pending.last().checkField('rfa_contract', 'title', 'read')).toBe(true);
148+
149+
const writable = mount(async () => ({ ...PROJECTION, writable: true }), { lockedBy: 'closed' });
150+
await new Promise((r) => setTimeout(r, 0));
151+
expect(writable.last().check('rfa_contract', 'update').reason).toBe('record-closed');
152+
});
153+
140154
it('an object grant the enclosing provider refuses keeps its own reason', async () => {
141155
const { last } = mount(async () => ({ ...PROJECTION, writable: false }), { principal: READ_ONLY_GRANT });
142156
await new Promise((r) => setTimeout(r, 0));

‎ui/packages/plugin-form/src/ModalForm.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
type LoadedRecordSnapshot,
7373
} from './sanitize';
7474
import { closedForRecord, closedFormAffordance, fieldWriteGate, gateFormFields } from './fieldWriteGate';
75-
import { RecordFieldAccessForForm } from './recordFieldAccess';
75+
import { RecordFieldAccessForForm, type RecordFieldAccessForFormProps } from './recordFieldAccess';
7676
import { ClosedAffordanceNotice } from './closedAffordanceNotice';
7777
import { seedCreateValues } from './schemaDefaults';
7878
import { createWritePayload } from './writePayload';
@@ -317,11 +317,12 @@ export interface ModalFormProps {
317317
/**
318318
* A lock on the edited record that the host reads and the record's field
319319
* projection leaves out: `'approval'` while a pending approval locks it
320-
* (objectstack#27138). The dialog then draws the record read-only, says
320+
* (objectstack#27138), `'closed'` while the record is closed (ADR-0162,
321+
* objectstack#38997). The dialog then draws the record read-only, says
321322
* why, and offers no Save, as it does for a row the server answers
322323
* `writable: false`. Read on an `edit` form with a `recordId` only.
323324
*/
324-
lockedBy?: 'approval';
325+
lockedBy?: RecordFieldAccessForFormProps['lockedBy'];
325326
}
326327

327328
/**

‎ui/packages/plugin-form/src/closedAffordanceNotice.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import type { ClosedFormAffordance } from './fieldWriteGate';
4040
* sentence names the record, not the object: the caller may edit other
4141
* records of it. `record` is the server's row verdict (sharing, ownership,
4242
* row-level security); `approval` a pending approval that locks the record,
43-
* said with the record page's own lock sentence.
43+
* said with the record page's own lock sentence; `closed` a record in one of
44+
* its object's closed states (ADR-0162), said with the record page's own
45+
* closed sentence.
4446
*
4547
* `role="status"`, the package's pattern for a form state (`UploadInFlightNotice`):
4648
* nothing has failed, and an assertive live region would interrupt a
@@ -54,6 +56,7 @@ const useClosedAffordanceTranslation = createSafeTranslation(
5456
'form.noPermissionToEdit': "You don't have permission to edit {{object}} records. The fields are read-only.",
5557
'form.noPermissionToEditRecord': "You don't have permission to edit this record. The fields are read-only.",
5658
'detail.lockedTooltip': 'This record has a pending approval request; editing is locked',
59+
'detail.lockedClosedTooltip': "This record is closed, so it can't be changed.",
5760
},
5861
'form.noPermissionToCreate',
5962
);
@@ -87,9 +90,11 @@ export function ClosedAffordanceNotice({
8790
? t('form.noPermissionToEditRecord')
8891
: affordance === 'approval'
8992
? t('detail.lockedTooltip')
90-
: affordance === 'edit'
91-
? t('form.noPermissionToEdit', { object })
92-
: t('form.noPermissionToCreate', { object });
93+
: affordance === 'closed'
94+
? t('detail.lockedClosedTooltip')
95+
: affordance === 'edit'
96+
? t('form.noPermissionToEdit', { object })
97+
: t('form.noPermissionToCreate', { object });
9398

9499
return (
95100
<p

‎ui/packages/plugin-form/src/fieldWriteGate.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ function managedModeLocked(
281281
* THIS record refusing the update while the object allows it (objectstack#27138)
282282
* — `record` when the server's record projection answered `writable: false`
283283
* (sharing, ownership, row-level security), `approval` when the host reported
284-
* a pending approval that locks the record.
284+
* a pending approval that locks the record, `closed` when the host reported
285+
* the record closed (ADR-0162: a closed state of its object holds).
285286
*/
286-
export type ClosedFormAffordance = 'create' | 'edit' | 'record' | 'approval';
287+
export type ClosedFormAffordance = 'create' | 'edit' | 'record' | 'approval' | 'closed';
287288

288289
/**
289290
* The row reasons `RecordFieldAccessScope` (`@object-ui/permissions`) answers
@@ -294,6 +295,7 @@ export type ClosedFormAffordance = 'create' | 'edit' | 'record' | 'approval';
294295
const ROW_REFUSALS: ReadonlyMap<string, ClosedFormAffordance> = new Map<string, ClosedFormAffordance>([
295296
['record-not-writable', 'record'],
296297
['record-locked-by-approval', 'approval'],
298+
['record-closed', 'closed'],
297299
]);
298300

299301
/**
@@ -302,7 +304,7 @@ const ROW_REFUSALS: ReadonlyMap<string, ClosedFormAffordance> = new Map<string,
302304
* nothing on the form the server would accept (objectstack#27138).
303305
*/
304306
export function closedForRecord(affordance: ClosedFormAffordance | undefined): boolean {
305-
return affordance === 'record' || affordance === 'approval';
307+
return affordance === 'record' || affordance === 'approval' || affordance === 'closed';
306308
}
307309

308310
/**
@@ -313,7 +315,7 @@ export function closedForRecord(affordance: ClosedFormAffordance | undefined): b
313315
*
314316
* It is {@link managedModeLocked}, the very predicate {@link gateFormFields}
315317
* disables every drawn field on, read for its reason: `create` for a create
316-
* form, `edit` for an edit form, and `record` / `approval` for an edit form
318+
* form, `edit` for an edit form, and `record` / `approval` / `closed` for an edit form
317319
* whose own row refuses the update (the reason the scoped `check` gave). The
318320
* locked form's notice
319321
* (`ClosedAffordanceNotice`) and the wizard's navigation gate read THIS, not a

‎ui/packages/plugin-form/src/recordFieldAccess.rowWritable-27138.test.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
* `AppContent` passes for a record a pending approval locks) → read-only, the
2727
* record page's lock sentence, no Save — on a data source without the record
2828
* projection too.
29+
* And under the host's closed lock (`lockedBy: 'closed'`, what `AppContent`
30+
* passes for a record in one of its object's closed states, ADR-0162) →
31+
* read-only, the record page's closed sentence, no Save (objectstack#38997).
2932
*/
3033
import { describe, it, expect, vi, afterEach } from 'vitest';
3134
import { render, waitFor, cleanup } from '@testing-library/react';
@@ -163,3 +166,22 @@ describe("[#27138] the console's edit dialog under the host's approval lock", ()
163166
expect(saveButtons()).toBe(0);
164167
});
165168
});
169+
170+
describe("[#38997] the console's edit dialog under the host's closed lock (ADR-0162)", () => {
171+
it.each([
172+
['a writable row', { ...PROJECTION, writable: true }],
173+
['a data source without the record projection', null],
174+
])('on %s, a closed record is drawn read-only with the closed sentence and no Save', async (_label, access) => {
175+
const ds = makeDS(access);
176+
render(
177+
<MePermissionsProvider initialPermissions={principal(true)}>
178+
<ModalForm schema={schema('modal')} dataSource={ds as any} lockedBy="closed" />
179+
</MePermissionsProvider>,
180+
);
181+
await drawn();
182+
await waitFor(() => expect(locked()).toEqual({ title: true, summary: true }));
183+
expect(notice()?.getAttribute('data-affordance')).toBe('closed');
184+
expect(notice()?.textContent).toBe("This record is closed, so it can't be changed.");
185+
expect(saveButtons()).toBe(0);
186+
});
187+
});

‎ui/packages/plugin-form/src/recordFieldAccess.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,23 @@
4141
* `writable: false` the scope refuses every field of the record and the
4242
* record's update, so the form draws read-only, says why and offers no Save.
4343
* A host that reads a lock the projection leaves out — a pending approval
44-
* that locks the record — passes it as `lockedBy`, and it reaches the same
44+
* that locks the record, or the record being closed (ADR-0162) — passes it as
45+
* `lockedBy`, and it reaches the same
4546
* gates the same way. A form edits a stored record under that lock even on a
4647
* data source without the projection: the scope then has no answer to ask
4748
* for, and only the host's lock narrows the row.
4849
*/
4950

5051
import React, { useEffect, useState } from 'react';
51-
import { RecordFieldAccessScope } from '@object-ui/permissions';
52+
import { RecordFieldAccessScope, type RecordFieldAccessScopeProps } from '@object-ui/permissions';
5253
import { useDataInvalidation } from '@object-ui/react';
5354
import type { DataSource } from '@object-ui/types';
5455

5556
export interface RecordFieldAccessForFormProps {
5657
schema: { objectName?: string; mode?: string; recordId?: string | number | null };
5758
dataSource?: DataSource | null;
5859
/** A lock the host reads on the record and the projection leaves out (`RecordFieldAccessScope`'s `lockedBy`). */
59-
lockedBy?: 'approval';
60+
lockedBy?: RecordFieldAccessScopeProps['lockedBy'];
6061
children: React.ReactNode;
6162
}
6263

0 commit comments

Comments
 (0)