Skip to content

Commit 6458913

Browse files
committed
fix(list): a toggle, paste or clear asked while the row's lock is read waits for it too; ledger the new route in the write-route ledgers; regenerate zh-Hant (#35795)
Claude-Session: https://claude.ai/code/session_01L6bhgXSK9qt8je9QbZvhKb Co-authored-by: Claude <noreply@anthropic.com>
1 parent 880816c commit 6458913

6 files changed

Lines changed: 96 additions & 21 deletions

File tree

‎packages/rest/src/rest-write-response-internal-fields.tripwire.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ const DISPOSITIONS: Record<string, Disposition> = {
403403
'POST /api/v1/approvals/requests/:id/remind': { kind: 'no-record-echo', why: 'Reminder receipt.' },
404404
'POST /api/v1/approvals/requests/:id/request-info': { kind: 'no-record-echo', why: 'Approval request state.' },
405405
'POST /api/v1/approvals/requests/:id/comment': { kind: 'no-record-echo', why: 'Approval comment row.' },
406+
'POST /api/v1/approvals/records/:object/locks': { kind: 'no-record-echo', why: 'A READ over POST: `{ recordId, locked }` per id, no field of the row.' },
406407

407408
'POST /api/v1/analytics/dataset/query': { kind: 'no-record-echo', why: 'A READ (aggregated dataset) over POST.' },
408409
'POST /api/v1/analytics/dataset/query/batch': { kind: 'no-record-echo', why: 'A READ (aggregated datasets, one answer entry per query) over POST.' },

‎packages/rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ const ANSWERS_THE_SENTENCE: Record<string, Driver> = {
427427
answer: (res) => res.body?.data?.results?.[0]?.error?.message,
428428
},
429429
'POST /api/v1/security/explain': { called: 'security.explain', body: { object: OBJECT, operation: 'read' } },
430+
// A read over POST, like explain: the caller's read of the ids is the one awaited.
431+
'POST /api/v1/approvals/records/:object/locks': { called: 'approvals.getRecordLocks', body: { recordIds: ['r1'] } },
430432
// [#30205] The hand-over answers per row, inside its `200`: a refused row's
431433
// entry in `failures` carries the `/data` door's sentence for that throw.
432434
'POST /api/v1/security/users/:id/assigned-work/transfer': {

‎ui/packages/components/src/context/gridCellSelection.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ export interface GridCellFacts {
3939
* record's lock, the reader's verdict on the record). An attempt to edit it
4040
* meanwhile opens no editor: the cell shows `text`, and once `settled`
4141
* settles (resolved or rejected) the same attempt, with the same typed key,
42-
* is asked again — unless the reader selected another cell or opened an
43-
* editor in the meantime. A toggle, a paste or a clear asked meanwhile shows
44-
* `text` and writes nothing. Absent ⇒ nothing is being read.
42+
* is asked again — unless the reader selected another cell, asked something
43+
* newer of it or opened an editor in the meantime. A toggle, a paste or a
44+
* clear asked meanwhile waits the same way: nothing is written before the
45+
* read settles. Absent ⇒ nothing is being read.
4546
*/
4647
checking?: { text: string; settled: Promise<unknown> } | null;
4748
/**

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3720,11 +3720,32 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
37203720
// Why the cell an edit was asked of opens no editor, drawn on that cell.
37213721
const [cellNotice, setCellNotice] = useState<{ rowIndex: number; colIndex: number; text: string } | null>(null);
37223722

3723-
// objectstack#35795 — an edit asked while the host still reads what decides
3724-
// it (`GridCellFacts.checking`), asked again when that read settles. One at
3725-
// a time: a newer ask, another selected cell or an open editor drops it.
3726-
const waitingEditRef = useRef<{ rowKey: PendingRowKey; columnKey: string; seed?: { value: unknown } } | null>(null);
3727-
const retryWaitingEditRef = useRef<(waiting: { rowKey: PendingRowKey; columnKey: string; seed?: { value: unknown } }) => void>(() => {});
3723+
// objectstack#35795 — an edit or a write asked while the host still reads
3724+
// what decides it (`GridCellFacts.checking`), asked again when that read
3725+
// settles. One at a time: a newer ask, another selected cell or an open
3726+
// editor drops it.
3727+
type WaitingAct = { rowKey: PendingRowKey; columnKey: string; run: (rowIndex: number, colIndex: number) => void };
3728+
const waitingEditRef = useRef<WaitingAct | null>(null);
3729+
const retryWaitingEditRef = useRef<(waiting: WaitingAct) => void>(() => {});
3730+
/** Say on the cell that it is being checked, and ask `run` again once `settled` settles. */
3731+
const waitForChecking = (
3732+
rowIndex: number,
3733+
colIndex: number,
3734+
row: any,
3735+
col: TableColumn,
3736+
checking: { text: string; settled: Promise<unknown> },
3737+
run: WaitingAct['run'],
3738+
) => {
3739+
setCellNotice({ rowIndex, colIndex, text: checking.text });
3740+
const waiting: WaitingAct = { rowKey: pendingRowKeyOf(row), columnKey: col.accessorKey, run };
3741+
waitingEditRef.current = waiting;
3742+
const retry = () => {
3743+
if (waitingEditRef.current !== waiting) return;
3744+
waitingEditRef.current = null;
3745+
retryWaitingEditRef.current(waiting);
3746+
};
3747+
checking.settled.then(retry, retry);
3748+
};
37283749

37293750
const selectCell = (rowIndex: number, colIndex: number) => {
37303751
const row = paginatedData[rowIndex];
@@ -3819,15 +3840,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38193840
// Asked again when what decides it has been read; it says so meanwhile.
38203841
const checking = factsOf(row, col)?.checking;
38213842
if (checking) {
3822-
setCellNotice({ rowIndex, colIndex, text: checking.text });
3823-
const waiting = { rowKey: pendingRowKeyOf(row), columnKey: col.accessorKey, ...(seed ? { seed } : {}) };
3824-
waitingEditRef.current = waiting;
3825-
const retry = () => {
3826-
if (waitingEditRef.current !== waiting) return;
3827-
waitingEditRef.current = null;
3828-
retryWaitingEditRef.current(waiting);
3829-
};
3830-
checking.settled.then(retry, retry);
3843+
waitForChecking(rowIndex, colIndex, row, col, checking, (r, c) => attemptEdit(r, c, seed));
38313844
return;
38323845
}
38333846
waitingEditRef.current = null;
@@ -3853,7 +3866,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38533866
const rowIndex = paginatedData.findIndex((r) => pendingRowKeyOf(r) === waiting.rowKey);
38543867
const colIndex = columns.findIndex((c) => c.accessorKey === waiting.columnKey);
38553868
if (rowIndex < 0 || colIndex < 0) return;
3856-
attemptEdit(rowIndex, colIndex, waiting.seed);
3869+
waiting.run(rowIndex, colIndex);
38573870
};
38583871

38593872
/** Write a value into a cell without an editor: the commit `saveEdit` makes. */
@@ -3885,12 +3898,14 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38853898
}
38863899
const value = valueOf(row, col);
38873900
if (value === undefined) return;
3888-
// Nothing is written while what decides the write is still being read.
3901+
// Written once what decides the write has been read, the value worked out
3902+
// again then; it says so meanwhile.
38893903
const checking = factsOf(row, col)?.checking;
38903904
if (checking) {
3891-
setCellNotice({ rowIndex, colIndex, text: checking.text });
3905+
waitForChecking(rowIndex, colIndex, row, col, checking, (r, c) => writeCell(r, c, valueOf));
38923906
return;
38933907
}
3908+
waitingEditRef.current = null;
38943909
commitCellValue(row, col.accessorKey, value);
38953910
};
38963911

