Skip to content

Commit 119c82c

Browse files
fix(plugin-form): pin the master-detail Save bar and guard the subform close (#34657)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBU5y97XtBcJ8qSLSR3B3Djd)_ Fixes #34599 Clause-②: no Metadata-protocol: none repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs ## 维护者速读 - **改了什么**:带内嵌子表的表单(报价单、项目预算这类)在弹窗、抽屉、整页里,取消 / 保存按钮现在固定在底部,滚到哪里都看得见;弹窗里填了内容再点关闭(X、Esc、点遮罩)会先弹「放弃更改?」确认,刷新页面也会提示。 - **为什么改**:以前按钮画在所有字段和行项目之后,长单据要滚到最底才能保存;子表分支关闭时也不拦截,填好的内容和行项目一按 Esc 就没了。 - **风险与回滚**:只改界面层(`@object-ui/plugin-form`),保存逻辑(`/api/v1/batch`)、按钮 test id、包的导出都没动;有问题直接回退本 PR 即可。 - **先看**:`MasterDetailForm.tsx`(操作栏的 sticky 类与未保存判定)、`ModalForm.tsx`(子表分支的关闭路径改走确认框)、`formDirtyReport.ts`(包内的未保存信号通道)。 - **两分钟验证**:在 showcase 新建一张带行项目的记录(弹窗),把弹窗滚到顶部,应能直接看到底部的取消 / 保存;在抬头输入一个字后按 Esc,应弹出「放弃更改?」。 - **需要你做的**:无,席位落地。 ## What changes - **The master-detail Save bar is pinned.** `MasterDetailForm`'s action bar (`md-form-cancel` / `md-form-submit`, test ids unchanged) is now `position: sticky; bottom: 0` with an opaque background, a direct child of the form's root. Sticky resolves against the nearest scrolling ancestor, so the same bar pins to the dialog body scroller (`ModalForm`), the drawer content (`DrawerForm`) and the record page's scroller (`ObjectForm` page host, `RecordFormPage`). Measured in Chromium: sticky stops at the scroller's CONTENT edge, so a padded scroller would show lines scrolling through the padding strip under the bar; an `after:` strip (24px, the widest host padding) paints over it. ADR-0035 Decision §6 stays true: the form owns its Save, and no host draws a second footer. - **The subform close is guarded.** A package-internal context, `FormDirtyReportContext` (`formDirtyReport.ts`, not re-exported from the index), carries an unsaved-input verdict up to the nearest provider: - `ModalForm` and `DrawerForm` provide their close guard's setter around the master-detail form they host; - `MasterDetailForm` reports header OR lines OR row editor, and provides its own reporters around the header form and the row editor; - the record-form layouts the header renders through (`ObjectForm`'s default arm, `TabbedForm`) report the renderer's existing `onDirtyChange` verdict to it, beside their bus gate. - Lines count as unsaved by the edit save's own row diff (`linesUnsaved`, already the bus-hold rule): a blank ghost line is not input, a reverted edit reads as saved. A save clears the verdict (create remounts the header; an edit resets the header verdict and advances the lines' baseline). - `ModalForm`'s subform arm now routes its Dialog close (X, Escape, backdrop) through the same `attemptClose` path and discard AlertDialog as the flat arm, and its beforeunload guard hears the same verdict. `DrawerForm` already routed its Sheet close through the guard; it now hears the master-detail input. The explicit Cancel still closes at once, as in the flat arm. - **No conflict dialog on the subform arm, by design.** The master-detail save goes through the header form's `submitHandler` (one batch), which never reaches `useOccSave`; there is no OCC token to conflict on, so none was invented. - Exported surface: `MasterDetailFormProps`, `MasterDetailFormSchema` and `src/index.tsx` are byte-identical (`git diff` of index.tsx is empty, no `export`/`interface` line moved), which is what keeps `Clause-②: no`. ## Tests - `subformHosts.test.tsx`, new top-level describe "master-detail Save bar is pinned to the host scroll frame": in modal, drawer and page hosts the bar is sticky + bottom-0 + opaque, and the first ancestor that sets an overflow is the host's own scroller (modal: the `flex-1 overflow-y-auto` body; drawer: the Sheet content; page: none inside the component). One Save in the dialog, no `modal-form-footer` / `drawer-form-footer`. - `discardGuard.test.tsx`, new top-level describe "master-detail overlay unsaved-changes guard": pristine dialog closes on the X; typed header input prompts and "Discard" closes; an edited line alone prompts; Cancel closes a dirty dialog at once; dirty dialog blocks unload; drawer prompts on typed header input; the reporter goes true then false across a create save and across an edit save (header stays mounted). - New pins went into the two existing harness files as top-level describes (AGENTS.md, ruling record 6583487846), not new files. <details><summary>Readings (head c367f82 unless noted)</summary> - `pnpm --filter @object-ui/plugin-form exec vitest run --root ../.. --maxWorkers=2 packages/plugin-form/` under the verify lock: `Test Files 233 passed (233)`, `Tests 2604 passed | 1 skipped (2605)`, VERDICT command-exit 0. - Re-run on the merged head 205f1d2 (origin/main 518baca merged in): the same suite, `Test Files 233 passed (233)`, `Tests 2604 passed | 1 skipped (2605)`, VERDICT command-exit 0; type-check and the changeset / nul-byte / type-check-coverage gates exit 0. - `pnpm --filter @object-ui/plugin-form run type-check` (both `tsc --noEmit` and `tsc -p tsconfig.test.json`): VERDICT command-exit 0. - Ablations (each through `scripts/ablation-replace.mjs`, mutation proven on disk, restored to the HEAD blob with `git diff HEAD` empty; tests import `./ModalForm` etc. from source, so no dist leg): - drop `sticky bottom-0` from the bar: 3 failed (the three host pins). - ObjectForm hands the renderer the bus handler only (no report): 4 failed (header prompt in modal and drawer, unload, reporter). - drop `linesDirty` from the verdict: 1 failed (edited line alone). - drop the header reset in `handleSaved`: first run stayed green (a create remounts the header, so the reset is redundant there); the edit-save pin was added, and the re-run failed 1 (that pin). - subform Dialog back to `onOpenChange={schema.onOpenChange}`: 2 failed (header and line prompts). - Chromium probe (scratch HTML, not committed): a sticky bottom-0 child of a 24px-padded scroller rests at 276 of a 300px scroller (the content edge); with the 24px `after:` strip the padding strip renders covered and the scroll height is unchanged (1088 = content + bar + padding). </details> ## Acceptance notes - Overlaps draft #34642 (#34605) in ModalForm.tsx; area order lands this PR first, #34642 merges main after. - Card acceptance 1 (modal) and 2 (drawer, page): pinned structurally and by the Chromium CSS probe; the live Console was not driven in a browser for this PR (NOT MEASURED: live UI). The Live E2E UI job runs the `md-form-submit` specs (acceptance 4) on this PR. - Acceptance 3: covered for the dialog and the drawer. The record page (`RecordFormPage`) has no close guard for the flat form either, so none was added for the master-detail page host. - `md-form-actions` is a new test id on the bar wrapper (for the pins); `md-form-cancel` / `md-form-submit` are unchanged. - The `after:` strip extends 24px below the bar in its resting position; in every host measured the master-detail form is the last child of its scroller, where that strip covers only the scroller's bottom padding. ## Verification - Local gates: the `dispatch-gates.mjs --commands` list for this diff (38 commands) plus `pnpm check:changeset-fixed` (its roster sits under `.changeset/`), every one exit 0; `pnpm --dir ui run check:new-line-citations`: 0 new citations. CI owns the rest (Lint UI, Type Check UI, Test UI, Build & E2E UI, Live E2E UI, Dogfood). --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f8d016c commit 119c82c

9 files changed

Lines changed: 432 additions & 41 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/plugin-form': patch
3+
---
4+
5+
fix(plugin-form): the master-detail Save bar stays in view, and closing a master-detail dialog with unsaved input asks first
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A form with inline sub-tables (`subforms`) drew its Cancel and Save buttons after the last field and the last line, so in a dialog, a drawer or on the record page a long form had to be scrolled to the end before it could be saved.
11+
12+
- **The action bar is pinned.** `MasterDetailForm` keeps its own Cancel and Save (ADR-0035 Decision §6), and the bar now sticks to the bottom edge of whatever scroll frame hosts the form: the dialog body, the drawer, the record page. The test ids `md-form-cancel` and `md-form-submit` are unchanged.
13+
- **Closing asks before it discards.** The master-detail arm of `ModalForm` closed on Escape, a backdrop click or the X with the typed values and edited lines gone. It now goes through the same "Discard changes?" confirmation, and the same page-unload prompt, as a form without sub-tables. Input counts when it is in the header fields, in the lines (a change the save would write; a blank line does not count) or in the open row editor. `DrawerForm` already routed its close through the guard, and now hears the master-detail form's input too. The explicit Cancel button still closes at once, and a successful save clears the guard.
14+
15+
Nothing changes in how the form saves (one atomic `/api/v1/batch`), and no prop or type is added to the package's exports.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
} from './loadFailure';
7979
import { hasInlineFieldSource, noSubmitTargetError } from './submitTarget';
8080
import { useRecordInvalidation } from './recordInvalidation';
81+
import { FormDirtyReportContext } from './formDirtyReport';
8182
import { useInitialFieldFocus } from './initialFieldFocus';
8283

