Skip to content

Commit 9b6db73

Browse files
feat(spec, ui): master_detail children are overview body tables by default (#35691)
Fixes #35597 Part of #35590 Clause-②: yes (widening) Metadata-protocol: semantic Skills-docs: follow-up owed — skills/objectstack-data/rules/relationships.md (line 368, "Default for a master_detail FK with inlineEdit"), skills/objectstack-ui/evals/record-page.json ("after the first field section") ## 维护者速读 - 用户能看到什么变化:打开带主从子表的记录(例如项目的任务),子表默认以表格出现在概览里、关键字段下方和字段分组上方;没有数据也显示表头和一行“新建”,超过十行可“显示全部”,合计由服务器按全部子记录计算。 - 为什么做:这是“记录详情页改版”史诗的子卡,落实维护者“子表放在关键字段下面”的要求,不再要求作者额外打开行内编辑才能把子表放进正文。 - 出错会怎样:原来在侧栏或标签页里的主从子表会移到概览正文;作者在关系字段上改回“侧栏列表”即可恢复原样,本次改动也可以直接撤回。 - 要你做什么:本次修订了一条架构决策记录(配置驱动的主从关系),需要你审核并合并。 ## What changes The rule (`isBodyTableRelationship`, still the one judgement): | FK | `relatedList` | before | after | |---|---|---|---| | master_detail | absent, no `inlineEdit` | side list | **body table** | | master_detail | absent, `inlineEdit` set | body table | body table | | master_detail | `false` | hidden | hidden | | master_detail | `true` | side list | side list | | any | `'primary'` | body table | body table | | lookup | absent | side list | side list | This supersedes two rulings, by id: - **ruling B on #27055** (implemented by #27478): the body-table predicate was `master_detail` + `inlineEdit`. Now the relation type decides; `inlineEdit` stays the WRITE side only (ADR-0035 §3, form derivation untouched). - **ADR-0035 Amendment clause (1) from #27069**. Dated amendment note in its own commit, d4364f4 (`docs/adr/0035-config-driven-master-detail.md`, "Amended (2026-11-19, #35597; epic #35590)"). This makes the PR Tier H. Readers that follow the predicate, measured: - `deriveRelatedLists` (`isPrimary`), `RecordDetailView` (`isBody`), and the Studio inspectors. `ObjectFieldInspector` reads a plain master_detail FK as "primary"; "Show" now writes an explicit `relatedList: true`. `ObjectGroupInspector` now offers plain master_detail relationships as group placements. - `fieldGroupBodyTableRefusal`, at defineStack and the lint publish door: **widened**. A field group may now name a plain master_detail child. It still refuses a lookup side list, `relatedList: true`, and `relatedList: false`. Placement (`buildDefaultPageSchema.ts`, `bodyTablePlacement`, the section posted on the card in comment 7023388416): - A body table that no field group positions is drawn above the field sections, in the parent's `relatedLists` order. That puts it under the header strip's stage bar and key fields. - A group-positioned table keeps its position. - With no section at all, the details node (the highlight fields) leads. - A body table never gets a tab or a related-column card. The drawer uses the same synthesized page. The body-table face (`RelatedList.tsx`): - **Totals are server-owned** (`useBodyTableTotals`). There are two sources: - When the parent has a `summary` field that rolls up the same rows (no extra filter, and the list has no own filter), its stored value is used. - Otherwise one `dataSource.aggregate(child, { aggregations: [sum…], where: parent scope [AND list filter] })` call. A record-mode currency amount is grouped by its code field, and it is totalled only when one code comes back. - This uses the existing `POST /api/v1/data/:object/query` aggregation path. **No new endpoint.** - Totals are drawn as the table's own `summaryRow`. The client "Totals (this page)" sum is gone. A data source with no `aggregate` draws no total. - **Row cap:** 10 by default (`BODY_TABLE_PAGE_SIZE`), and the page's `pageSize` overrides it. Past the cap, a "Show all N" button (`data-body-table-show-all`) replaces the pager and expands in place. - **↗** (`data-body-table-open-list`) calls the host's `onViewAll`. That is the existing `useOpenRecordList` path, so the child list opens under the parent filter. - **Empty:** the column headers plus one row (`data-body-table-empty-row`) holding "No related records found" and a New button. The header's New button is hidden while the table is empty. - No new i18n keys: the existing `list.showAll`, `detail.viewAll`, `detail.noRelatedRecords` and `form.masterDetail.total` are reused. Authored pages (`RecordDetailView.tsx`, the ~5099 `bodyTableIds` line only): `authoredBodyTableIds(page, relations)`, a new export of `deriveRelatedLists.ts`, names the `record:related_list` nodes an authored page places whose relation is a body table. Those nodes get the body treatment: totals, the empty row, and the cap. Examples that flip (A1): `showcase_task.project`, `showcase_field_zoo.f_master_detail`, `showcase_project_membership.team` and `showcase_project_membership.project`. None is a comment, attachment or activity association. The CRM opportunity line item and the showcase expense and invoice lines already declared `inlineEdit`, so they are unchanged. ## Tests <details><summary>Migrated / added / retired tests</summary> Spec and lint: - `packages/spec/src/data/related-list-body-table.test.ts`: verdict cells moved to the new rule (md with no keys → body; md + `inlineEdit: false` → body; md + `true` → side; md + `false` → none). Added a `plainOwned` control; the refusal text was updated. - `packages/spec/src/stack-related-lists-order.test.ts`: a plain md is now accepted. The refusal test now covers md + `relatedList: false` and a hidden lookup. - `packages/lint/src/validate-related-list-refs.test.ts`: added a plain-md group control (no finding). `ui/packages/plugin-detail`: - `src/__tests__/RelatedList.bodyTable-27055.test.tsx`: rewritten against a server `aggregate` mock. It covers the server total, the total over ALL rows at a cap of 1 of 3, show-all, ↗, the empty row, no aggregate meaning no total, the stored roll-up versus filtered lists, and the record-mode groupBy. - **Retired:** "draws the full table with a totals line and no View All" (the client sum). It is replaced by the server-total cases. - `src/synth/__tests__/buildDefaultPageSchema.bodyTables-27055.test.ts`: the new order (tables before the sections), plus a no-section case. - `src/__tests__/RelatedList.parentCurrency-31912.test.tsx`: the total now comes from an aggregate mock and is read off the summary row. - `src/renderers/__tests__/record-related-list.emptyFold-25895.test.tsx`: the empty sentence and New button are read off the empty row. - `src/__tests__/RecordPageColumns.test.tsx` (the test only; `RecordPageColumns.tsx` is untouched): the approval-band fixture places LINES with a field group, so the split it pins still exists. `ui/packages/app-shell`: - `src/utils/__tests__/deriveRelatedLists.test.ts`: md is now `isPrimary: true`. New describe for `authoredBodyTableIds`. - `src/utils/__tests__/deriveRelatedLists.relatedListsOrder-27069.test.ts`: a plain md is primary. Added the true / false / 'primary' cells. - `src/views/metadata-admin/inspectors/ObjectFieldInspector.relatedList-27054.test.tsx`: - the side-card fixture declares `relatedList: true`; - the show/hide case uses a lookup; - new case: a plain md reads as primary and "Show" writes `true`; - collection-time `@objectstack/formula` / `@objectstack/lint` imports (`check:test-source-alias`). - `src/views/RecordDetailView.harness.test.tsx`: new describe "the relation type decides, not inlineEdit" with 3 cases. The 27241 and 27524 side-list fixtures declare `relatedList: true`. - `src/views/RecordDetailView.childWriteRefreshesParent-12244.test.tsx`, `RecordDetailView.recordPageTiers-26678.test.tsx` and `RecordDetailView.relatedListFilter-4664.test.tsx`: these pin side-list mechanics (tabs, badge probes), so their md fixtures declare `relatedList: true`. </details> <details><summary>Local runs at f6595c5 (and the merge 2450e9d before it)</summary> - spec: `vitest run` over the whole package: Test Files 952 passed, Tests 29054 passed | 1 todo. `pnpm --filter @objectstack/spec typecheck` passed (VERDICT command-exit 0). - lint: `vitest run`: Test Files 221 passed, Tests 9311 passed. - ui, the record-page set (plugin-detail whole package plus app-shell `RecordDetailView*`, `deriveRelatedLists*`, the inspectors, `PagePreview`, `AppContent.packagelessRecordRelated-29552`): 13 failures after the rule change, all of them side-list fixtures. Migrated as listed above. - Re-run of the changed files at the final head: Test Files 88 passed, Tests 762 passed. - `pnpm --filter @object-ui/plugin-detail type-check` + build: exit 0. `pnpm --filter @object-ui/app-shell type-check`: exit 0. </details> ## Acceptance notes - Metadata-protocol is declared `semantic`, not the claim's "widened": the vocabulary is `added|narrowed|semantic|none`, and this is a changed default reading of an existing key. - These comments outside the claimed surface still describe the old `inlineEdit` predicate. Comments only, no behaviour: - `ObjectFieldInspector.tsx` ~2977 / ~3006; - `ObjectGroupInspector`; - `RecordDetailView.tsx` ~4285 (out of the claimed region); - the liveness notes in `field.json` / `object.json`; - lint data-model-rules. - The published skills text needs a follow-up, as named on the `Skills-docs:` line. - A4, the dogfood screenshots of the built console, was **NOT MEASURED**. Reason: a console build plus a showcase/CRM stack boot did not fit the memory-tight shared box next to the test runs. The overview order, the empty row, the cap, ↗, and "no tab or card" are pinned by the harness and the RelatedList suites above. A new checklist item, `records-forms.master-detail-body-tables`, carries the live legs. - Checklist: added `docs/qa/platform-checklist/areas/records-forms.json` → `records-forms.master-detail-body-tables` (rev 1). `records-forms.related-list-server-pagination` still holds as written: Contacts is a lookup child. ## Browser reading (A4) Built console, headless Chromium (Playwright), 1440x900, deviceScaleFactor 2, light theme, one server at a time on a private port, signed in as the seeded admin. Same data on both sides: the AFTER sqlite file was copied for the BEFORE boot, so record ids match. - BEFORE = `d9801038` (`origin/main` merge-base of this PR). - AFTER = `b4ba2a6d`. Commits since then (`719ca6f5` the two-key roll-up choice, docs, a describe pin; head now `af275005`) do not touch the cases read here: no case below has two keys to the same parent. The AFTER side was not re-shot on the current head. - This supersedes the "A4 ... NOT MEASURED" note under Acceptance notes. - HotCRM is not in this repository. The showcase and CRM examples below stand in for it. - Local-only data, added through the REST API: 11 extra tasks on Website Relaunch (13 in all), "A4 Empty Team" (no memberships), "A4 Big Team" (12 memberships), and 3 line items on "Acme — Q3 Platform Renewal". - Images are not committed: the repo keeps no review-screenshot convention in-tree. The 36 PNGs (18 per side, `CASE-before.png` / `CASE-after.png`) are in the area folder `objectstack-seat5/area-ux/ux-2/a4-35597/` on the project files mount. | Case | Before (`d9801038`) | After (`b4ba2a6d`) | Verdict | |---|---|---|---| | 1. Project with tasks, `showcase_task.project` (Data Platform, 2 tasks) | Authored page (Details / Tasks / Related tabs). The task list is in the Related tab, footer "View All". | Same tabs and placement: an authored page keeps its own layout. The Related-tab list gets the body face: collapse chevron and ↗ in the header, no footer. No new tab. | As designed. The side-card-to-body flip cannot be seen on the project page, because it is authored. | | 1t. Synthesized page: team with memberships, `showcase_project_membership.team` (Platform, 2) | Memberships tab plus a side card listing "Record #id" rows. | Memberships table in the Overview body, above the Team and Other field sections. No Memberships tab, no rail card. All columns, ↗, New. | Flip confirmed. No duplicate tab or rail card. | | 2. Empty child (A4 Empty Team; Legacy Sunset project) | Team: an empty "Memberships 0" rail card, and the tab sits behind "+1". Project Related tab: a folded one-line "Tasks 0 · No related records found" with New in its header. No table. | Team: body table with column headers and one row, "No related records found" plus New. The header New is hidden. Project Related tab: the same empty row. | Pass. | | 3. Over 10 rows (A4 Big Team, 12; Website Relaunch, 13 tasks) | Team: rail card with 3 rows, plus a Memberships tab. Project Related tab: 5 rows a page, a "Page 1 of 3" pager, and "View All". | Team: 10 rows and "Show all 12". It expands in place to 12 and the button goes away. Project Related tab: 10 rows and "Show all 13", which expands in place. | Pass. | | 4. CRM opportunity with line items, `crm_opportunity_line_item.opportunity` (3 lines; `line_total` 111,000) | Body table under the field sections (Owner ... Products Total). No totals line. | Body table above the field sections, with a ↗ added. **No total row.** | Placement and ↗ as designed. The missing total is unchanged from before and is not a regression; see the note below. | | 4s. Control: showcase expense report EXP-2001 (4 lines) | Body table under the Report section, with the approval lock band above it. | Body table first, with a server total "Total $1,500.50" (equal to the stored `total_amount`) and ↗. The lock band and Report section follow. | Pass. The server total renders. | | 5. Record drawer (project row; team row) | Project drawer: authored tabs, the same as the page. Team drawer: a Memberships tab, plus a Memberships card under the fields. | Project drawer: unchanged authored tabs; the Related tab carries the body face. Team drawer: Memberships body table above the field sections, no tab. | Pass. The drawer uses the same synthesized page. | Case 4 note: the CRM line item `amount` is a currency field with no currency of its own, and the CRM example sets no tenant default. Its cells draw without a symbol ("6,000.00"). `useBodyTableTotals` drops a currency column whose currency does not resolve (`if (!currency) continue`), and it does so before the stored roll-up branch, so the 111,000 the parent already holds is not drawn. Main's client "Totals (this page)" line had the same gate, and neither side draws a total. Not a defect of this PR, but the expected "server total" is not visible on this record. Whether a stored same-rows roll-up should stand without a resolved currency is the area's call. Page errors captured during the runs: none on either side. ## Verification Read first, by risk: 1. `packages/spec/src/data/related-list-body-table.ts`: the three-line predicate. 2. `ui/packages/plugin-detail/src/RelatedList.tsx` `useBodyTableTotals`: the stored versus aggregate choice, and the groupBy for record-mode currency. 3. `ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts` `bodyTablePlacement`: unplaced tables go before the sections. Two-minute check: from `ui/`, run `pnpm exec vitest run packages/plugin-detail/src/__tests__/RelatedList.bodyTable-27055.test.tsx`. Expect every case to pass, including "the total is the server's over EVERY row, not the rows on show". --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CZrgaiMgTJCnswR6jQ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e75a528 commit 9b6db73

30 files changed

Lines changed: 1108 additions & 272 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@object-ui/plugin-detail': minor
4+
'@object-ui/app-shell': minor
5+
---
6+
7+
feat(spec, ui): a master_detail child is a table in the record overview by default
8+
9+
Clause-②: yes (widening: a master_detail FK with no `relatedList` now reads as `'primary'`)
10+
Metadata-protocol: semantic
11+
12+
A `master_detail` child used to be a side list unless it also declared `inlineEdit`. Now the relation type decides: a `master_detail` FK that declares no `relatedList` is a body table in the parent's record overview. `inlineEdit` is no longer needed for that; it stays what it was, the write side (whether the edit form inlines the child as line items).
13+
14+
- `relatedList: false` hides the list, `relatedList: true` keeps it a side list (a card in the related column, a tab on the tab row), `relatedList: 'primary'` is unchanged. A `lookup` FK with no `relatedList` stays a side list.
15+
- `isBodyTableRelationship` is still the one judgement. The field-group placement check at `defineStack` and at the publish door follows it, so a field group may now name a plain `master_detail` child to position its table. Studio reads a plain `master_detail` FK as "primary" and writes an explicit `true` when you pick "Show".
16+
- Placement: the body tables of a synthesized page are drawn in the overview's left column above the field sections (under the stage bar and key fields), in the parent's `relatedLists` order. A field group that names one still positions it. They never get a tab or a related-column card. The drawer uses the same page.
17+
- An empty body table draws its column headers and one empty row holding the empty sentence and a New button.
18+
- The table shows 10 rows by default (the page can set its own page size). "Show all N" expands it in place, and ↗ opens the child list filtered to the parent.
19+
- Totals come from the server: the parent's `summary` field over the same child rows when there is one, otherwise a sum aggregate over every child row of this parent (the existing data query, no new endpoint). They are drawn in the table's summary row. The old "this page" sum of the shown rows is gone; a data source with no `aggregate` draws no total.
20+
- A `master_detail` related list placed on an authored record page gets the same body-table treatment (the totals and the empty row).
21+
22+
To keep an existing `master_detail` child as a side list, write `relatedList: true` on its FK.

‎content/docs/references/data/field.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const result = CurrencyConfigSchema.parse(data);
8585
| **inlineTitle** | `string` | optional | Title for the inline master-detail grid |
8686
| **inlineColumns** | `{ name: string; label?: string; type?: Enum<'text' \| 'number' \| 'currency' \| 'date' \| 'datetime' \| 'time' \| 'select' \| 'lookup' \| 'file'>; width?: number; … }[]` | optional | Explicit columns for the inline grid (derived from the child object when omitted). Each entry is a strict, name-keyed column (`{ name, label?, type?, … }` — objectui GridColumn); identity-only entries (`{ name }`) hydrate everything else from the child object's fields. Unknown keys and the retired `field` spelling are refused at parse. |
8787
| **inlineAmountField** | `string` | optional | Numeric child field summed for the inline grid total |
88-
| **relatedList** | `boolean \| 'primary'` | optional | Show this child collection as a related list on the parent's detail page (read-side mirror of inlineEdit). false = the child object is not shown on the parent record page; true/absent = shown as an auxiliary panel on the record page; 'primary' = part of the record's main content, shown as a full-width table in the record's detail body. Absent on a master_detail field that sets inlineEdit, the list is 'primary' by default; write true to keep it an auxiliary panel. 'primary' places a list and does not order it: the parent object's relatedLists orders the full-width tables and the auxiliary panels. The page layout is defined by ADR-0085. A derived related list (relatedList: 'primary') inherits its row order from the child object's DEFAULT list view sort — the isDefault view, or the first declared list item when none is marked default; wire spelling is sort=`<field>` / sort=-`<field>`, never $orderby. A child object with no list-view sort emits no ordering parameter, and rows fall back to record-id order. |
88+
| **relatedList** | `boolean \| 'primary'` | optional | Show this child collection as a related list on the parent's detail page (read-side mirror of inlineEdit). true = an auxiliary panel on the record page; absent = 'primary' (a body table) on a master_detail field, an auxiliary panel on a lookup field; false = hidden: the child object is not shown on the parent record page; 'primary' = a body table: part of the record's main content, shown as a full-width table in the record's detail body. Write true on a master_detail field to keep it an auxiliary panel. 'primary' places a list and does not order it: the parent object's relatedLists orders the full-width tables and the auxiliary panels. The page layout is defined by ADR-0085. A derived related list (relatedList: 'primary') inherits its row order from the child object's DEFAULT list view sort — the isDefault view, or the first declared list item when none is marked default; wire spelling is sort=`<field>` / sort=-`<field>`, never $orderby. A child object with no list-view sort emits no ordering parameter, and rows fall back to record-id order. |
8989
| **relatedListTitle** | `string` | optional | Title for the detail-page related list |
9090
| **relatedListColumns** | `string[]` | optional | Explicit columns for the detail-page related list, as child field names (e.g. ['name', 'status']); derived from the child object (highlightFields → field walk) when omitted. Strings only — labels, cell types and formatting always derive from the child object's field definitions; column objects are refused at parse. |
9191
| **relatedListFilter** | `any` | optional | Declarative default filter for the detail-page related list: AND-composed with the parent-relationship condition `{ [referenceField]: parentId }` — an authored constraint, never a user-editable suggestion. The related-list tab badge count honors the same composed filter, so counts match the visible rows. Canonical Query-DSL FilterCondition (the same dialect as a query `where`), e.g. `{ status: { $ne: 'deleted' } }` to hide soft-deleted children. |

0 commit comments

Comments
 (0)