Skip to content

Commit 0d0ed81

Browse files
fix(plugin-detail): the record drawer's per-field save asks for the fields a change makes required (#36298)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XTRdLmK9YYgMSCJ7NH2PuUY)_ Fixes #35995 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在看板、日历、甘特图自带的记录抽屉里改一个字段,若这次改动让另一个空字段变成必填,现在会先弹出填写小窗,填好后一次保存;以前直接被服务器拒绝。 - 属于「记录页行内编辑」这一组体验修复:让抽屉和记录页、列表单元格、看板拖拽用同一个填写小窗。 - 出错时影响仅限这个抽屉的保存:小窗点取消什么都不写,可直接撤回本次改动;不触发必填的改动照旧立即保存。 - 无 ## What changes `InlineEditSaveBar`'s callback mode (the record overlay, `RecordDetailPanel` / `RecordDetailDrawer`) now runs the same `collectRequiredWhenPromptFields` check with the same `fillable` test as the atomic mode before its first `onFieldSave`. When fields come back it writes nothing and opens the shared `RequiredFieldsDialog`; Save sends the changed field plus the typed values in ONE `dataSource` update with `If-Match` at the version the edit session began on; Cancel closes the dialog and keeps the draft; a 409 opens the same conflict dialog the atomic mode opens, over the fill-in dialog (Cancel comes back to the typed values, Overwrite resends both at the server's version). A change that makes nothing required still goes through `onFieldSave` at once. - `ui/packages/plugin-detail/src/InlineEditSaveBar.tsx` — the ask runs in both modes when the DataSource props are present; the callback mode's ask carries the edit session's starting version (`RequiredAsk.ifMatch`); the plain callback save's 409 still reads as a refusal (the conflict dialog's overwrite writes through the DataSource, which is not the path that refused). The edit-base block moved above `handleSave` unchanged so the save can read it. - `ui/packages/plugin-detail/src/RecordDetailPanel.tsx` — hands the bar `dataSource`, `objectName`, `recordId` and `data` (all existing props) and wraps the bar alone in a `RecordContextProvider` carrying the panel's `objectSchema`, so the bar knows the object's fields. No new prop, no new callback shape. - One `@object-ui/plugin-detail` patch changeset. Measured caller set (Zone 2.1): the callback mode has exactly one caller, `RecordDetailPanel` (`RecordDetailDrawer` renders it). It is the overlay of `ObjectKanban`, `ObjectCalendar`, `ObjectGantt` and `ObjectTree` (the tree passes no `onFieldSave`, so it is read-only) when the host routes no row click. Inside the console a list row click opens `RecordDetailView` in the drawer stack (`objectViewRecordOverlay.tsx`), whose bar is the atomic mode and already asks since the shared prompt landed; that file is untouched here. ## Tests - The pin in `InlineEditSaveBar.requiredPrompt-35956.test.tsx` that said the callback mode never asks now says it asks and writes nothing yet. - A new top-level `describe` in the same file (the component's shared harness, per the ruling that a new pin goes into that file): Save writes once with both fields and `ifMatch` and never calls `onFieldSave`; the guard is the version the edit began on even after the host re-reads the record mid-edit; Cancel writes nothing and keeps the edit; CONTROL — a change that makes nothing required goes through `onFieldSave` at once; a 409 keeps the fill-in dialog open under the conflict dialog and Overwrite resends both at the server's version; CONTROL — with no data source handed over it never asks; and one test through the real `RecordDetailPanel` + `DetailView` (double-click, edit, Save → dialog → one guarded update). <details><summary>Readings</summary> Recorded at the commit named in the report; see the `os-dev-report` comment on the card for the full gate list. - `vitest run InlineEditSaveBar.requiredPrompt-35956.test.tsx` — Test Files 1 passed, Tests 15 passed. - 25 plugin-detail test files naming `InlineEditSaveBar` / `RecordDetailPanel` / `RecordDetailDrawer` — Test Files 25 passed, Tests 163 passed, 10 skipped. - Ablation (via `scripts/ablation-replace.mjs`, restored to the HEAD blob with `git diff HEAD` empty): restoring the old `!onFieldSave &&` guard turns 6 tests red (the flipped pin, Save, the version guard, Cancel, the 409 and the panel test) while both CONTROLs stay green. </details> ## Acceptance notes - The dialog's single write goes through the data source, not through the host's `onFieldSave`. The kanban and the calendar re-read on the data source's mutation event, as they do for any write; a host that only patches its own list inside `onFieldSave` does not see that patch for this one write. The panel's `record` is the host's snapshot (`navigation.selectedRecord`) either way, as it already is after a per-field save. - Without a data source on the overlay there is no one write to put the values in, so it saves field by field as before (pinned as a CONTROL). - Handing the bar `data` also turns on two existing behaviours in the overlay: the changed-elsewhere notice, and a server refusal naming a record field reading as a field hint (labelled with the machine name, since the panel passes no `fieldLabelFor`). - 375 px / dark: the dialog is the shared one, unchanged here; no browser check was run for this PR. ## Verification Files to read first, by risk: `InlineEditSaveBar.tsx` (`handleSave`'s ask and the 409 gate), `RecordDetailPanel.tsx` (the record context around the bar), the new `describe` at the end of the test file. Two-minute check: `cd ui && pnpm exec vitest run packages/plugin-detail/src/__tests__/InlineEditSaveBar.requiredPrompt-35956.test.tsx` — expect 15 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5oLLK7uoxp33riiBJL --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2ab7601 commit 0d0ed81

4 files changed

Lines changed: 252 additions & 53 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): the record drawer's per-field save asks for the fields a change makes required
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
In the record overlay (`RecordDetailPanel`, and `RecordDetailDrawer` around it), a change that made another field required (`requiredWhen`) while that field was empty went straight to the host's `onFieldSave` and came back refused by the server. The overlay now asks first, in the same fill-in dialog the record page, the list cell and the kanban open: Save writes the change and the typed values in one update guarded with `If-Match` at the version the edit began on, Cancel writes nothing and keeps the edit. A change that makes nothing required still saves at once through `onFieldSave`.
11+
12+
The ask needs one write to put the values in, so `InlineEditSaveBar` asks in its callback mode only when it is also given `dataSource`, `objectName`, `recordId` and `data`; `RecordDetailPanel` now passes them, with a record context naming the object's fields. That one write goes through the data source, not through `onFieldSave`; a host that patches its own list in `onFieldSave` sees it through the data source's mutation event. Without a data source the overlay saves field by field as before.