8384
// Localized strings for the unsaved-changes guard and, since objectui#11039,
@@ -953,9 +954,13 @@ const DrawerFormBody: React.FC<DrawerFormProps> = ({
953954
) : null;
954955

955956
// Master-detail in a drawer: render the master-detail form (it owns its Save
956-
// bar) when the schema declares inline child collections; saved atomically.
957+
// bar, pinned to the bottom of this drawer's scroll frame) when the schema
958+
// declares inline child collections; saved atomically. It reports its unsaved
959+
// input into this drawer's close guard (`formDirtyReport.ts`), so the close
960+
// paths prompt as they do for the flat body (objectstack#34599).
957961
const subforms = (schema as any).subforms as any[] | undefined;
958962
const drawerBody = subforms?.length && schema.mode !== 'view' ? (
963+
<FormDirtyReportContext.Provider value={setIsDirty}>
959964
<MasterDetailForm
960965
schema={{
961966
type: 'object-master-detail-form',
@@ -973,6 +978,7 @@ const DrawerFormBody: React.FC<DrawerFormProps> = ({
973978
}}
974979
dataSource={dataSource}
975980
/>
981+
</FormDirtyReportContext.Provider>
976982
) : (
977983
<>
978984
{closedAffordanceNotice}

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

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* `lookup`) FK on the child object.
3131
*/
3232

33-
import React, { startTransition, useCallback, useEffect, useMemo, useRef, useState } from 'react';
33+
import React, { startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
3434
import type { BatchTransactionOperation, DataSource, GridFieldMetadata, I18nLabel } from '@object-ui/types';
3535
import { resolveAffordance, runBatchTransaction } from '@object-ui/core';
3636
import { LineItemsField, lookupAutofillByField, useBooleanValueLabel, type BooleanValueLabel, type GridColumn, type LookupAutofillByField } from '@object-ui/fields';
@@ -48,6 +48,7 @@ import { dataChangeMatches, subscribeDataChanges } from '@object-ui/react';
4848
import { ObjectForm } from './ObjectForm';
4949
import { applyColumnPermissions } from './fieldWriteGate';
5050
import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate';
51+
import { FormDirtyReportContext } from './formDirtyReport';
5152
import { useFormChromeTranslation } from './formChrome';
5253
import {
5354
buildMasterDetailBatch,
@@ -1766,6 +1767,41 @@ export const MasterDetailForm: React.FC<MasterDetailFormProps> = ({
17661767
}));
17671768
}, []);
17681769

1770+
/**
1771+
* Whether this document holds input a close would discard, reported to the
1772+
* hosting overlay's close guard (`formDirtyReport.ts`): the header form's
1773+
* renderer verdict, the open row editor's, or any collection whose lines the
1774+
* save would write ({@link linesUnsaved}, the edit save's own row diff — so a
1775+
* blank ghost line is not input and a reverted edit reads as saved).
1776+
*
1777+
* The header and the row editor report through reporters this form provides
1778+
* around them, never to the host directly. A save clears the header's
1779+
* verdict (a create remounts it; an edit's next keystroke reports again) and
1780+
* advances or empties the lines, so a saved document reads as pristine.
1781+
*/
1782+
const reportUnsaved = useContext(FormDirtyReportContext);
1783+
const [headerDirty, setHeaderDirty] = useState(false);
1784+
const [rowEditorDirty, setRowEditorDirty] = useState(false);
1785+
const linesDirty = useMemo(
1786+
() =>
1787+
entries.some((e) =>
1788+
linesUnsaved(rowState[e.id], e.config, parentIdKey, childSchemasRef.current[e.config.childObject]),
1789+
),
1790+
[entries, rowState, parentIdKey],
1791+
);
1792+
// A closed row editor holds no draft: Apply wrote it into the lines, and
1793+
// cancel dropped it. Its renderer reports nothing on its way out.
1794+
useEffect(() => {
1795+
if (!expanded) setRowEditorDirty(false);
1796+
}, [expanded]);
1797+
const unsavedInput = headerDirty || rowEditorDirty || linesDirty;
1798+
useEffect(() => {
1799+
reportUnsaved?.(unsavedInput);
1800+
}, [reportUnsaved, unsavedInput]);
1801+
// Unmounted (the overlay closed, or the host swapped forms): nothing of this
1802+
// document is on screen to discard any more.
1803+
useEffect(() => () => reportUnsaved?.(false), [reportUnsaved]);
1804+
17691805
// Header tax-rate field name — the live value is read by <MasterDetailLines>
17701806
// (from the header record and the user's edits) and drives the Subtotal / Tax
17711807
// / Total stack.
@@ -1826,6 +1862,7 @@ export const MasterDetailForm: React.FC<MasterDetailFormProps> = ({
18261862
const handleSaved = useCallback(
18271863
async (parent: any) => {
18281864
releaseSave();
1865+
setHeaderDirty(false);
18291866
if (!schema.onSuccess) {
18301867
toast.success(
18311868
isEdit
@@ -2147,7 +2184,9 @@ export const MasterDetailForm: React.FC<MasterDetailFormProps> = ({
21472184
<div className={cn('space-y-6', className, schema.className)}>
21482185
{/* 1) Header fields on top */}
21492186
<div ref={formHostRef}>
2150-
<ObjectForm key={formKey} schema={parentSchema as any} dataSource={headerDataSource} />
2187+
<FormDirtyReportContext.Provider value={setHeaderDirty}>
2188+
<ObjectForm key={formKey} schema={parentSchema as any} dataSource={headerDataSource} />
2189+
</FormDirtyReportContext.Provider>
21512190
</div>
21522191

21532192
{/* 2) Line items + document totals, in a sibling component that owns the
@@ -2204,6 +2243,7 @@ export const MasterDetailForm: React.FC<MasterDetailFormProps> = ({
22042243
row its id. A disabled fieldset disables every control in the
22052244
editor, "Apply" included, until the save has settled. */}
22062245
<fieldset disabled={saving} className="min-w-0">
2246+
<FormDirtyReportContext.Provider value={setRowEditorDirty}>
22072247
<ObjectForm
22082248
key={`row-${expanded.entryId}-${expanded.rowIdx}`}
22092249
schema={{
@@ -2225,15 +2265,28 @@ export const MasterDetailForm: React.FC<MasterDetailFormProps> = ({
22252265
} as any}
22262266
dataSource={dataSource}
22272267
/>
2268+
</FormDirtyReportContext.Provider>
22282269
</fieldset>
22292270
</CardContent>
22302271
</Card>
22312272
)}
22322273

22332274
{/* Single action bar at the bottom — suppressed when the host opts out
2234-
(e.g. the Studio screen-preview, which must never persist). */}
2275+
(e.g. the Studio screen-preview, which must never persist).
2276+
Pinned to the bottom edge of whatever scroll frame hosts this form —
2277+
the dialog body, the drawer, the record page — so Save and Cancel
2278+
stay in view at any scroll position (objectstack#34599). Sticky
2279+
resolves against the nearest scrolling ancestor, so it is a direct
2280+
child of this form's root and nothing between it and the host's
2281+
scroller may set `overflow`. Sticky stops at the scroller's CONTENT
2282+
edge: the `after:` strip paints over the host's bottom padding below
2283+
it, so lines never scroll through that gap. Owned here, not by the
2284+
host (ADR-0035 Decision §6: the form owns its Save). */}
22352285
{schema.showSubmit !== false && (
2236-
<div className="border-t border-border pt-4">
2286+
<div
2287+
className="sticky bottom-0 z-10 border-t border-border bg-background pt-4 pb-3 after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-6 after:bg-background"
2288+
data-testid="md-form-actions"
2289+
>
22372290
{/* Why Save is unavailable — above the row so it reads before the
22382291
dead control (objectui#10166). */}
22392292
<UploadInFlightNotice gate={uploadGate} />

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

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import { hasInlineFieldSource, noSubmitTargetError } from './submitTarget';
8484
import { useRecordInvalidation } from './recordInvalidation';
8585
import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate';
8686
import { useInitialFieldFocus } from './initialFieldFocus';
87+
import { FormDirtyReportContext } from './formDirtyReport';
8788

8889
// Localized strings for the unsaved-changes guard and, since objectui#11039,
8990
// the form's own chrome (the default submit and cancel labels and the
@@ -1183,9 +1184,49 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
11831184
);
11841185
}
11851186

1187+
// Radix routes backdrop click, Escape, and the X button all through here, in
1188+
// both arms. Closes are intercepted so unsaved input isn't silently
1189+
// discarded.
1190+
const handleDialogOpenChange = (open: boolean) => {
1191+
if (open) { schema.onOpenChange?.(true); return; }
1192+
attemptClose(false);
1193+
};
1194+
1195+
// Unsaved-changes guard — rendered INSIDE DialogContent so its portal
1196+
// inherits the Dialog's Radix layer context (focus scope + dismissable
1197+
// layer) through React. As a sibling of <Dialog> it had no such context, so
1198+
// the still-open modal swallowed its button clicks and "Keep editing" did
1199+
// nothing. Nesting lets Radix stack the two modals correctly: the alert
1200+
// becomes the topmost layer and its buttons work.
1201+
const discardDialog = (
1202+
<AlertDialog open={discardOpen} onOpenChange={setDiscardOpen}>
1203+
<AlertDialogContent>
1204+
<AlertDialogHeader>
1205+
<AlertDialogTitle>{t('form.discardTitle')}</AlertDialogTitle>
1206+
<AlertDialogDescription>
1207+
{t('form.discardMessage')}
1208+
</AlertDialogDescription>
1209+
</AlertDialogHeader>
1210+
<AlertDialogFooter>
1211+
<AlertDialogCancel onClick={() => { cancelIntentRef.current = false; }}>
1212+
{t('form.keepEditing')}
1213+
</AlertDialogCancel>
1214+
<AlertDialogAction onClick={finalizeClose}>
1215+
{t('form.discard')}
1216+
</AlertDialogAction>
1217+
</AlertDialogFooter>
1218+
</AlertDialogContent>
1219+
</AlertDialog>
1220+
);
1221+
11861222
if (subforms?.length && schema.mode !== 'view') {
1223+
// The master-detail form owns its Save bar and pins it to the bottom of
1224+
// the body scroller below (objectstack#34599); it reports its unsaved
1225+
// input — header, lines, row editor — into this dialog's close guard, so
1226+
// the close paths prompt here exactly as they do in the flat arm. Its
1227+
// batch save carries no OCC token, so this arm has no conflict dialog.
11871228
return (
1188-
<Dialog open={isOpen} onOpenChange={schema.onOpenChange}>
1229+
<Dialog open={isOpen} onOpenChange={handleDialogOpenChange}>
11891230
<MobileDialogContent
11901231
showCloseButton={showCloseButton}
11911232
onOpenAutoFocus={initialFieldFocus.onOpenAutoFocus}
@@ -1204,6 +1245,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12041245
)}
12051246
<div className="@container flex-1 overflow-y-auto px-4 sm:px-6 py-4">
12061247
<Suspense fallback={<ModalFormBodyPending />}>
1248+
<FormDirtyReportContext.Provider value={setIsDirty}>
12071249
<MasterDetailForm
12081250
schema={{
12091251
type: 'object-master-detail-form',
@@ -1239,8 +1281,10 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12391281
}}
12401282
dataSource={dataSource}
12411283
/>
1284+
</FormDirtyReportContext.Provider>
12421285
</Suspense>
12431286
</div>
1287+
{discardDialog}
12441288
</MobileDialogContent>
12451289
</Dialog>
12461290
);
@@ -1249,15 +1293,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12491293
const hasFooter = !loading && !error && (showSubmit || showCancel || showReset);
12501294

12511295
return (
1252-
<Dialog
1253-
open={isOpen}
1254-
onOpenChange={(open) => {
1255-
// Radix routes backdrop click, Escape, and the X button all through
1256-
// here. Intercept closes so unsaved input isn't silently discarded.
1257-
if (open) { schema.onOpenChange?.(true); return; }
1258-
attemptClose(false);
1259-
}}
1260-
>
1296+
<Dialog open={isOpen} onOpenChange={handleDialogOpenChange}>
12611297
<MobileDialogContent
12621298
showCloseButton={showCloseButton}
12631299
onOpenAutoFocus={initialFieldFocus.onOpenAutoFocus}
@@ -1338,30 +1374,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
13381374
</div>
13391375
)}
13401376

1341-
{/* Unsaved-changes guard — rendered INSIDE DialogContent so its portal
1342-
inherits the Dialog's Radix layer context (focus scope + dismissable
1343-
layer) through React. As a sibling of <Dialog> it had no such
1344-
context, so the still-open modal swallowed its button clicks and
1345-
"Keep editing" did nothing. Nesting lets Radix stack the two modals
1346-
correctly: the alert becomes the topmost layer and its buttons work. */}
1347-
<AlertDialog open={discardOpen} onOpenChange={setDiscardOpen}>
1348-
<AlertDialogContent>
1349-
<AlertDialogHeader>
1350-
<AlertDialogTitle>{t('form.discardTitle')}</AlertDialogTitle>
1351-
<AlertDialogDescription>
1352-
{t('form.discardMessage')}
1353-
</AlertDialogDescription>
1354-
</AlertDialogHeader>
1355-
<AlertDialogFooter>
1356-
<AlertDialogCancel onClick={() => { cancelIntentRef.current = false; }}>
1357-
{t('form.keepEditing')}
1358-
</AlertDialogCancel>
1359-
<AlertDialogAction onClick={finalizeClose}>
1360-
{t('form.discard')}
1361-
</AlertDialogAction>
1362-
</AlertDialogFooter>
1363-
</AlertDialogContent>
1364-
</AlertDialog>
1377+
{discardDialog}
13651378
{/* Same nesting rationale as the discard guard above: as a child of
13661379
the Dialog content the conflict alert stacks as the topmost Radix
13671380
layer, so its buttons receive clicks while the modal stays open. */}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { ObjectFormSchema, FormField, FormSchema, DataSource } from '@objec
1818
import { SchemaRenderer, useSafeFieldLabel } from '@object-ui/react';
1919
import { pickLocalized, useObjectTranslation, useLocalization, withHomeAmountSource } from '@object-ui/i18n';
2020
import { useRecordInvalidation } from './recordInvalidation';
21+
import { useReportedDirtyChange } from './formDirtyReport';
2122
import { mapFieldTypeToFormType, buildValidationRules, formatFileSize, fieldHelpText, withFollowedParentObject, withFormObject, PERMISSION_SET_GRANT_COLUMNS } from '@object-ui/fields';
2223
import { isExpressionComputedField } from '@object-ui/core';
2324
import { useIsMobile, toast } from '@object-ui/components';
@@ -814,8 +815,11 @@ const SimpleObjectForm: React.FC<{ schema: LocalizedObjectFormSchema; dataSource
814815
// (objectui#10715). Dirtiness is read from the form renderer's existing
815816
// `onDirtyChange` channel; nothing new is declared on any schema.
816817
const readsRecord = !!schema.recordId && schema.mode !== 'create' && !hasInlineFields;
817-
const { refetch: recordRefetch, onDirtyChange: handleDirtyChange, saved: recordSaved } =
818+
const { refetch: recordRefetch, onDirtyChange: onBusDirtyChange, saved: recordSaved } =
818819
useRecordInvalidation(schema.objectName, schema.recordId, readsRecord);
820+
// The same verdict reaches a hosting master-detail form, when one provides a
821+
// reporter (`formDirtyReport.ts`): its close guard counts the header's input.
822+
const handleDirtyChange = useReportedDirtyChange(onBusDirtyChange);
819823
// The `recordRefetch` value the fetch effect last ran for — a run that moved
820824
// it is a re-read IN PLACE and must not enter the loading branch.
821825
const appliedRecordRefetchRef = React.useRef(0);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
} from './loadFailure';
4040
import { hasInlineFieldSource, noSubmitTargetError } from './submitTarget';
4141
import { useRecordInvalidation } from './recordInvalidation';
42+
import { useReportedDirtyChange } from './formDirtyReport';
4243
import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate';
4344
import { useFormChromeTranslation } from './formChrome';
4445

@@ -374,8 +375,10 @@ export const TabbedForm: React.FC<TabbedFormProps> = ({
374375
// this record, to its object or to `'*'` re-reads the record IN PLACE through
375376
// the effect below while the form is pristine, and is held while it is dirty.
376377
// Dirtiness is the form renderer's `onDirtyChange`, wired below.
377-
const { refetch: recordRefetch, onDirtyChange: handleDirtyChange, saved: recordSaved } =
378+
const { refetch: recordRefetch, onDirtyChange: onBusDirtyChange, saved: recordSaved } =
378379
useRecordInvalidation(schema.objectName, schema.recordId, !!schema.recordId && schema.mode !== 'create');
380+
// Also reported to a hosting master-detail form (`formDirtyReport.ts`).
381+
const handleDirtyChange = useReportedDirtyChange(onBusDirtyChange);
379382

380383
// Fetch initial data for edit/view modes
381384
React.useEffect(() => {

0 commit comments

Comments
 (0)