Skip to content

Commit 5e60936

Browse files
committed
feat(console): the record page reads the data lock from its one payload request (ADR-0162 item 4)
Re-applies the record-page half held back from #38994. Edit and Delete read the data layer's lock (`dataLock`), which the page payload now carries (`dataLock: true` on `POST /data/:object/:id/page`), so a closed record is greyed and worded as closed without a second request. Reads the hook sends itself (the edit dialog over a list, a refresh after a change) keep asking `GET /data/:object/:id/lock`. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ
1 parent 77d1564 commit 5e60936

21 files changed

Lines changed: 609 additions & 69 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/types': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
fix(console): a closed record's page reads as closed, not as in approval, from the page's one request
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
The record page now reads the data layer's lock for its Edit and Delete, and words the reason from its `lockReason`. It asks for that lock in the request it already sends when it opens (`POST /api/v1/data/{object}/{id}/page` with `dataLock: true`), so opening a record page is still one request. It no longer asks the approvals lock read for these affordances; the approvals panel and the header's approval tag keep reading it.
13+
14+
- A closed record (`lockReason: 'closed_state'`, its own state or its master's) shows Edit greyed with "This record is closed, so it can't be changed.", a "Closed" chip, and no Delete, for either `lockSource`. Its master-detail lines offer no New, Edit or Delete. A record that is closed and also held by an approval reads as closed.
15+
- A record held by an approval behaves as before: its own approval keeps Delete, and a line of a held master does not.
16+
- The answer is read above the caller's field permissions, so a reader who may not see the state field still gets the closed wording, and the page shows neither the field nor its value.
17+
- When nothing on screen is a record page, the edit dialog opened over a list reads the record's lock through `GET /api/v1/data/{object}/{id}/lock` next to its approvals reads. The record page does the same when it re-reads after the record changes. Over its record page, the dialog reuses the page's answer and sends nothing.
18+
- `RecordPagePayload` (`@object-ui/types`) declares the payload's `dataLock` part.
19+
- New strings `detail.lockedClosed` and `detail.lockedClosedTooltip` in every console locale.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import React from 'react';
3131
import { render, cleanup, waitFor } from '@testing-library/react';
3232
import { MemoryRouter, Routes, Route } from 'react-router-dom';
3333
import { registerAllFields } from '@object-ui/fields';
34+
// The console chain reaches `@objectstack/lint` behind a dynamic import; pay its first load at collection.
35+
import '@objectstack/lint';
3436

3537
registerAllFields();
3638

@@ -138,7 +140,11 @@ let served: Approvals = { requests: [], lock: false };
138140
// test body returns can reach a socket; handed back in `afterAll`.
139141
const fetchSpy = vi.fn(async (input: RequestInfo | URL) => {
140142
const url = String(input);
141-
const body = url.includes('/approvals/records/')
143+
// objectstack#37773 — the dialog's lock is the data layer's one lock read
144+
// (`/data/:object/:id/lock`), answering `lockReason: 'approval'` here.
145+
const body = /\/data\/[^/]+\/[^/]+\/lock$/.test(url)
146+
? { success: true, data: served.lock ? { locked: true, lockSource: 'record', lockReason: 'approval' } : { locked: false } }
147+
: url.includes('/approvals/records/')
142148
? { success: true, data: { locked: served.lock } }
143149
: url.includes('/approvals/requests?')
144150
? { data: served.requests }

‎ui/packages/app-shell/src/hooks/useRecordApprovals.lockSource-37195.test.tsx‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@
1313
* (`POST /data/:object/:id/page`) answers the lock beside the rows whether or
1414
* not a pending request decides it, so the kind is kept beside a pending
1515
* request too — a self-held line under a held master answers `'master'`.
16+
*
17+
* objectstack#37773 — beside the payload's approvals lock, the hook asks the
18+
* data layer's one lock read (`GET /data/:object/:id/lock`, ADR-0162 D9),
19+
* which the payload does not carry, and hands it back as `dataLock` in the
20+
* same publish. The affordances read that one: `recordClosedByLock`,
21+
* `openApprovalOf`.
1622
*/
1723

18-
import { describe, it, expect, afterEach } from 'vitest';
24+
import { describe, it, expect, afterEach, afterAll, vi } from 'vitest';
1925
import { renderHook, waitFor, act } from '@testing-library/react';
2026
import {
2127
__resetRecordApprovalsStore,
28+
openApprovalOf,
29+
recordClosedByLock,
2230
recordLockAnswerOf,
2331
seedRecordApprovals,
2432
useRecordApprovals,
@@ -36,8 +44,25 @@ const PENDING_ROW = {
3644
lock_record: true,
3745
};
3846

47+
/** What the data layer's lock door answers; set per test. */
48+
let dataLock: Record<string, unknown> = { locked: false };
49+
const dataLockGets: string[] = [];
50+
// Installed once for the whole file: the seeded read asks the data lock door
51+
// beside the payload, and no read may reach a socket after a test returns.
52+
vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL) => {
53+
const url = String(input);
54+
if (url.endsWith(`/data/${OBJECT}/${RECORD}/lock`)) {
55+
dataLockGets.push(url);
56+
return new Response(JSON.stringify({ success: true, data: dataLock }), { status: 200, headers: { 'content-type': 'application/json' } });
57+
}
58+
return new Response(JSON.stringify({ data: [] }), { status: 200, headers: { 'content-type': 'application/json' } });
59+
}));
60+
afterAll(() => vi.unstubAllGlobals());
61+
3962
afterEach(() => {
4063
__resetRecordApprovalsStore();
64+
dataLock = { locked: false };
65+
dataLockGets.length = 0;
4166
});
4267

4368
async function seeded(answer: SeededRecordApprovals) {
@@ -87,3 +112,30 @@ describe('recordLockAnswerOf — the two bits the lock doors serve, as the grid
87112
expect(recordLockAnswerOf(null)).toEqual({ locked: false });
88113
});
89114
});
115+
116+
describe('useRecordApprovals — the data layer\'s lock read beside the payload (objectstack#37773)', () => {
117+
it('a closed record: `dataLock` names `closed_state`, so the record reads closed and no approval opens', async () => {
118+
dataLock = { locked: true, lockSource: 'record', lockReason: 'closed_state' };
119+
const out = await seeded({ requests: [], lock: { locked: false } });
120+
expect(dataLockGets).toHaveLength(1);
121+
expect(out.dataLock).toEqual({ locked: true, lockSource: 'record', lockReason: 'closed_state' });
122+
expect(recordClosedByLock(out)).toBe(true);
123+
expect(openApprovalOf(out)).toBeNull();
124+
// The approvals panel's lock is the payload's, untouched.
125+
expect(out.recordLock).toEqual({ locked: false });
126+
});
127+
128+
it('a record held by an approval the reader cannot see: the data lock opens it, whatever the approvals-family lock says', async () => {
129+
dataLock = { locked: true, lockSource: 'record', lockReason: 'approval' };
130+
const out = await seeded({ requests: [], lock: { locked: false } });
131+
expect(recordClosedByLock(out)).toBe(false);
132+
expect(openApprovalOf(out)).toEqual({ locked: true });
133+
});
134+
135+
it('CONTROL: the approvals-family lock alone opens no approval for the affordances', async () => {
136+
dataLock = { locked: false };
137+
const out = await seeded({ requests: [], lock: { locked: true, lockSource: 'record' } });
138+
expect(out.recordLock).toEqual({ locked: true, lockSource: 'record' });
139+
expect(openApprovalOf(out)).toBeNull();
140+
});
141+
});

0 commit comments

Comments
 (0)