‎ui/packages/plugin-detail/src/InlineEditSaveBar.tsx‎

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* - **Callback mode** (standalone drawer): loops a caller-supplied
2020
* `onFieldSave(field, value)` over the draft, preserving the drawer's
2121
* existing per-field persistence contract with plugin-gantt/calendar/kanban.
22+
* The one exception is a draft that makes other fields required
23+
* (objectstack#35995): see `handleSave`.
2224
*
2325
* While the session is active the bar also owns the record-level keyboard
2426
* shortcuts (objectui#2572): **Esc** cancels (when no popover/dialog is open)
@@ -112,7 +114,10 @@ export interface InlineEditSaveBarProps {
112114
/**
113115
* Callback-persistence mode (drawer): when provided, the save loops this
114116
* per-field callback over the draft instead of issuing a DataSource update.
115-
* Takes precedence over the DataSource path.
117+
* Takes precedence over the DataSource path — except for a draft that makes
118+
* other fields required (objectstack#35995): when the DataSource props are
119+
* given too, that draft asks for the fields and writes the draft and the
120+
* typed values in ONE guarded DataSource update, as the record page does.
116121
*/
117122
onFieldSave?: (field: string, value: any) => void | Promise<void>;
118123
/** When true, disables Save and shows a lock hint (e.g. approval-locked). */
@@ -141,6 +146,18 @@ export interface InlineEditSaveBarProps {
141146
* `currentRecord` / `currentVersion` is a red build here rather than a fresh
142147
* `any`.
143148
*/
149+
/**
150+
* A draft waiting on the fill-in dialog (objectstack#35956). `ifMatch` is
151+
* present only for the callback mode (objectstack#35995): the version its edit
152+
* session began on, which guards the combined write. The atomic mode reads the
153+
* record's version when Save is pressed, as its plain Save does.
154+
*/
155+
interface RequiredAsk {
156+
draft: Record<string, unknown>;
157+
fields: RequiredWhenPromptField[];
158+
ifMatch?: string | undefined;
159+
}
160+
144161
type NarrowedBy<F> = F extends (arg: unknown) => arg is infer N ? N : never;
145162
type ConcurrentUpdateErrorShape = NarrowedBy<typeof isConcurrentUpdateError>;
146163

@@ -317,19 +334,18 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
317334

318335
// objectstack#35956 — a draft that makes other fields required asks for
319336
// them before the write, in the dialog the list cell and the kanban drop
320-
// open, and Save writes the draft and those values in ONE update. Only on
321-
// the atomic path: the drawer's per-field callback has no one write to put
322-
// them in. The fields come from the page's record context, which describes
323-
// this record only when it names the same object.
337+
// open, and Save writes the draft and those values in ONE update. That
338+
// update is the DataSource one, so the ask needs the DataSource props in
339+
// both modes: the drawer's per-field callback has no one write to put them
340+
// in, and objectstack#35995 has the drawer hand those props over too. The
341+
// fields come from the record context, which describes this record only
342+
// when it names the same object.
324343
const recordCtx = useRecordContext();
325344
const perms = usePermissions();
326345
const { fieldLabel, translateOptions, fieldOptionLabel } = useSafeFieldLabel();
327346
const objectSchema = recordCtx?.objectName === objectName ? recordCtx?.objectSchema : undefined;
328347
const objectFields = (objectSchema as { fields?: Record<string, unknown> } | undefined)?.fields;
329-
const [requiredAsk, setRequiredAsk] = React.useState<{
330-
draft: Record<string, unknown>;
331-
fields: RequiredWhenPromptField[];
332-
} | null>(null);
348+
const [requiredAsk, setRequiredAsk] = React.useState<RequiredAsk | null>(null);
333349
// The write a conflict raised from that dialog was making (the draft AND the
334350
// typed values), so the conflict dialog's overwrite sends all of it rather
335351
// than the draft alone, which the server would refuse again. `null` for a
@@ -471,6 +487,21 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
471487
[fieldLabelFor, t],
472488
);
473489

490+
// objectstack#35685 — the record's version when this edit session began. A
491+
// record read again meanwhile at another version was changed elsewhere (a
492+
// list cell beside the drawer, another tab): the draft stays as typed and
493+
// Save writes it over the record as it is now, so the bar says so.
494+
const editing = !!inline?.editing;
495+
const dataVersion = typeof data?.updated_at === 'string' ? (data.updated_at as string) : undefined;
496+
const [editBase, setEditBase] = React.useState<{ version: string | undefined } | null>(null);
497+
React.useEffect(() => {
498+
if (!editing) {
499+
setEditBase(null);
500+
return;
501+
}
502+
setEditBase((prev) => prev ?? { version: dataVersion });
503+
}, [editing, dataVersion]);
504+
474505
const handleSave = React.useCallback(async () => {
475506
if (!inline) return;
476507
const draft = inline.draft;
@@ -480,12 +511,16 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
480511
inline.reset();
481512
return;
482513
}
483-
if (!onFieldSave && canAtomic && data && typeof data === 'object') {
514+
// Asked in both modes before anything is written (objectstack#35995):
515+
// the callback mode's first `onFieldSave` would otherwise land the change
516+
// alone, and the server refuses it for the empty field. The callback mode
517+
// guards the combined write with the version the edit session began on.
518+
if (canAtomic && data && typeof data === 'object') {
484519
const fields = collectRequiredWhenPromptFields(objectFields, data, draft, { fillable });
485520
if (fields.length > 0) {
486521
inline.setError(null);
487522
inline.setFieldErrors(null);
488-
setRequiredAsk({ draft, fields });
523+
setRequiredAsk(onFieldSave ? { draft, fields, ifMatch: editBase?.version ?? dataVersion } : { draft, fields });
489524
return;
490525
}
491526
}
@@ -516,7 +551,10 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
516551
}
517552
inline.reset();
518553
} catch (err) {
519-
if (isConcurrentUpdateError(err) && canAtomic) {
554+
// The callback mode's writes are the host's, so its conflict is
555+
// presented like any other refusal: the dialog's overwrite writes
556+
// through the DataSource, which is not the path that refused.
557+
if (isConcurrentUpdateError(err) && canAtomic && !onFieldSave) {
520558
// Stay in edit mode; the dialog drives reload / overwrite.
521559
setConflict(buildConflict(draft, err));
522560
} else {
@@ -527,7 +565,7 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
527565
} finally {
528566
inline.setSaving(false);
529567
}
530-
}, [inline, onFieldSave, canAtomic, data, dataSource, objectName, recordId, refresh, buildConflict, presentRefusal, objectFields, fillable]);
568+
}, [inline, onFieldSave, canAtomic, data, dataSource, objectName, recordId, refresh, buildConflict, presentRefusal, objectFields, fillable, editBase, dataVersion]);
531569

532570
const closeConflict = React.useCallback(() => {
533571
conflictWriteRef.current = null;
@@ -580,7 +618,6 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
580618
// layer", so the session only cancels when nothing is stacked on top.
581619
// Both respect the in-flight `saving` state; save also respects `locked`
582620
// and stands down while the conflict dialog drives the session.
583-
const editing = !!inline?.editing;
584621
const saving = !!inline?.saving;
585622
const cancel = inline?.cancel;
586623
const conflictOpen = !!conflict;
@@ -612,24 +649,11 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
612649
return () => window.removeEventListener('keydown', onKeyDown);
613650
}, [editing, saving, locked, conflictOpen, handleSave, cancel]);
614651

615-
// objectstack#35685 — the record's version when this edit session began. A
616-
// record read again meanwhile at another version was changed elsewhere (a
617-
// list cell beside the drawer, another tab): the draft stays as typed and
618-
// Save writes it over the record as it is now, so the bar says so.
619-
const dataVersion = typeof data?.updated_at === 'string' ? (data.updated_at as string) : undefined;
620-
const [editBase, setEditBase] = React.useState<{ version: string | undefined } | null>(null);
621-
React.useEffect(() => {
622-
if (!editing) {
623-
setEditBase(null);
624-
return;
625-
}
626-
setEditBase((prev) => prev ?? { version: dataVersion });
627-
}, [editing, dataVersion]);
628652
const changedWhileEditing =
629653
!saving && editBase !== null && editBase.version !== undefined && dataVersion !== undefined && dataVersion !== editBase.version;
630654

631655
/** The fill-in dialog for a draft that needs fields filled (objectstack#35956). */
632-
const renderRequiredAsk = (ask: { draft: Record<string, unknown>; fields: RequiredWhenPromptField[] }) => {
656+
const renderRequiredAsk = (ask: RequiredAsk) => {
633657
const objectKey = objectName ?? '';
634658
const labelOf = (name: string): string => {
635659
const declared = (objectFields?.[name] as { label?: unknown } | undefined)?.label;
@@ -678,7 +702,9 @@ export const InlineEditSaveBar: React.FC<InlineEditSaveBarProps> = ({
678702
// draft is still the reader's to change or cancel.
679703
onCancel={() => setRequiredAsk(null)}
680704
onSubmit={async (values) => {
681-
const ifMatch = typeof data?.updated_at === 'string' ? (data.updated_at as string) : undefined;
705+
const ifMatch = 'ifMatch' in ask
706+
? ask.ifMatch
707+
: typeof data?.updated_at === 'string' ? (data.updated_at as string) : undefined;
682708
inline?.setSaving(true);
683709
const write = { ...ask.draft, ...values };
684710
try {

‎ui/packages/plugin-detail/src/RecordDetailPanel.tsx‎

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import React from 'react';
5353
import { isExpandableFieldType, resolveAffordance, type SchemaLike } from '@object-ui/core';
5454
import type { DataSource } from '@object-ui/types';
5555
import { SYSTEM_MANAGED_FIELD_NAMES } from '@object-ui/types';
56-
import { InlineEditProvider } from '@object-ui/react';
56+
import { InlineEditProvider, RecordContextProvider } from '@object-ui/react';
5757
import { usePermissions } from '@object-ui/permissions';
5858
import { DetailView } from './DetailView';
5959
import { InlineEditSaveBar } from './InlineEditSaveBar';
@@ -347,19 +347,37 @@ export function RecordDetailPanel({
347347
/>
348348
{/* Record-level Save/Cancel bar. Callback mode: loops the caller's
349349
per-field onFieldSave over the draft, preserving the overlay's
350-
existing persistence contract (plugin-gantt/kanban/calendar). */}
351-
<InlineEditSaveBar
352-
onFieldSave={fieldSave ? async (field, value) => {
353-
try {
354-
await fieldSave(field, value);
355-
} catch (err) {
356-
console.error('[RecordDetailPanel] inline field save failed:', err);
357-
// Rethrow so the save bar surfaces the failure inline and keeps
358-
// the draft — swallowing made a rejected save look successful.
359-
throw err;
360-
}
361-
} : undefined}
362-
/>
350+
existing persistence contract (plugin-gantt/kanban/calendar).
351+
objectstack#35995 — the record, its object and the data source go
352+
along too, so a draft that makes other fields required asks for
353+
them first and writes everything in one guarded update, as the
354+
record page does. The record context names this record for the
355+
bar alone (the object's fields), not for the panel's body. */}
356+
<RecordContextProvider
357+
objectName={objectName}
358+
recordId={recordId}
359+
data={record}
360+
objectSchema={objectSchema}
361+
dataSource={dataSource}
362+
embedded
363+
>
364+
<InlineEditSaveBar
365+
dataSource={dataSource}
366+
objectName={objectName}
367+
recordId={recordId}
368+
data={record}
369+
onFieldSave={fieldSave ? async (field, value) => {
370+
try {
371+
await fieldSave(field, value);
372+
} catch (err) {
373+
console.error('[RecordDetailPanel] inline field save failed:', err);
374+
// Rethrow so the save bar surfaces the failure inline and keeps
375+
// the draft — swallowing made a rejected save look successful.
376+
throw err;
377+
}
378+
} : undefined}
379+
/>
380+
</RecordContextProvider>
363381
</InlineEditProvider>
364382
);
365383
}

0 commit comments

Comments
 (0)