Skip to content

Commit 3c21300

Browse files
committed
wip: texts and tests for group-placed detail in the entry form
Claude-Session: https://claude.ai/code/session_01L6bhgXUMw7b8gUmNsyoXHR Co-authored-by: Claude <noreply@anthropic.com>
1 parent bf197a6 commit 3c21300

10 files changed

Lines changed: 280 additions & 12 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/plugin-form': patch
3+
'@object-ui/components': patch
4+
'@objectstack/spec': patch
5+
---
6+
7+
fix(ui): the entry form draws a group-placed master-detail table at its field group
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A master-detail child that a field group of the parent places (`fieldGroups[].relatedList`) is now drawn at that group in the parent's create and edit forms, where the record page draws it, instead of below all of the record's fields:
13+
14+
- A form laid out from the parent's field groups draws the table after the sections of the groups declared before the placing group and before the ones declared after it.
15+
- A tabbed form gives it a tab of its own at that position, labelled with the group's label. A wizard master-detail form is drawn as the simple form, as before, and places it the same way.
16+
- A form whose sections name no field group, and a child no group places (a form view's own `subforms`), keep the table below the record's fields, as before.
17+
18+
The table is the same one: its rows still save with the record in one batch, an expanded row's editor opens beside it, and the document totals stay at the foot of the form. No metadata changes.

‎.changeset/35889-master-detail-tab-by-default.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A `master_detail` FK that declares no `relatedList` used to put its child list i
1919
- `inlineEdit` on the FK no longer inlines a child in the parent's form by itself (maintainer ruling B: only the field group decides). It now only picks the form factor of a child a group places: `'grid'`, `'form'`, or `true` / absent for the shape-picked default. A child with `inlineEdit` that no group names is a tab and is not in the form.
2020
- `os lint`: `relationship/line-items-inline-edit` now suggests a field group on the parent (with its required `label`) instead of `inlineEdit: true`, and only for a FK a group may place; `relationship/association-inline-edit` and `relationship/inline-edit-needs-bulk` judge the children a parent group places; the field-consumer rule credits a child's inline grid columns only when a parent group places it.
2121
- The showcase invoice and expense report, and the CRM opportunity, gain a field group naming their lines, so their forms and record pages keep the line table.
22-
- In the entry form a placed table still sits below the record's fields, where `inlineEdit` tables sit today. Moving it to its group's place in the form is a follow-up.
22+
- In the entry form a placed table sits at its group's place too: between the sections of the groups around it, or in a tab of its own (labelled with the group) in a tabbed form. A form whose sections name no field group keeps it below the record's fields.
2323
- Studio's field-group picker offers the same children as before. The relationship field inspector reads a plain `master_detail` FK as "Show", and "Show" leaves the key absent so a group can still place it.
2424

2525
To keep a master-detail child's table in the overview and its rows in the form (including a child that set `inlineEdit`), add a field group to the parent that names it, in the place the table should sit:

‎docs/adr/0035-config-driven-master-detail.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ a self-referential FK surfaces a "children" list.
169169
> group (a `master_detail` FK may instead drop `relatedList: true`); a group
170170
> naming a list its FK hides (`false`) is refused.
171171
172+
> **Note (2026-11-21, #35889, second slice).** The entry form now draws a
173+
> placed child where the record page does, so "placed in the form below the
174+
> record's fields until the form places it at the group" above is superseded.
175+
> A form laid out from the parent's field groups draws the child's table
176+
> after the sections of the groups declared before the placing group and
177+
> before those declared after it; a tabbed form gives it a tab of its own at
178+
> that position, labelled with the group's label (a wizard master-detail form
179+
> is drawn as the simple form, as before). A form whose sections name no
180+
> declared field group, and a child no group places (a form view's own
181+
> subforms), keep the table below the record's fields. The table is the same
182+
> one: it still saves with the record in one batch, and the document totals
183+
> stay at the foot of the form.
184+
172185
The derivation is a pure function — `deriveRelatedLists(objectDef, objects)` in
173186
`@object-ui/app-shell` (`utils/deriveRelatedLists.ts`) — the read-side analogue
174187
of `attachInlineSubforms`. `RecordDetailView` feeds its output into the

‎packages/spec/src/data/field.zod.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,8 +2365,8 @@ export const FieldSchema = lazySchema(() => {
23652365
* #35597's `'primary'` default): it joins the record's main content only
23662366
* when a field group of the PARENT names it (`ObjectFieldGroupSchema.relatedList`),
23672367
* which draws its table at the group's position in the record page and its
2368-
* edit state, and inlines it in the parent's entry form (below the record's
2369-
* fields until the form places it at the group too).
2368+
* edit state, and inlines it in the parent's entry form at the same place
2369+
* (a form whose sections name no field group keeps it below its fields).
23702370
* Write `relatedList: true` to keep it a tab even from a group (a group
23712371
* naming it is refused), `'primary'` to make it a body table with no group,
23722372
* or `false` to hide it.

‎packages/spec/src/data/object.zod.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,9 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({
14141414
* `relatedList: 'primary'` (the group positions that body table), or a
14151415
* `master_detail` FK that declares no `relatedList` (a tab by default; the
14161416
* group makes it a body table at this position in the record page and its
1417-
* edit state, and the parent's entry form inlines it, below the record's
1418-
* fields until the form places it at the group too, #35889). A group
1417+
* edit state, and the parent's entry form inlines it at the same position;
1418+
* a form whose sections name no field group keeps it below its fields,
1419+
* #35889). A group
14191420
* naming a side card, or a list its FK hides with `relatedList: false`,
14201421
* draws nothing at the group, so it is refused wherever the child's fields
14211422
* are known: at `defineStack` and at the runtime metadata write door
@@ -1426,7 +1427,7 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({
14261427
*/
14271428
relatedList: z.string().regex(RELATED_LIST_ENTRY_PATTERN, {
14281429
message: 'A field group\'s relatedList is a child object name (e.g. "task") or object.field (e.g. "event.related_to"), in snake_case',
1429-
}).optional().describe('Places a related list\'s body table at this position in the record\'s details column instead of a section of fields: names one inbound relationship, as a relatedLists entry does (child object, or object.field when that child has more than one relationship to this object). A group with relatedList holds no fields: a field that names it as its group is refused, and so is a fields list on it. The name is judged as a relatedLists entry is: refused when its child is in the stack with no inbound lookup / master_detail field, or exists nowhere (by os validate / os build, which leave a sys_ / cloud_ / ai_ name to the runtime, and by a metadata write that names no package); a write into a package stores it, and the record page places nothing for it. It names a body table only (a FK declaring relatedList: \'primary\', or a master_detail FK that declares no relatedList, which is a tab unless a group places it; placed, it is drawn here, and the parent\'s entry form inlines it below the record\'s fields until the form places it at the group as well): a group naming a side card or a list hidden by relatedList: false draws nothing, so it is refused where the child\'s fields are known (os validate / os build and the metadata write door), naming the FK and the remedy (set relatedList: \'primary\' on it, name only the body table as object.field when a bare child name also names a side card, or remove the group\'s relatedList).').meta({ title: 'Related List' }),
1430+
}).optional().describe('Places a related list\'s body table at this position in the record\'s details column instead of a section of fields: names one inbound relationship, as a relatedLists entry does (child object, or object.field when that child has more than one relationship to this object). A group with relatedList holds no fields: a field that names it as its group is refused, and so is a fields list on it. The name is judged as a relatedLists entry is: refused when its child is in the stack with no inbound lookup / master_detail field, or exists nowhere (by os validate / os build, which leave a sys_ / cloud_ / ai_ name to the runtime, and by a metadata write that names no package); a write into a package stores it, and the record page places nothing for it. It names a body table only (a FK declaring relatedList: \'primary\', or a master_detail FK that declares no relatedList, which is a tab unless a group places it; placed, it is drawn here, and the parent\'s entry form inlines it here too, or below its fields when the form\'s sections name no field group): a group naming a side card or a list hidden by relatedList: false draws nothing, so it is refused where the child\'s fields are known (os validate / os build and the metadata write door), naming the FK and the remedy (set relatedList: \'primary\' on it, name only the body table as object.field when a bare child name also names a side card, or remove the group\'s relatedList).').meta({ title: 'Related List' }),
14301431

14311432
/**
14321433
* [ADR-0085 §5] Section visibility predicate — CEL, the ADR-0089 canonical

‎packages/spec/src/data/related-list-body-table.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('fieldGroups[i].relatedList describes the body-table rule it enforces',
110110
const text = root.properties?.relatedList?.description ?? '';
111111

112112
it('says it names a body table only, and that any other list is refused with the remedy', () => {
113-
expect(text).toContain("It names a body table only (a FK declaring relatedList: 'primary', or a master_detail FK that declares no relatedList, which is a tab unless a group places it; placed, it is drawn here, and the parent's entry form inlines it below the record's fields until the form places it at the group as well)");
113+
expect(text).toContain("It names a body table only (a FK declaring relatedList: 'primary', or a master_detail FK that declares no relatedList, which is a tab unless a group places it; placed, it is drawn here, and the parent's entry form inlines it here too, or below its fields when the form's sections name no field group)");
114114
expect(text).toContain('a group naming a side card or a list hidden by relatedList: false draws nothing, so it is refused');
115115
expect(text).toContain("set relatedList: 'primary' on it, name only the body table as object.field when a bare child name also names a side card, or remove the group's relatedList");
116116
});

‎packages/spec/src/data/related-list-body-table.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
* default"). It becomes a body table only when one of the PARENT's field
1919
* groups names it (`ObjectFieldGroupSchema.relatedList`): then it is drawn
2020
* at that group's position, the record page's edit state carries it, and
21-
* the parent's entry form inlines it (below the record's fields until the
22-
* form places it at the group). `inlineEdit` takes no part in placement:
23-
* since ruling B on #35889 it only picks the form factor of a child a group
24-
* places (ADR-0035 as amended);
21+
* the parent's entry form inlines it at the same place (below its fields
22+
* when the form's sections name no field group). `inlineEdit` takes no
23+
* part in placement: since ruling B on #35889 it only picks the form
24+
* factor of a child a group places (ADR-0035 as amended);
2525
* - anything else is a tab (`true`, or a `lookup` with no `relatedList`), or
2626
* hidden (`false`). `relatedList: true` on a `master_detail` keeps it a tab,
2727
* which a group cannot override. A `lookup` child is a body table only by

‎packages/spec/src/migrations/entries/semantic/18.master-detail-related-list-tab-by-default.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const entry: SemanticMigration = {
6868
+ 'draws no table for the child and the tab row carries the child\'s tab with its count; the create and '
6969
+ 'edit forms do not inline it. After adding a field group that names the '
7070
+ 'child, second in fieldGroups: the overview draws the child\'s table in the second group\'s place, the '
71-
+ 'tab is still there, the create and edit forms inline the table, and the record page\'s Edit saves the '
71+
+ 'tab is still there, the create and edit forms inline the table at the same place (a tab of its own in a '
72+
+ 'tabbed form), and the record page\'s Edit saves the '
7273
+ 'record fields and the rows in one save. A child whose FK sets inlineEdit and that no group names is not '
7374
+ 'inlined in the parent\'s forms. A child whose FK declares relatedList \'primary\' is drawn on the '
7475
+ 'record page as before: a body table with no tab of its own, whether or not a group positions it. Where '
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import { describe, it, expect, vi } from 'vitest';
2+
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
3+
import React from 'react';
4+
import { registerAllFields } from '@object-ui/fields';
5+
import { MasterDetailForm } from './MasterDetailForm';
6+
7+
// objectstack#35889 — a master-detail collection a field group of the parent
8+
// places (`fieldGroups[].relatedList`) is drawn at that group in the entry
9+
// form, as the record page draws it: after the groups declared before it,
10+
// before the groups declared after it. A collection no group places stays
11+
// below the record's fields.
12+
13+
registerAllFields();
14+
15+
const LINES_GROUP = { key: 'lines', label: 'Lines', relatedList: 'po_line' };
16+
function parentWith(fieldGroups: unknown[]) {
17+
return {
18+
name: 'po',
19+
fieldGroups,
20+
fields: {
21+
ref: { type: 'text', label: 'Ref', group: 'header' },
22+
memo: { type: 'text', label: 'Memo', group: 'totals' },
23+
},
24+
};
25+
}
26+
const HEADER_GROUP = { key: 'header', label: 'Header', fields: ['ref'] };
27+
const TOTALS_GROUP = { key: 'totals', label: 'Totals', fields: ['memo'] };
28+
29+
function makeDataSource(parent: unknown, overrides: Record<string, unknown> = {}) {
30+
return {
31+
getObjectSchema: vi.fn().mockResolvedValue(parent),
32+
find: vi.fn().mockResolvedValue({ data: [] }),
33+
create: vi.fn(),
34+
update: vi.fn(),
35+
delete: vi.fn(),
36+
bulk: vi.fn(),
37+
...overrides,
38+
} as any;
39+
}
40+
41+
const details = [
42+
{ childObject: 'po_line', relationshipField: 'po', title: 'Order lines', columns: [{ key: 'qty', label: 'Qty', type: 'number' } as any] },
43+
];
44+
45+
/** Whether `a` comes before `b` in document order. */
46+
function before(a: Node, b: Node): boolean {
47+
return (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
48+
}
49+
50+
async function collection(container: HTMLElement): Promise<HTMLElement> {
51+
return waitFor(() => {
52+
const el = container.querySelector('[data-testid="md-collection"]') as HTMLElement | null;
53+
if (!el) throw new Error('collection not drawn');
54+
return el;
55+
});
56+
}
57+
58+
describe('MasterDetailForm — a group-placed collection sits at its group (objectstack#35889)', () => {
59+
it('simple form: between the sections of the groups around its group, inside the header form', async () => {
60+
const ds = makeDataSource(parentWith([HEADER_GROUP, LINES_GROUP, TOTALS_GROUP]));
61+
const { container } = render(
62+
<MasterDetailForm schema={{ objectName: 'po', mode: 'create', details } as any} dataSource={ds} />,
63+
);
64+
await waitFor(() => {
65+
const el = container.querySelector('[data-form-slot] [data-testid="md-collection"]');
66+
if (!el) throw new Error('collection not placed');
67+
});
68+
const placed = await collection(container);
69+
const header = container.querySelector('[data-form-section="header"]')!;
70+
const totals = container.querySelector('[data-form-section="totals"]')!;
71+
expect(header).toBeTruthy();
72+
expect(totals).toBeTruthy();
73+
expect(placed.closest('form')).toBe(header.closest('form'));
74+
expect(before(header, placed)).toBe(true);
75+
expect(before(placed, totals)).toBe(true);
76+
expect(placed.textContent).toContain('Order lines');
77+
});
78+
79+
it('simple form: a collection no group places stays below the record fields', async () => {
80+
const ds = makeDataSource(parentWith([HEADER_GROUP, TOTALS_GROUP]));
81+
const { container } = render(
82+
<MasterDetailForm schema={{ objectName: 'po', mode: 'create', details } as any} dataSource={ds} />,
83+
);
84+
await waitFor(() => {
85+
if (!container.querySelector('[data-form-section="totals"]')) throw new Error('header not ready');
86+
});
87+
const below = await collection(container);
88+
expect(below.closest('form')).toBeNull();
89+
expect(container.querySelector('[data-form-slot]')).toBeNull();
90+
expect(before(container.querySelector('[data-form-section="totals"]')!, below)).toBe(true);
91+
});
92+
93+
it('a group placed last: after every declared group', async () => {
94+
const ds = makeDataSource(parentWith([HEADER_GROUP, TOTALS_GROUP, LINES_GROUP]));
95+
const { container } = render(
96+
<MasterDetailForm schema={{ objectName: 'po', mode: 'create', details } as any} dataSource={ds} />,
97+
);
98+
await waitFor(() => {
99+
if (!container.querySelector('[data-form-slot] [data-testid="md-collection"]')) throw new Error('not placed');
100+
});
101+
const placed = await collection(container);
102+
expect(before(container.querySelector('[data-form-section="totals"]')!, placed)).toBe(true);
103+
});
104+
105+
it('saves the record and its lines in one batch from the placed table', async () => {
106+
const batchTransaction = vi.fn().mockResolvedValue({ results: [{ id: 'po1' }] });
107+
const ds = makeDataSource(parentWith([HEADER_GROUP, LINES_GROUP, TOTALS_GROUP]), { batchTransaction });
108+
const { container } = render(
109+
<MasterDetailForm schema={{ objectName: 'po', mode: 'create', details } as any} dataSource={ds} />,
110+
);
111+
await waitFor(() => {
112+
if (!container.querySelector('[data-form-slot] [data-testid="md-collection"]')) throw new Error('not placed');
113+
});
114+
const ref = container.querySelector('input[name="ref"]') as HTMLInputElement;
115+
fireEvent.change(ref, { target: { value: 'PO-1' } });
116+
fireEvent.click(screen.getByTestId('md-form-submit'));
117+
await waitFor(() => expect(batchTransaction).toHaveBeenCalledTimes(1));
118+
const ops = batchTransaction.mock.calls[0][0] as Array<{ object?: string; objectName?: string; data?: any }>;
119+
expect(JSON.stringify(ops)).toContain('PO-1');
120+
});
121+
122+
it('tabbed form: a tab of its own at its group, labelled with the group', async () => {
123+
const ds = makeDataSource(parentWith([HEADER_GROUP, LINES_GROUP, TOTALS_GROUP]));
124+
const { container } = render(
125+
<MasterDetailForm
126+
schema={{
127+
objectName: 'po',
128+
mode: 'create',
129+
formType: 'tabbed',
130+
sections: [
131+
{ name: 'header', label: 'Header', fields: ['ref'] },
132+
{ name: 'totals', label: 'Totals', fields: ['memo'] },
133+
],
134+
details,
135+
} as any}
136+
dataSource={ds}
137+
/>,
138+
);
139+
await waitFor(() => {
140+
if (!container.querySelector('[data-form-slot] [data-testid="md-collection"]')) throw new Error('not placed');
141+
});
142+
const tabs = screen.getAllByRole('tab').map((tab) => tab.textContent?.trim());
143+
expect(tabs).toEqual(['Header', 'Lines', 'Totals']);
144+
const placed = await collection(container);
145+
const panel = placed.closest('[role="tabpanel"]') as HTMLElement;
146+
expect(panel).toBeTruthy();
147+
const label = panel.getAttribute('aria-labelledby');
148+
expect(label && document.getElementById(label)?.textContent?.trim()).toBe('Lines');
149+
});
150+
});

0 commit comments

Comments
 (0)