Skip to content

Commit f7b1a6d

Browse files
committed
wip(plugin-form): retire SplitForm; move drawer/modal containers to the object-form block
1 parent 295699d commit f7b1a6d

15 files changed

Lines changed: 216 additions & 784 deletions

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
*
1515
* Renamed off `FormSection` (objectui#3161, objectstack#4115 ledger batch 7).
1616
* `@objectstack/spec/ui` owns `FormSection` for the authored section METADATA —
17-
* `{ name?, label?, description?, collapsible, collapsed, columns, pane?,
17+
* `{ name?, label?, description?, collapsible, collapsed, columns,
1818
* visibleWhen?, fields }` — and this repo already uses that word for that
1919
* meaning in its own prose: `plugin-form/README.md` and the plugin docs both
20-
* write "spec `FormSection.pane`", `@object-ui/types` re-exports the spec type
20+
* wrote "spec `FormSection.pane`" (retired with the split form, ADR-0050),
21+
* `@object-ui/types` re-exports the spec type
2122
* as `SpecFormSection`, and its own authored dialect is `ObjectFormSection`. So
2223
* the name was taken twice over, and the file header said this component
2324
* "aligns with @objectstack/spec FormSection" — the canonical-claim comment the
@@ -28,7 +29,7 @@
2829
* ONE prop, so that renderer restates nothing. This one takes the metadata
2930
* FLATTENED into individual props (`label`, `description`, `collapsible`,
3031
* `collapsed`, `columns`) — a second vocabulary for the same keys, minus
31-
* `fields` (children instead), minus `name`, minus `pane`, minus `visibleWhen`,
32+
* `fields` (children instead), minus `name`, minus `visibleWhen`,
3233
* plus render-only knobs. A declaration like that is exactly what the next
3334
* session would read as the authoritative shape of a form section.
3435
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export interface MasterDetailFormSchema {
126126
objectName: string;
127127
mode?: 'create' | 'edit';
128128
/**
129-
* `string | number` to match `ObjectFormSchema` and the drawer/modal/split/
129+
* `string | number` to match `ObjectFormSchema` and the drawer/modal/
130130
* tabbed/wizard envelopes that hand a record straight through to this form —
131131
* a numeric primary key is a real backend shape. Narrowed to a string only at
132132
* the batch-transaction boundary, whose `BatchTransactionOperation.id` is a

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

Lines changed: 36 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ import {
3838
import { TabbedForm } from './TabbedForm';
3939
import { WizardForm } from './WizardForm';
4040
import { useFormChromeTranslation } from './formChrome';
41-
import { SplitForm } from './SplitForm';
42-
import { DrawerForm } from './DrawerForm';
43-
import { ModalForm } from './ModalForm';
4441
import { MasterDetailForm } from './MasterDetailForm';
4542
import {
4643
applyAutoLayout,
@@ -226,18 +223,31 @@ export const ObjectForm: React.FC<ObjectFormComponentProps> = ({ schema, ...rest
226223
</RecordFieldAccessForForm>
227224
);
228225

229-
const ObjectFormBody: React.FC<ObjectFormComponentProps> = ({
230-
schema: rawSchema,
231-
dataSource,
232-
}) => {
226+
/**
227+
* The schema every layout reads, prepared ONCE above the layout fork: the
228+
* structured `buttons` / `defaults` folded onto the flat keys, the seven
229+
* `I18nLabel` members resolved, legacy `groups` normalised to `sections`,
230+
* field-level permissions applied and `{ group }` sections resolved — plus the
231+
* section-label translator every section map uses.
232+
*
233+
* A hook of its own because two renderers prepare the same schema: this file's
234+
* `ObjectForm` (the `simple` / `tabbed` / `wizard` layouts) and
235+
* `ObjectFormContainer`, which supplies the drawer or modal container an
236+
* `object-form` block asks for with `formType` (ADR-0050 Decision 4 — the
237+
* container is the caller's, never the form's).
238+
*/
239+
export function usePreparedFormSchema(
240+
rawSchema: ObjectFormComponentProps['schema'],
241+
dataSource: ObjectFormComponentProps['dataSource'],
242+
) {
233243
const perms = usePermissions();
234244

235245
// ── `sections[].group` — the ADR-0085 §5 REFERENCE form (objectui#7051) ───
236246
//
237247
// A section may point `group` at one of the object's declared `fieldGroups`
238248
// instead of enumerating members (`@objectstack/spec` 17.3.0,
239249
// objectstack#13855). Resolving it needs the OBJECT definition, and this
240-
// dispatcher — unlike the six bodies below it — has never loaded one.
250+
// preparation — unlike the layout bodies it feeds — has never loaded one.
241251
//
242252
// It is resolved HERE, above the routing, on purpose: every variant's
243253
// `sections` prop is rebuilt key by key in the maps below, so a `group` left
@@ -274,7 +284,8 @@ const ObjectFormBody: React.FC<ObjectFormComponentProps> = ({
274284

275285
// Apply field-level permissions to the entire schema (sections + flat
276286
// fields) BEFORE dispatching to any variant. This way all variants
277-
// (Tabbed/Wizard/Split/Drawer/Modal/Simple) transparently honour FLS.
287+
// (Tabbed/Wizard/Simple here, Drawer/Modal through `ObjectFormContainer`)
288+
// transparently honour FLS.
278289
// Fail-open when no provider mounted (perms.isLoaded false).
279290
const schema = useMemo<LocalizedObjectFormSchema>(() => {
280291
// framework#1894 / objectstack-ai/objectstack#2998 (ADR-0078): the authored @objectstack/spec
@@ -341,15 +352,23 @@ const ObjectFormBody: React.FC<ObjectFormComponentProps> = ({
341352
const { sectionLabel } = useSafeFieldLabel();
342353
const tSec = (s: any) =>
343354
s?.name ? sectionLabel(schema.objectName, s.name, s.label || s.name) : s?.label;
355+
return { schema, tSec };
356+
}
357+
358+
const ObjectFormBody: React.FC<ObjectFormComponentProps> = ({
359+
schema: rawSchema,
360+
dataSource,
361+
}) => {
362+
const { schema, tSec } = usePreparedFormSchema(rawSchema, dataSource);
344363

345364
// Master-detail: when the schema declares inline child collections, render as
346365
// a master-detail form (parent fields + child grids, persisted atomically).
347366
// This lets a plain form view become master-detail by config — no bespoke
348367
// page. Skipped in view mode (read-only detail uses related lists instead).
349-
// For drawer/modal formTypes we fall through to DrawerForm/ModalForm, which
350-
// host the master-detail form INSIDE their envelope.
351-
const routesToMasterDetail = !!(schema as any).subforms?.length && schema.mode !== 'view'
352-
&& schema.formType !== 'drawer' && schema.formType !== 'modal';
368+
// A drawer or modal container never reaches here: `ObjectFormContainer`
369+
// hands it to DrawerForm/ModalForm, which host the master-detail form INSIDE
370+
// their envelope.
371+
const routesToMasterDetail = !!(schema as any).subforms?.length && schema.mode !== 'view';
353372

354373
// ── objectui#6237 diagnostic, now scoped to the ONE arm still inert ────────
355374
// The interim diagnostic ruled on 2026-08-29 covered `tabbed` AND `wizard`,
@@ -447,10 +466,10 @@ const ObjectFormBody: React.FC<ObjectFormComponentProps> = ({
447466
// ADR-0089 section predicate (objectui#6237) — key-by-key rebuild,
448467
// so an uncopied key is silently dropped before TabbedForm ever
449468
// sees it, exactly as it was on this route until this card. The
450-
// split/drawer/modal maps below have carried it since #6111; this
451-
// is the tabbed arm joining them.
469+
// drawer/modal maps (`ObjectFormContainer`) have carried it since
470+
// #6111; this is the tabbed arm joining them.
452471
//
453-
// Read WITHOUT an `as any` cast on purpose, unlike those three:
472+
// Read WITHOUT an `as any` cast on purpose, unlike those two:
454473
// `ObjectFormSection.visibleWhen` is declared, so the compiler is
455474
// able to catch a rename here. Through a cast it would keep
456475
// compiling and silently copy `undefined` — the exact silent-drop
@@ -532,115 +551,6 @@ const ObjectFormBody: React.FC<ObjectFormComponentProps> = ({
532551
);
533552
}
534553

535-
if (schema.formType === 'split' && schema.sections?.length) {
536-
return (
537-
<SplitForm
538-
schema={{
539-
...schema,
540-
formType: 'split',
541-
sections: schema.sections.map(s => ({
542-
name: s.name,
543-
label: tSec(s),
544-
description: s.description,
545-
columns: s.columns,
546-
// `?? []` — see the tabbed arm above (objectui#7051).
547-
fields: s.fields ?? [],
548-
// Explicit pane placement (spec FormSection.pane). This mapping
549-
// rebuilds each section key by key, so a key it doesn't copy is
550-
// silently dropped — exactly how `visibleOn` once vanished here.
551-
pane: s.pane,
552-
// ADR-0089 section predicate (#6111) — same reason as `pane` above:
553-
// a key this map does not copy never reaches the layout at all.
554-
visibleWhen: (s as any).visibleWhen,
555-
visibleWhenFault: s.visibleWhenFault,
556-
// `className` / `gridClassName`: deliberately not copied — see the
557-
// tabbed arm above (objectstack#13626, ruled 2026-09-01).
558-
})),
559-
splitDirection: schema.splitDirection,
560-
splitSize: schema.splitSize,
561-
splitResizable: schema.splitResizable,
562-
}}
563-
dataSource={dataSource}
564-
className={schema.className}
565-
/>
566-
);
567-
}
568-
569-
if (schema.formType === 'drawer') {
570-
// `layout` passes through unfolded: it is `vertical | horizontal` on both
571-
// faces since objectui#11168 slice 3 (objectui#7759 group C), and the fold
572-
// that mapped `inline` / `grid` away here is retired with them.
573-
return (
574-
<DrawerForm
575-
schema={{
576-
...schema,
577-
formType: 'drawer',
578-
sections: schema.sections?.map(s => ({
579-
name: s.name,
580-
label: tSec(s),
581-
description: s.description,
582-
columns: s.columns,
583-
// `?? []` — see the tabbed arm above (objectui#7051).
584-
fields: s.fields ?? [],
585-
collapsible: (s as any).collapsible,
586-
collapsed: (s as any).collapsed,
587-
// ADR-0089 section predicate (#6111) — key-by-key rebuild, so an
588-
// uncopied key is silently dropped before DrawerForm ever sees it.
589-
visibleWhen: (s as any).visibleWhen,
590-
visibleWhenFault: s.visibleWhenFault,
591-
// `className`: deliberately not copied — see the tabbed arm above
592-
// (objectstack#13626, ruled 2026-09-01). DrawerForm's own divider
593-
// site stops reading it in the same pass.
594-
})),
595-
open: schema.open,
596-
onOpenChange: schema.onOpenChange,
597-
drawerSide: schema.drawerSide,
598-
drawerWidth: schema.drawerWidth,
599-
}}
600-
dataSource={dataSource}
601-
className={schema.className}
602-
/>
603-
);
604-
}
605-
606-
if (schema.formType === 'modal') {
607-
// `layout` passes through unfolded — see the drawer branch above.
608-
return (
609-
<ModalForm
610-
schema={{
611-
...schema,
612-
formType: 'modal',
613-
sections: schema.sections?.map(s => ({
614-
name: s.name,
615-
label: tSec(s),
616-
description: s.description,
617-
columns: s.columns,
618-
// `?? []` — see the tabbed arm above (objectui#7051).
619-
fields: s.fields ?? [],
620-
// The collapse pair (objectui#9849 step two — director ruling
621-
// letter E, item 1: group semantics attach 「on every arm」). The
622-
// spec declares both on `sections[]`; this map used to copy
623-
// neither, so the modal silently ignored a declared collapse.
624-
collapsible: s.collapsible,
625-
collapsed: s.collapsed,
626-
// ADR-0089 section predicate (#6111) — key-by-key rebuild, so an
627-
// uncopied key is silently dropped before ModalForm ever sees it.
628-
visibleWhen: (s as any).visibleWhen,
629-
visibleWhenFault: s.visibleWhenFault,
630-
// `className` / `gridClassName`: deliberately not copied — see the
631-
// tabbed arm above (objectstack#13626, ruled 2026-09-01).
632-
})),
633-
open: schema.open,
634-
onOpenChange: schema.onOpenChange,
635-
modalSize: schema.modalSize,
636-
modalCloseButton: schema.modalCloseButton,
637-
}}
638-
dataSource={dataSource}
639-
className={schema.className}
640-
/>
641-
);
642-
}
643-
644554
// Default: simple form
645555
return <SimpleObjectForm schema={schema} dataSource={dataSource} />;
646556
};
@@ -1342,7 +1252,7 @@ const SimpleObjectForm: React.FC<{ schema: LocalizedObjectFormSchema; dataSource
13421252
}
13431253

13441254
// What this save writes — the ONE outbound sequence, shared with the
1345-
// `tabbed`, `split` and `wizard` layouts (objectui#10563): strip what a form never
1255+
// `tabbed` and `wizard` layouts (objectui#10563): strip what a form never
13461256
// writes (server-owned, computed, read-only, unknown to the object, and
13471257
// refused by the caller's field-level security through `fieldWriteGate`,
13481258
// objectui#10108 / `80c54122e`), omit the producer-owned defaults on a
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* ObjectFormContainer — the drawer and modal containers an `object-form`
11+
* block asks for with `formType: 'drawer' | 'modal'`.
12+
*
13+
* ADR-0050 Decision 4 (Accepted by ruling 6464210455 on objectstack#27032):
14+
* `ObjectForm` lays a form out (`simple` / `tabbed` / `wizard`) and never
15+
* chooses where it opens; `DrawerForm` / `ModalForm` are containers the CALLER
16+
* supplies. A host that owns the container mounts `ModalForm` itself (the
17+
* console's New / Edit dialog, an action modal). A page author has no such
18+
* host: the `object-form` block (`<ObjectForm formType="drawer">` on a React
19+
* page) is the only door to a built-in overlay form, so the block renderer is
20+
* the caller, and this is the container it supplies. The form view's own
21+
* `type` never reaches here: `@objectstack/spec` refuses `drawer` / `modal`
22+
* there since #27155.
23+
*
24+
* Both maps prepare the schema through `usePreparedFormSchema`, the one
25+
* preparation `ObjectForm` uses, so the labels, field-level security and
26+
* `{ group }` sections a container draws are the ones the layouts draw.
27+
*/
28+
29+
import React from 'react';
30+
import type { ObjectFormSchema } from '@object-ui/types';
31+
import { usePreparedFormSchema, ObjectForm, type ObjectFormComponentProps } from './ObjectForm';
32+
import { DrawerForm } from './DrawerForm';
33+
import { ModalForm } from './ModalForm';
34+
import { RecordFieldAccessForForm } from './recordFieldAccess';
35+
36+
/** The `formType` values that name a container rather than a layout. */
37+
export type ObjectFormContainerType = 'drawer' | 'modal';
38+
39+
/** True when an `object-form` block's `formType` names a container. */
40+
export function isObjectFormContainerType(
41+
formType: ObjectFormSchema['formType'] | undefined,
42+
): formType is ObjectFormContainerType {
43+
return formType === 'drawer' || formType === 'modal';
44+
}
45+
46+
/**
47+
* The container route of the `object-form` block. Wrapped in the same record
48+
* field-lock scope as `ObjectForm` (objectstack#26594).
49+
*/
50+
export const ObjectFormContainer: React.FC<ObjectFormComponentProps> = ({ schema, ...rest }) => (
51+
<RecordFieldAccessForForm schema={schema} dataSource={rest.dataSource}>
52+
{/* `schema=` by name, so the handler-key census follows the document into the body. */}
53+
<ObjectFormContainerBody schema={schema} {...rest} />
54+
</RecordFieldAccessForForm>
55+
);
56+
57+
const ObjectFormContainerBody: React.FC<ObjectFormComponentProps> = ({
58+
schema: rawSchema,
59+
dataSource,
60+
}) => {
61+
const { schema, tSec } = usePreparedFormSchema(rawSchema, dataSource);
62+
63+
if (schema.formType === 'drawer') {
64+
// `layout` passes through unfolded: it is `vertical | horizontal` on both
65+
// faces since objectui#11168 slice 3 (objectui#7759 group C), and the fold
66+
// that mapped `inline` / `grid` away here is retired with them.
67+
return (
68+
<DrawerForm
69+
schema={{
70+
...schema,
71+
formType: 'drawer',
72+
sections: schema.sections?.map(s => ({
73+
name: s.name,
74+
label: tSec(s),
75+
description: s.description,
76+
columns: s.columns,
77+
// `?? []` — see `ObjectForm`'s tabbed arm (objectui#7051).
78+
fields: s.fields ?? [],
79+
collapsible: (s as any).collapsible,
80+
collapsed: (s as any).collapsed,
81+
// ADR-0089 section predicate (#6111) — key-by-key rebuild, so an
82+
// uncopied key is silently dropped before DrawerForm ever sees it.
83+
visibleWhen: (s as any).visibleWhen,
84+
visibleWhenFault: s.visibleWhenFault,
85+
// `className`: deliberately not copied — see `ObjectForm`'s tabbed arm
86+
// (objectstack#13626, ruled 2026-09-01). DrawerForm's own divider
87+
// site stops reading it in the same pass.
88+
})),
89+
open: schema.open,
90+
onOpenChange: schema.onOpenChange,
91+
drawerSide: schema.drawerSide,
92+
drawerWidth: schema.drawerWidth,
93+
}}
94+
dataSource={dataSource}
95+
className={schema.className}
96+
/>
97+
);
98+
}
99+
100+
if (schema.formType === 'modal') {
101+
// `layout` passes through unfolded — see the drawer branch above.
102+
return (
103+
<ModalForm
104+
schema={{
105+
...schema,
106+
formType: 'modal',
107+
sections: schema.sections?.map(s => ({
108+
name: s.name,
109+
label: tSec(s),
110+
description: s.description,
111+
columns: s.columns,
112+
// `?? []` — see `ObjectForm`'s tabbed arm (objectui#7051).
113+
fields: s.fields ?? [],
114+
// The collapse pair (objectui#9849 step two — director ruling
115+
// letter E, item 1: group semantics attach 「on every arm」). The
116+
// spec declares both on `sections[]`; this map used to copy
117+
// neither, so the modal silently ignored a declared collapse.
118+
collapsible: s.collapsible,
119+
collapsed: s.collapsed,
120+
// ADR-0089 section predicate (#6111) — key-by-key rebuild, so an
121+
// uncopied key is silently dropped before ModalForm ever sees it.
122+
visibleWhen: (s as any).visibleWhen,
123+
visibleWhenFault: s.visibleWhenFault,
124+
// `className` / `gridClassName`: deliberately not copied — see
125+
// `ObjectForm`'s tabbed arm (objectstack#13626, ruled 2026-09-01).
126+
})),
127+
open: schema.open,
128+
onOpenChange: schema.onOpenChange,
129+
modalSize: schema.modalSize,
130+
modalCloseButton: schema.modalCloseButton,
131+
}}
132+
dataSource={dataSource}
133+
className={schema.className}
134+
/>
135+
);
136+
}
137+
138+
// Not a container: the layout is `ObjectForm`'s to draw.
139+
return <ObjectForm schema={rawSchema} dataSource={dataSource} />;
140+
};

0 commit comments

Comments
 (0)