‎ui/packages/i18n/src/locales/zh-Hant.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ const zhHant = {
562562
objectReadOnly: '這些記錄不能在這裡編輯。',
563563
noPermission: '您沒有編輯這些記錄的權限。',
564564
approvalLocked: '此記錄正在審批中,已鎖定。',
565-
checking: '正在確認這筆記錄能否編輯…',
565+
checking: '正在確認這條記錄能否編輯…',
566566
noRecordPermission: '您沒有編輯此記錄的權限。',
567567
},
568568
stateChange: {

‎ui/packages/plugin-grid/src/__tests__/ObjectGrid.autosave-35685.test.tsx‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,62 @@ describe('ObjectGrid autosave — one update, this row only (objectstack#35685)'
181181
});
182182
});
183183

184+
describe("ObjectGrid autosave — a write asked while the row's lock is read waits for it (objectstack#35795)", () => {
185+
/** The approvals service answers the page's locks after `delay` ms; explain answers at once. */
186+
function stubSlowLocks(locked: ReadonlySet<string>, delay: number) {
187+
vi.stubGlobal('fetch', vi.fn(async (url: unknown, init?: { body?: unknown }) => {
188+
const body = init?.body ? JSON.parse(String(init.body)) : {};
189+
const ids: string[] = Array.isArray(body.recordIds) ? body.recordIds : [];
190+
if (String(url).endsWith(`/api/v1/approvals/records/${OBJECT}/locks`)) {
191+
const answer = {
192+
ok: true, status: 200,
193+
json: async () => ({ success: true, data: { records: ids.map((id) => ({ recordId: id, locked: locked.has(id) })) } }),
194+
};
195+
return new Promise((resolve) => setTimeout(() => resolve(answer), delay));
196+
}
197+
return { ok: true, status: 200, json: async () => ({ allowed: true, records: ids.map((id) => ({ recordId: id, visible: true })) }) };
198+
}));
199+
}
200+
function paste(container: HTMLElement, cell: HTMLElement, text: string) {
201+
fireEvent.click(cell);
202+
const catcher = container.querySelector<HTMLInputElement>('[data-slot="cell-type-catcher"]')!;
203+
fireEvent.paste(catcher, { clipboardData: { getData: () => text } });
204+
}
205+
afterEach(() => {
206+
vi.useRealTimers();
207+
});
208+
209+
it('a paste is not written while the lock is read, and is written once it answers unlocked', async () => {
210+
stubSlowLocks(new Set(), 2000);
211+
const ds = makeDataSource();
212+
const { container } = renderGrid(ds, true);
213+
await screen.findByText('beta');
214+
vi.useFakeTimers();
215+
paste(container, dataCell(container, 0, 'alpha'), 'zeta');
216+
expect(screen.getByTestId('cell-readonly-reason')).toHaveTextContent('Checking whether this record can be edited…');
217+
await act(async () => { await vi.advanceTimersByTimeAsync(1999); });
218+
expect(ds.update).not.toHaveBeenCalled();
219+
await act(async () => { await vi.advanceTimersByTimeAsync(1); });
220+
vi.useRealTimers();
221+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
222+
expect(ds.update.mock.calls[0][2]).toEqual({ name: 'zeta' });
223+
});
224+
225+
it('a paste on a row the answer says is locked is never written, and the cell says why', async () => {
226+
stubSlowLocks(new Set(['d1']), 2000);
227+
const ds = makeDataSource();
228+
const { container } = renderGrid(ds, true);
229+
await screen.findByText('beta');
230+
vi.useFakeTimers();
231+
paste(container, dataCell(container, 0, 'alpha'), 'zeta');
232+
await act(async () => { await vi.advanceTimersByTimeAsync(2000); });
233+
expect(screen.getByTestId('cell-readonly-reason')).toHaveTextContent("This record is locked while it's in approval.");
234+
vi.useRealTimers();
235+
await act(async () => { await new Promise((r) => setTimeout(r, 20)); });
236+
expect(ds.update).not.toHaveBeenCalled();
237+
});
238+
});
239+
184240
describe('ObjectGrid autosave — a 409 kept as mine re-reads nothing either (objectstack#35685)', () => {
185241
/** The first write meets a newer version; the "Overwrite anyway" write lands and is announced. */
186242
function conflictOnce(ds: any) {

0 commit comments

Comments
 (0)