From 11268c72efcc658ade4de1b797ab9791e08d348f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:43:17 +0000 Subject: [PATCH 01/10] feat(spec): fieldGroups[].fields lists a group's members and their order A field group may list its own members in display order. A group that lists none keeps the older rule (Field.group plus field declaration order), so existing objects render as before. The object parse refuses the two spellings disagreeing. Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .../spec/src/data/field-group-layout.test.ts | 168 +++++++++++++++++- packages/spec/src/data/field-group-layout.ts | 93 ++++++++-- packages/spec/src/data/field.zod.ts | 13 +- packages/spec/src/data/object.zod.ts | 155 +++++++++++++--- 4 files changed, 389 insertions(+), 40 deletions(-) diff --git a/packages/spec/src/data/field-group-layout.test.ts b/packages/spec/src/data/field-group-layout.test.ts index 8d2bab8b914..fa75bdcfe5a 100644 --- a/packages/spec/src/data/field-group-layout.test.ts +++ b/packages/spec/src/data/field-group-layout.test.ts @@ -1,7 +1,8 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. import { describe, it, expect } from 'vitest'; -import { deriveFieldGroupLayout, FIELD_GROUP_SYSTEM_FIELDS, AUDIT_PROVENANCE_FIELDS } from './field-group-layout'; +import { deriveFieldGroupLayout, readFieldGroupMembership, FIELD_GROUP_SYSTEM_FIELDS, AUDIT_PROVENANCE_FIELDS } from './field-group-layout'; +import { ObjectSchema } from './object.zod'; describe('deriveFieldGroupLayout (ADR-0085 §5)', () => { const groupedDef = { @@ -181,3 +182,168 @@ describe('AUDIT_PROVENANCE_FIELDS', () => { } }); }); + +describe('fieldGroups[].fields — a group lists its own members and their order', () => { + // The epic's quote: `fields` declares name before account; the group lists + // account first. + const quote = (groups: unknown[], fieldExtras: Record> = {}) => ({ + name: 'quote', + label: 'Quote', + fieldGroups: groups, + fields: { + name: { type: 'text', label: 'Name', ...fieldExtras.name }, + account: { type: 'text', label: 'Account', ...fieldExtras.account }, + valid_until: { type: 'date', label: 'Valid until', ...fieldExtras.valid_until }, + discount: { type: 'percent', label: 'Discount', ...fieldExtras.discount }, + terms: { type: 'textarea', label: 'Terms', ...fieldExtras.terms }, + }, + }); + + it('places the listed fields in list order, not field declaration order', () => { + const def = quote([{ key: 'basic', label: 'Basic', fields: ['account', 'name'] }]); + const sections = deriveFieldGroupLayout(def)!; + expect(sections[0]).toMatchObject({ key: 'basic', fields: ['account', 'name'] }); + // Everything no group lists stays in the trailing untitled bucket, in declaration order. + expect(sections[1]).toEqual({ collapse: 'none', fields: ['valid_until', 'discount', 'terms'] }); + }); + + it('a group without fields keeps the older Field.group rule beside a listing group', () => { + const def = quote( + [ + { key: 'basic', label: 'Basic', fields: ['valid_until', 'name'] }, + { key: 'money', label: 'Money' }, + ], + { discount: { group: 'money' }, account: { group: 'money' } }, + ); + expect(deriveFieldGroupLayout(def)!.map((s) => [s.key, s.fields])).toEqual([ + ['basic', ['valid_until', 'name']], + ['money', ['account', 'discount']], + [undefined, ['terms']], + ]); + }); + + it('a field whose group names a listing group the list leaves out follows the listed ones', () => { + const def = quote( + [{ key: 'basic', label: 'Basic', fields: ['account', 'name'] }], + { terms: { group: 'basic' }, valid_until: { group: 'basic' } }, + ); + expect(deriveFieldGroupLayout(def)![0].fields).toEqual(['account', 'name', 'valid_until', 'terms']); + }); + + it('skips a listed name the object does not declare, and a hidden listed field', () => { + const def = quote( + [{ key: 'basic', label: 'Basic', fields: ['tax_id', 'account', 'discount'] }], + { discount: { hidden: true } }, + ); + expect(deriveFieldGroupLayout(def)![0].fields).toEqual(['account']); + }); + + it('keeps a system field a list names, as the older spelling does', () => { + const def = { ...quote([{ key: 'basic', label: 'Basic', fields: ['created_at', 'name'] }]) }; + (def.fields as Record).created_at = { type: 'datetime', label: 'Created' }; + expect(deriveFieldGroupLayout(def)![0].fields).toEqual(['created_at', 'name']); + }); + + it('a group whose list names nothing it can show is dropped, as an empty group is', () => { + const def = quote([ + { key: 'basic', label: 'Basic', fields: ['name'] }, + { key: 'ghost', label: 'Ghost', fields: ['nowhere'] }, + ]); + expect(deriveFieldGroupLayout(def)!.map((s) => s.key)).toEqual(['basic', undefined]); + }); + + it('un-parsed input that breaks the agreement rules resolves first-listing-wins', () => { + const def = quote( + [ + { key: 'basic', label: 'Basic', fields: ['name', 'account'] }, + { key: 'money', label: 'Money', fields: ['account', 'discount'] }, + ], + { name: { group: 'money' } }, + ); + const sections = deriveFieldGroupLayout(def)!; + expect(sections[0].fields).toEqual(['name', 'account']); + expect(sections[1].fields).toEqual(['discount']); + }); + + it('readFieldGroupMembership answers the same membership, hidden fields included', () => { + const def = quote( + [{ key: 'basic', label: 'Basic', fields: ['account', 'name'] }, { key: 'money', label: 'Money' }], + { discount: { group: 'money', hidden: true }, terms: { group: 'basic' } }, + ); + const { members, groupOf } = readFieldGroupMembership(def); + expect([...members]).toEqual([ + ['basic', ['account', 'name', 'terms']], + ['money', ['discount']], + ]); + expect(groupOf.get('discount')).toBe('money'); + expect(groupOf.has('valid_until')).toBe(false); + }); +}); + +describe('fieldGroups[].fields — the object parse holds the two spellings in agreement', () => { + const base = { + name: 'quote', + label: 'Quote', + fields: { + name: { type: 'text', label: 'Name' }, + account: { type: 'text', label: 'Account' }, + discount: { type: 'percent', label: 'Discount' }, + } as Record>, + }; + const issues = (def: unknown) => { + const r = ObjectSchema.safeParse(def); + return r.success ? [] : r.error.issues.map((i) => ({ path: i.path.join('.'), message: i.message })); + }; + + it('parses a listing group, and keeps the list on the output', () => { + const r = ObjectSchema.safeParse({ ...base, fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['account', 'name'] }] }); + expect(r.success).toBe(true); + expect(r.success && r.data.fieldGroups?.[0].fields).toEqual(['account', 'name']); + }); + + it('parses a listed field whose own group names the same group, and a listed name no field declares', () => { + expect(issues({ + ...base, + fields: { ...base.fields, name: { ...base.fields.name, group: 'basic' } }, + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['name', 'tax_id'] }], + })).toEqual([]); + }); + + it('refuses a listed field whose own group names another group, at both places', () => { + const found = issues({ + ...base, + fields: { ...base.fields, account: { ...base.fields.account, group: 'money' } }, + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['account'] }, { key: 'money', label: 'Money' }], + }); + expect(found.map((i) => i.path)).toEqual(['fieldGroups.0.fields.0', 'fields.account.group']); + expect(found[0].message).toContain("'basic'"); + expect(found[0].message).toContain("'money'"); + }); + + it('refuses a field two groups list, at the second listing', () => { + const found = issues({ + ...base, + fieldGroups: [ + { key: 'basic', label: 'Basic', fields: ['name', 'account'] }, + { key: 'money', label: 'Money', fields: ['discount', 'account'] }, + ], + }); + expect(found.map((i) => i.path)).toEqual(['fieldGroups.1.fields.1']); + expect(found[0].message).toContain("'basic' and 'money'"); + }); + + it('refuses a name one list repeats', () => { + expect(issues({ ...base, fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['name', 'name'] }] }) + .map((i) => i.path)).toEqual(['fieldGroups.0.fields.1']); + }); + + it('refuses fields on a group that places a related list', () => { + expect(issues({ ...base, fieldGroups: [{ key: 'lines', label: 'Lines', relatedList: 'quote_line', fields: ['name'] }] }) + .map((i) => i.path)).toEqual(['fieldGroups.0.fields']); + }); + + it('refuses a list entry that is not a snake_case field name', () => { + expect(issues({ ...base, fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['Account'] }] }) + .map((i) => i.path)).toEqual(['fieldGroups.0.fields.0']); + }); +}); diff --git a/packages/spec/src/data/field-group-layout.ts b/packages/spec/src/data/field-group-layout.ts index 54baee44aee..fa8fef78912 100644 --- a/packages/spec/src/data/field-group-layout.ts +++ b/packages/spec/src/data/field-group-layout.ts @@ -4,7 +4,8 @@ * Field-group layout derivation — the single source of the `fieldGroups` * rendering semantics (ADR-0085 §5). * - * An object's `fieldGroups` + each field's `Field.group` membership are a + * An object's `fieldGroups` (each group's own `fields` list, or else each + * field's older `Field.group`) are a * cross-surface semantic role: forms, detail pages, drawers and the designer * all render the SAME grouping. The rules live here — a pure, dependency-free * helper next to the schema that defines the keys (the ADR-0078 §2 @@ -14,6 +15,14 @@ * * Rules (per the ObjectFieldGroupSchema contract): * - sections come back in declared-group order; + * - a group that lists `fields` holds those fields in list order (names the + * object does not declare are skipped), then any field whose `Field.group` + * names it that the list leaves out, in field declaration order; a group + * without `fields` holds the fields whose `Field.group` names it, in field + * declaration order (the older spelling, unchanged); + * - un-parsed input that breaks the parse's agreement rules resolves + * first-listing-wins: a field listed by two groups joins the first, and a + * listed field joins the listing group whatever its own `group` says; * - declared groups no visible field references are dropped; * - fields without a (declared) group collect into a trailing untitled * bucket, preserving field declaration order — EXCEPT audit/system @@ -76,7 +85,7 @@ export interface FieldGroupSection { collapse: FieldGroupCollapse; /** Section visibility predicate, passed through verbatim; absent = always visible. Never present on the ungrouped bucket. */ visibleWhen?: FieldGroupVisibleWhen; - /** Member field NAMES in field-declaration order. Renderers resolve defs themselves. */ + /** Member field NAMES in display order (the group's `fields` list first, else field-declaration order). Renderers resolve defs themselves. */ fields: string[]; } @@ -118,7 +127,7 @@ export const FIELD_GROUP_SYSTEM_FIELDS: ReadonlySet = new Set([ type AnyRec = Record; /** Normalize one declared group entry; null for malformed/keyless entries. */ -function readGroup(g: unknown): { key: string; label?: string; icon?: string; description?: string; collapse: FieldGroupCollapse; visibleWhen?: FieldGroupVisibleWhen } | null { +function readGroup(g: unknown): { key: string; label?: string; icon?: string; description?: string; collapse: FieldGroupCollapse; visibleWhen?: FieldGroupVisibleWhen; members?: string[] } | null { if (!g || typeof g !== 'object' || Array.isArray(g)) return null; const grp = g as AnyRec; if (typeof grp.key !== 'string' || grp.key.length === 0) return null; @@ -142,8 +151,14 @@ function readGroup(g: unknown): { key: string; label?: string; icon?: string; de // Deprecated spec flag. collapse = grp.defaultExpanded ? 'expanded' : 'collapsed'; } + // A group's own member list (`fields`). A group placing a related list holds + // no fields (the parse refuses a list there), so a list on one is not read. + const members = Array.isArray(grp.fields) && typeof grp.relatedList !== 'string' + ? grp.fields.filter((n): n is string => typeof n === 'string' && n.length > 0) + : undefined; return { key: grp.key, + ...(members !== undefined ? { members } : {}), label: typeof grp.label === 'string' ? grp.label : undefined, icon: typeof grp.icon === 'string' ? grp.icon : undefined, description: typeof grp.description === 'string' ? grp.description : undefined, @@ -152,6 +167,61 @@ function readGroup(g: unknown): { key: string; label?: string; icon?: string; de }; } +/** Which declared group each field belongs to, and each group's members in display order. */ +export interface FieldGroupMembership { + /** Group key → member field names in display order (hidden fields included). */ + members: Map; + /** Field name → the key of the group it belongs to. A field absent here is ungrouped. */ + groupOf: Map; +} + +function resolveFieldGroupMembership( + declared: ReadonlyArray<{ key: string; members?: string[] }>, + fields: Record, +): FieldGroupMembership { + const members = new Map(); + const groupOf = new Map(); + for (const g of declared) members.set(g.key, []); + // The lists speak first: a listed name joins its first listing group. + for (const g of declared) { + if (!g.members) continue; + for (const name of g.members) { + if (groupOf.has(name) || !Object.prototype.hasOwnProperty.call(fields, name)) continue; + groupOf.set(name, g.key); + members.get(g.key)!.push(name); + } + } + // Then the older spelling, in field declaration order: a field no list names + // joins the group its `group` names — after that group's listed members. + for (const [name, f] of Object.entries(fields)) { + if (groupOf.has(name)) continue; + const g = typeof f?.group === 'string' ? f.group : undefined; + if (g === undefined || !members.has(g)) continue; + groupOf.set(name, g); + members.get(g)!.push(name); + } + return { members, groupOf }; +} + +/** + * Field-group membership of an object definition (or any bare metadata record + * shaped like one): each declared group's members in display order, and the + * group of each member. The same resolution {@link deriveFieldGroupLayout} + * places sections from, before it filters hidden fields and drops empty + * groups, so an editor that shows every field (hidden ones included) agrees + * with the rendered layout on who belongs where and in what order. + */ +export function readFieldGroupMembership(def: unknown): FieldGroupMembership { + const obj = def && typeof def === 'object' && !Array.isArray(def) ? (def as AnyRec) : {}; + const declared = (Array.isArray(obj.fieldGroups) ? obj.fieldGroups : []) + .map(readGroup) + .filter((g): g is NonNullable> => g !== null); + const fields = (obj.fields && typeof obj.fields === 'object' && !Array.isArray(obj.fields)) + ? (obj.fields as Record) + : {}; + return resolveFieldGroupMembership(declared, fields); +} + /** * Derive the grouped layout for an object definition (or any bare metadata * record shaped like one — the helper is deliberately tolerant of @@ -166,24 +236,23 @@ export function deriveFieldGroupLayout(def: unknown): FieldGroupSection[] | null .filter((g): g is NonNullable> => g !== null); if (declared.length === 0) return null; - const declaredKeys = new Set(declared.map((g) => g.key)); const fields = (obj.fields && typeof obj.fields === 'object' && !Array.isArray(obj.fields)) ? (obj.fields as Record) : {}; + const membership = resolveFieldGroupMembership(declared, fields); const buckets = new Map(); for (const g of declared) buckets.set(g.key, []); const ungrouped: string[] = []; let anyGrouped = false; + for (const [key, names] of membership.members) { + const visible = names.filter((name) => fields[name]?.hidden !== true); + buckets.set(key, visible); + if (visible.length > 0) anyGrouped = true; + } for (const [name, f] of Object.entries(fields)) { - if (f?.hidden === true) continue; - const g = typeof f?.group === 'string' && declaredKeys.has(f.group) ? (f.group as string) : null; - if (g) { - buckets.get(g)!.push(name); - anyGrouped = true; - } else if (!FIELD_GROUP_SYSTEM_FIELDS.has(name)) { - ungrouped.push(name); - } + if (f?.hidden === true || membership.groupOf.has(name)) continue; + if (!FIELD_GROUP_SYSTEM_FIELDS.has(name)) ungrouped.push(name); } // No visible field references a declared group → grouping doesn't apply. if (!anyGrouped) return null; diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index ba698ce081b..7c0b55a46f9 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -2762,8 +2762,17 @@ export const FieldSchema = lazySchema(() => { // side of ADR-0049. Do not restore a schema on its own; that middle state is what // both issues were filed about. - /** Layout & Grouping */ - group: z.string().optional().describe('Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system")'), + /** + * Layout & Grouping — the OLDER spelling of field-group membership, still + * read and not scheduled for removal. It names the `key` of one of the + * object's `fieldGroups`; the field joins that group in field declaration + * order. New metadata lists a group's members on the group instead + * (`fieldGroups[].fields`), which also orders them without moving the field. + * When both speak they must agree: a field one group lists may not name + * another group here. A field naming a group that lists `fields` without it + * is placed after the listed members. + */ + group: z.string().optional().describe('Older spelling of field-group membership, still read: the key of one of the object\'s fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones.'), /** * Conditional field rules (CEL predicates over `record`). Evaluated on BOTH diff --git a/packages/spec/src/data/object.zod.ts b/packages/spec/src/data/object.zod.ts index ae4e92315ba..c8799e665b2 100644 --- a/packages/spec/src/data/object.zod.ts +++ b/packages/spec/src/data/object.zod.ts @@ -1274,24 +1274,32 @@ const RELATED_LIST_ENTRY_PATTERN = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)?$/; * related fields together for presentation in forms, detail pages, and * editors (e.g., "Contact Info", "Billing", "System"). * - * Design rules (MVP): + * Design rules: * - Group **order** is the declaration order of this array — no `order` property. - * - Field → group mapping is derived automatically from `Field.group` - * matching `ObjectFieldGroup.key`; the **in-group display order** equals - * the traversal order of `ObjectSchema.fields`. - * - Fields whose `group` is unset (or references an undeclared key) are - * considered ungrouped and must be rendered by consumers in a default - * bucket after the declared groups, preserving their field declaration order. - * - Extension packages and runtime code use `Field.group` to assign fields - * to an existing group — no per-field order property is introduced at this - * layer. - * - * Migration operations supported by this MVP: + * - A group lists its own members, in display order, in `fields`. A group that + * writes no `fields` keeps the older rule: its members are the fields whose + * `Field.group` names its `key`, in the traversal order of + * `ObjectSchema.fields`. So an object written before `fields` existed + * renders exactly as it did. + * - A field whose `group` names a group that lists `fields`, but that the list + * does not name (a field another package added later, say), follows the + * listed members in field declaration order: it is never dropped. + * - Fields no group lists and whose `group` is unset (or references an + * undeclared key) are ungrouped and render in a default bucket after the + * declared groups, preserving their field declaration order. + * - Two spellings of one membership must agree: the object parse refuses a + * field one group lists while its own `group` names another, a field two + * groups list, a name one list repeats, and `fields` on a group that places + * a related list. A listed name the object does not declare is skipped (the + * layout places only declared fields), so removing a field never makes the + * object unparseable. + * + * Migration operations supported: * - add / rename / delete / reorder groups (via the array) - * - assign an existing field to a group (via `Field.group`) - * - * Deferred (not part of MVP): - * - explicit per-field in-group ordering + * - assign a field to a group and order it inside the group (via `fields`; + * `Field.group` is the older spelling, still read) + * + * Deferred: * - nested groups / sub-groups * * Group-level visibility (`visibleWhen`) closed the ADR-0049 enforce-or-remove @@ -1309,8 +1317,8 @@ const RELATED_LIST_ENTRY_PATTERN = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)?$/; * @example * ```ts * fieldGroups: [ - * { key: 'contact_info', label: 'Contact Information', icon: 'user' }, - * { key: 'billing', label: 'Billing', collapse: 'collapsed' }, + * { key: 'contact_info', label: 'Contact Information', icon: 'user', fields: ['email', 'phone'] }, + * { key: 'billing', label: 'Billing', collapse: 'collapsed', fields: ['billing_address'] }, * { key: 'system', label: 'System' }, * ] * ``` @@ -1332,11 +1340,6 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({ // Membership is declared the OTHER WAY ROUND, and this is the single most // likely thing an author reaches for here — a group that lists its fields // is what every other layout system in this space looks like. - fields: - '`fields` does not live on a group — membership is declared on the FIELD, pointing ' + - "back: `fields: { email: { type: 'email', group: 'contact_info' } }`. The group " + - 'declares only its `key`, `label` and presentation; `deriveFieldGroupLayout` ' + - '(ADR-0085 §5) does the assembly.', order: '`order` is not a group key — ARRAY ORDER is display order. `fieldGroups: [...]` ' + 'renders top to bottom, so move the entry rather than numbering it.', @@ -1364,6 +1367,30 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({ /** Human-readable label displayed as the group header. */ label: z.string().describe('Group display label').meta({ title: 'Label' }), + /** + * The group's members, in display order: field names of this object. Written, + * it decides which fields the group shows and in what order, on every surface + * that renders the group (record page, create and edit forms, drawer); the + * object's `fields` declaration order then no longer decides the order inside + * the group, so the group can be reordered without moving any field. + * + * Absent, the group keeps the older rule: its members are the fields whose + * `Field.group` names this group's `key`, in field declaration order. That + * spelling is still read; new metadata lists members here. + * + * A field whose `group` names this group but that this list does not name is + * appended after the listed members, in field declaration order, never + * dropped. The object parse refuses a field this list names while its own + * `group` names another group, a field two groups list, and a name this list + * repeats. A name the object declares no field for is skipped. A group that + * places a related list (`relatedList`) holds no fields, so it may not write + * `fields`. Derivation: `deriveFieldGroupLayout` (field-group-layout.ts, + * ADR-0085 §5). + */ + fields: z.array(z.string().regex(/^[a-z_][a-z0-9_]*$/, { + message: 'A field group\'s fields entry is a field name of this object, in snake_case (e.g. "account")', + })).optional().describe('The group\'s members in display order (field names of this object). Written, it decides which fields the group shows and their order on the record page and the forms, without changing the order of the object\'s fields. Absent, members are the fields whose `group` names this group, in field declaration order (the older spelling, still read). A field whose `group` names this group but that the list does not name follows the listed ones. Refused: a listed field whose own `group` names another group, a field two groups list, a repeated name, and `fields` on a group with `relatedList`. A name the object does not declare is skipped.').meta({ title: 'Fields' }), + /** Optional Lucide/Material icon name for the group header. */ icon: z.string().optional().describe('Icon name (Lucide/Material) for the group header').meta({ title: 'Icon' }), @@ -1378,7 +1405,7 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({ * items can sit under its basic information with its terms after them. * * Such a group carries no fields: a field whose `group` names it is refused - * at parse. Its name is judged exactly as a `relatedLists` entry's is (see + * at parse, and so is a `fields` list on it. Its name is judged exactly as a `relatedLists` entry's is (see * there): a child in the stack with no inbound relationship is refused * everywhere; a child that exists nowhere is refused at `defineStack` (save a * platform-prefixed name, left to the runtime) and by a metadata write that @@ -1396,7 +1423,7 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({ */ relatedList: z.string().regex(RELATED_LIST_ENTRY_PATTERN, { 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', - }).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. 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): 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' }), + }).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): 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' }), /** * [ADR-0085 §5] Section visibility predicate — CEL, the ADR-0089 canonical @@ -3330,6 +3357,81 @@ function refuseFieldsInRelatedListGroups(fieldGroups: unknown, fields: unknown, } } +/** + * A field group's `fields` list and a field's own `group` are two spellings of + * one membership (`ObjectFieldGroupSchema.fields`), so where both speak they + * must agree. One located issue per disagreement: + * + * - `fields` on a group that places a related list (`relatedList`): such a + * group holds no fields — at `['fieldGroups', i, 'fields']`; + * - a name one list repeats — at the repeat; + * - a field two groups list — at the second listing, naming the first group; + * - a listed field whose own `group` names a different group — at the + * listing AND at `['fields', , 'group']`, each naming the other, so + * the author sees both places to fix. + * + * A listed name the object declares no field for is NOT judged: the layout + * skips it, and refusing it would make the object unparseable the moment any + * door removes a field without editing every list. A field whose `group` names + * a listing group the list leaves out is not a conflict either: it is placed + * after the listed members (`deriveFieldGroupLayout`). + * + * Judged in the object's `superRefine` for the reason + * {@link refuseFieldsInRelatedListGroups} gives: only the object holds both the + * groups and the field map. + */ +function refuseFieldGroupMembershipConflicts(fieldGroups: unknown, fields: unknown, ctx: z.RefinementCtx): void { + if (!Array.isArray(fieldGroups)) return; + const fieldMap = fields !== null && typeof fields === 'object' ? (fields as Record) : {}; + const listedIn = new Map(); + fieldGroups.forEach((group: unknown, index: number) => { + if (group === null || typeof group !== 'object') return; + const { key, relatedList, fields: members } = group as { key?: unknown; relatedList?: unknown; fields?: unknown }; + if (!Array.isArray(members) || typeof key !== 'string') return; + if (typeof relatedList === 'string') { + ctx.addIssue({ + code: 'custom', + path: ['fieldGroups', index, 'fields'], + message: + `Field group '${key}' places the related list '${relatedList}' (its \`relatedList\`), so it holds no ` + + 'fields and may not list any. Move these fields into a group of fields beside the table.', + }); + return; + } + const seen = new Set(); + members.forEach((name: unknown, at: number) => { + if (typeof name !== 'string') return; + const path = ['fieldGroups', index, 'fields', at]; + if (seen.has(name)) { + ctx.addIssue({ code: 'custom', path, message: `Field group '${key}' lists the field '${name}' twice. List each field once.` }); + return; + } + seen.add(name); + const first = listedIn.get(name); + if (first !== undefined) { + ctx.addIssue({ + code: 'custom', + path, + message: + `Field '${name}' is listed by two field groups, '${first}' and '${key}'. A field belongs to one group: ` + + 'remove it from one of the two lists.', + }); + return; + } + listedIn.set(name, key); + const field = fieldMap[name]; + const own = field !== null && typeof field === 'object' ? (field as { group?: unknown }).group : undefined; + if (typeof own !== 'string' || own === key) return; + const message = + `Field '${name}' is listed by the field group '${key}' (its \`fields\`), but its own \`group\` names ` + + `'${own}'. The two say different things: keep the field in '${key}'s list and drop its \`group\` ` + + `(the list is the current spelling), or remove it from the list.`; + ctx.addIssue({ code: 'custom', path, message }); + ctx.addIssue({ code: 'custom', path: ['fields', name, 'group'], message }); + }); + }); +} + /** * [ADR-0055 §1 · #23100, maintainer ruling B] A `controlled_by_parent` object * derives its master from EXACTLY ONE `master_detail` field declared @@ -4956,6 +5058,9 @@ const ObjectSchemaBase = strictObject( // [#27069] A field group carrying `relatedList` is a body table: no field // joins it. See the helper's docblock. refuseFieldsInRelatedListGroups(object.fieldGroups, object.fields, ctx); + // A group's `fields` list and a field's own `group` agree where both speak. + // See the helper's docblock. + refuseFieldGroupMembershipConflicts(object.fieldGroups, object.fields, ctx); // [ADR-0055 §1 · #23100 ruling B, as amended by #30905 ruling A] Exactly one // master `master_detail` under `controlled_by_parent` (the required one, or // the only one declared `required: false`) — the one master relation the From 865063c9edef9b25e06f4534e17d4b924c91e399 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:44:27 +0000 Subject: [PATCH 02/10] feat(lint): field groups judged by the membership the layout resolves; warn on a listed name no field declares Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- packages/lint/src/index.ts | 1 + .../lint/src/validate-semantic-roles.test.ts | 43 +++++++++++++++++++ packages/lint/src/validate-semantic-roles.ts | 41 +++++++++++++++--- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index a3fe2cacbae..d047b460b8e 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -276,6 +276,7 @@ export { FIELD_GROUP_UNDECLARED, FIELD_GROUP_EMPTY, FIELD_GROUP_SHADOWED, + FIELD_GROUP_MEMBER_UNKNOWN, SEMANTIC_ROLE_FIELD_UNKNOWN, SEMANTIC_ROLE_FIELD_UNPROVISIONED, } from './validate-semantic-roles.js'; diff --git a/packages/lint/src/validate-semantic-roles.test.ts b/packages/lint/src/validate-semantic-roles.test.ts index 3684fd102d4..d9daf70746d 100644 --- a/packages/lint/src/validate-semantic-roles.test.ts +++ b/packages/lint/src/validate-semantic-roles.test.ts @@ -6,6 +6,7 @@ import { FIELD_GROUP_UNDECLARED, FIELD_GROUP_EMPTY, FIELD_GROUP_SHADOWED, + FIELD_GROUP_MEMBER_UNKNOWN, SEMANTIC_ROLE_FIELD_UNKNOWN, SEMANTIC_ROLE_FIELD_UNPROVISIONED, } from './validate-semantic-roles'; @@ -314,6 +315,48 @@ describe('validateSemanticRoles (ADR-0085)', () => { // derivation the registry's `applySystemFields` consumes, so the warning is // still correct wherever the column really is absent. // --------------------------------------------------------------------------- +describe('validateSemanticRoles — a group that lists its own fields', () => { + it('counts a listing group as referenced, and judges rule (d) on its listed members', () => { + const clean = validateSemanticRoles(stack([{ + name: 'quote', + highlightFields: ['name'], + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['code', 'name'] }], + fields: { name: { type: 'text' }, code: { type: 'text' } }, + }])); + expect(clean, JSON.stringify(clean)).toEqual([]); + const shadowed = validateSemanticRoles(stack([{ + name: 'quote', + highlightFields: ['name', 'code'], + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['code', 'name'] }], + fields: { name: { type: 'text' }, code: { type: 'text' } }, + }])); + expect(shadowed.map((f) => f.rule)).toEqual([FIELD_GROUP_SHADOWED]); + }); + + it('warns on a listed name the object does not declare, at its list position', () => { + const findings = validateSemanticRoles(stack([{ + name: 'quote', + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['code', 'acount'] }], + fields: { code: { type: 'text' }, account: { type: 'text' } }, + }])); + expect(findings).toEqual([expect.objectContaining({ + severity: 'warning', + rule: FIELD_GROUP_MEMBER_UNKNOWN, + path: 'objects[0].fieldGroups[0].fields[1]', + })]); + expect(findings[0].message).toContain('"acount"'); + }); + + it('a list that names only missing fields leaves the group empty (rule b), beside rule (e)', () => { + const findings = validateSemanticRoles(stack([{ + name: 'quote', + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['code'] }, { key: 'ghost', label: 'Ghost', fields: ['gone'] }], + fields: { code: { type: 'text' } }, + }])); + expect(findings.map((f) => f.rule).sort()).toEqual([FIELD_GROUP_EMPTY, FIELD_GROUP_MEMBER_UNKNOWN].sort()); + }); +}); + describe('validateSemanticRoles — injected system columns (#5378)', () => { // The issue's acceptance criterion #2, verbatim. it('does not warn on highlightFields: [owner_id] for an injection-only object', () => { diff --git a/packages/lint/src/validate-semantic-roles.ts b/packages/lint/src/validate-semantic-roles.ts index 2b06ef801d7..3d4d1586407 100644 --- a/packages/lint/src/validate-semantic-roles.ts +++ b/packages/lint/src/validate-semantic-roles.ts @@ -29,12 +29,14 @@ */ import { RECORD_HIGHLIGHTS_MAX } from '@objectstack/spec/ui'; +import { readFieldGroupMembership } from '@objectstack/spec/data'; import { injectedColumnsFor, unprovisionedInjectedColumnsFor } from './system-fields.js'; import { recordsOf } from './object-graph.js'; export const FIELD_GROUP_UNDECLARED = 'field-group-undeclared'; export const FIELD_GROUP_EMPTY = 'field-group-empty'; export const FIELD_GROUP_SHADOWED = 'field-group-shadowed'; +export const FIELD_GROUP_MEMBER_UNKNOWN = 'field-group-member-unknown'; export const SEMANTIC_ROLE_FIELD_UNKNOWN = 'semantic-role-field-unknown'; export const SEMANTIC_ROLE_FIELD_UNPROVISIONED = 'semantic-role-field-unprovisioned'; @@ -138,11 +140,39 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { .map((g) => g.key) .filter((k): k is string => typeof k === 'string' && k.length > 0), ); - const referencedGroups = new Set(); + // Membership as the layout resolves it: a group's own `fields` list first, + // else the older `Field.group` (`readFieldGroupMembership`, the same + // resolution `deriveFieldGroupLayout` places sections from). + const membership = readFieldGroupMembership(obj); + const referencedGroups = new Set( + [...membership.members].filter(([, names]) => names.length > 0).map(([key]) => key), + ); + // ── (e) a group's `fields` list names a field the object does not declare ── + // The parse skips such a name (removing a field must not make the object + // unparseable), so the layout places nothing for it: almost always a typo + // or a field removed without editing the list. + (Array.isArray(obj.fieldGroups) ? obj.fieldGroups : []).forEach((g: unknown, gi: number) => { + if (!g || typeof g !== 'object') return; + const grp = g as AnyRec; + if (!Array.isArray(grp.fields) || typeof grp.relatedList === 'string') return; + grp.fields.forEach((name: unknown, fi: number) => { + if (typeof name !== 'string' || Object.prototype.hasOwnProperty.call(fields, name)) return; + findings.push({ + severity: 'warning', + rule: FIELD_GROUP_MEMBER_UNKNOWN, + where, + path: `${path}.fieldGroups[${gi}].fields[${fi}]`, + message: + `${objName}: field group "${String(grp.key)}" lists "${name}", which is not a field on this ` + + `object — the group places nothing for it`, + hint: + `Fix the name to one of ${objName}'s fields, or remove it from the group's fields list.`, + }); + }); + }); for (const [fname, f] of Object.entries(fields)) { const g = f?.group; if (typeof g !== 'string' || g.length === 0) continue; - referencedGroups.add(g); if (!declaredGroups.has(g)) { findings.push({ severity: 'warning', @@ -172,7 +202,7 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { `${objName}: fieldGroups declares "${key}" but no field references it — ` + `the group never renders`, hint: - `Assign at least one field via group: '${key}', or remove the unused ` + + `List at least one field in its fields (fields: ['…']), or remove the unused ` + `group declaration.`, }); } @@ -251,9 +281,8 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { for (const key of declaredGroups) { if (relatedListGroups.has(key)) continue; - const members = Object.entries(fields) - .filter(([, f]) => f?.group === key && f?.hidden !== true) - .map(([fname]) => fname); + const members = (membership.members.get(key) ?? []) + .filter((fname) => fields[fname]?.hidden !== true); if (members.length === 0) continue; // rule (b) already covers empty groups if (!members.every((m) => hiddenFromBody.has(m))) continue; findings.push({ From 8f6f6dcde7e5c0ade79251f821b46f41dfb639dc Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:49:31 +0000 Subject: [PATCH 03/10] feat(studio): moving a field in or between field groups writes the groups' fields lists, not the object's field order Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- packages/spec/authorable-surface/data.json | 1 + .../inspectors/ObjectFieldInspector.tsx | 31 +++- .../previews/ObjectFormCanvas.tsx | 154 +++++++++--------- .../previews/object-fields-io.ts | 151 +++++++++++++++-- .../studio-design/ObjectFormDesigner.tsx | 67 ++++---- .../studio-design/ObjectGroupInspector.tsx | 12 +- 6 files changed, 287 insertions(+), 129 deletions(-) diff --git a/packages/spec/authorable-surface/data.json b/packages/spec/authorable-surface/data.json index 374825b2b36..9333ae32078 100644 --- a/packages/spec/authorable-surface/data.json +++ b/packages/spec/authorable-surface/data.json @@ -753,6 +753,7 @@ "data/ObjectFieldGroup:collapsible", "data/ObjectFieldGroup:defaultExpanded", "data/ObjectFieldGroup:description", + "data/ObjectFieldGroup:fields", "data/ObjectFieldGroup:icon", "data/ObjectFieldGroup:key", "data/ObjectFieldGroup:label", diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx index 80b3157e849..a470a52a04f 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx @@ -123,6 +123,10 @@ import { toFieldNameLoose, toFieldNameOrEmpty, indexOfField, + readGroups, + groupMembership, + currentGroupLayout, + writeGroupLayout, type FieldsView, type FieldEntry, } from '../previews/object-fields-io.js'; @@ -1081,6 +1085,29 @@ export function ObjectFieldInspector({ onPatch({ fields: writeFields(next) }); }; + /** + * Move this field to another group (or out of every group). Where no list + * is involved — the field is listed nowhere and the target lists nothing — + * the older `group` key is all there is to write, as before. Otherwise the + * move goes through `writeGroupLayout`, which keeps a group's `fields` list + * and the field's own `group` from contradicting each other + * (objectstack#35900): the field joins the end of the target group. + */ + const moveToGroup = (target: string | null) => { + const groups = readGroups(fieldGroups); + const listsIt = groups.some((g) => Array.isArray(g.fields) && g.fields.includes(entry.name)); + const targetLists = target !== null && groups.some((g) => g.key === target && Array.isArray(g.fields)); + if (!listsIt && !targetLists) { + patchDef({ group: target ?? undefined }); + return; + } + const layout = currentGroupLayout(view, groups); + for (const [key, names] of layout) layout.set(key, names.filter((n) => n !== entry.name)); + layout.set(target, [...(layout.get(target) ?? []), entry.name]); + const patch = writeGroupLayout(view, groups, layout); + if (patch.fields !== undefined || patch.fieldGroups !== undefined) onPatch(patch); + }; + const patchDef = (patch: Record) => { const nextEntries = [...view.entries]; nextEntries[idx] = { ...entry, def: { ...def, ...patch } }; @@ -2094,14 +2121,14 @@ export function ObjectFieldInspector({ typeof g.key === 'string') .map((g) => ({ value: g.key as string, label: String(g.label ?? g.key) })), ]} - onCommit={(v) => patchDef({ group: v || undefined })} + onCommit={(v) => moveToGroup(v || null)} disabled={locked} /> diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/ObjectFormCanvas.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/ObjectFormCanvas.tsx index 9c6ccb3c455..b986fe17e5d 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/ObjectFormCanvas.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/ObjectFormCanvas.tsx @@ -57,6 +57,8 @@ import { removeGroup, moveGroup, clearFieldGroup, + currentGroupLayout, + writeGroupLayout, diffFields, type FieldEntry, type ObjectFieldGroup, @@ -81,6 +83,12 @@ import { import { t, tFormat } from '../i18n.js'; import { DisabledControlReason } from '../inspectors/_shared.js'; +/** The container (group key, or `null` for ungrouped) holding `name` in a layout. */ +function containerOf(layout: Map, name: string): string | null | undefined { + for (const [key, names] of layout) if (names.includes(name)) return key; + return undefined; +} + /* ─── locale helpers ─── */ // Both resolve through the Studio catalog now. They used to read a `labelZh` // column on FIELD_TYPE_META behind an `isZh` check, which meant the picker @@ -270,25 +278,27 @@ export function ObjectFormCanvas({ name = `${base}_${i}`; } const entry = newField(name, type); - if (groupKey) entry.def = { ...entry.def, group: groupKey }; - // Insert at the end of the target group's run so it lands in-section, - // otherwise append to the very end (ungrouped / no groups). - let insertAt = view.entries.length; - if (groupKey) { - for (let j = view.entries.length - 1; j >= 0; j -= 1) { - if (view.entries[j].def.group === groupKey) { insertAt = j + 1; break; } - } - } - const entries = view.entries.slice(); - entries.splice(insertAt, 0, entry); - onPatch({ fields: writeFields({ shape: view.shape, entries }) }); + // A new field is declared last. In a group that lists its members + // (`fieldGroups[].fields`) it joins the end of that list; in one that + // does not, its `group` puts it at the end of the group's run either way + // (objectstack#35900). + const target = groupKey ? declaredGroups.find((g) => g.key === groupKey) : undefined; + const listed = target !== undefined && Array.isArray(target.fields); + if (groupKey && !listed) entry.def = { ...entry.def, group: groupKey }; + const entries = [...view.entries, entry]; + onPatch({ + fields: writeFields({ shape: view.shape, entries }), + ...(listed + ? { fieldGroups: declaredGroups.map((g) => (g.key === groupKey ? { ...g, fields: [...(g.fields ?? []), name] } : g)) } + : {}), + }); onSelectionChange?.({ kind: 'field', id: name, label: String(entry.def.label ?? name), }); }, - [onPatch, onSelectionChange, view], + [onPatch, onSelectionChange, view, declaredGroups], ); /* ─── Section (field group) operations ─── */ @@ -335,90 +345,76 @@ export function ObjectFormCanvas({ [onPatch, declaredGroups], ); + // Every move below edits the grouped layout and writes it back through + // `writeGroupLayout`: membership and in-group order live on the group's + // `fields` list, so a move never reorders the object's fields except inside + // the ungrouped bucket, which has no list (objectstack#35900). + const applyLayout = React.useCallback( + (edit: (layout: Map) => boolean) => { + if (!onPatch) return; + const layout = currentGroupLayout(view, declaredGroups); + if (!edit(layout)) return; + const patch = writeGroupLayout(view, declaredGroups, layout); + if (patch.fields !== undefined || patch.fieldGroups !== undefined) onPatch(patch); + }, + [onPatch, view, declaredGroups], + ); // Reorder fields by moving `fromName` to the position of `toName`. // Uses native HTML5 DnD — no library, no animations, just a working // reorder for the most common designer interaction. // If `toName`'s field is in a different group than the dragged field, - // adopt that group so cross-group drops are intuitive. + // it joins that group so cross-group drops are intuitive. const reorderField = React.useCallback( (fromName: string, toName: string, position: 'before' | 'after') => { - if (!onPatch) return; if (fromName === toName) return; - const entries = view.entries.slice(); - const fromIdx = entries.findIndex((e) => e.name === fromName); - if (fromIdx < 0) return; - const [moved] = entries.splice(fromIdx, 1); - const toIdx = entries.findIndex((e) => e.name === toName); - const targetEntry = toIdx >= 0 ? entries[toIdx] : undefined; - if (targetEntry) { - const targetGroup = typeof targetEntry.def.group === 'string' ? targetEntry.def.group : undefined; - const fromGroup = typeof moved.def.group === 'string' ? moved.def.group : undefined; - if (targetGroup !== fromGroup) { - moved.def = { ...moved.def, group: targetGroup }; - } - } - if (toIdx < 0) { - entries.push(moved); - } else { - entries.splice(position === 'before' ? toIdx : toIdx + 1, 0, moved); - } - onPatch({ fields: writeFields({ shape: view.shape, entries }) }); + applyLayout((layout) => { + const from = containerOf(layout, fromName); + const to = containerOf(layout, toName); + if (from === undefined || to === undefined) return false; + layout.set(from, layout.get(from)!.filter((n) => n !== fromName)); + const target = layout.get(to)!.slice(); + const at = target.indexOf(toName); + target.splice(position === 'before' ? at : at + 1, 0, fromName); + layout.set(to, target); + return true; + }); }, - [onPatch, view], + [applyLayout], ); - // Keyboard reorder (Alt+↑/↓): swap a field with its nearest neighbour - // in the SAME group so a focused row moves predictably within its - // section without ever changing groups. + // Keyboard reorder (Alt+↑/↓): swap a field with its neighbour in the SAME + // group so a focused row moves predictably within its section without ever + // changing groups. const moveFieldByOffset = React.useCallback( (name: string, dir: -1 | 1) => { - if (!onPatch) return; - const entries = view.entries.slice(); - const idx = entries.findIndex((e) => e.name === name); - if (idx < 0) return; - const grp = typeof entries[idx].def.group === 'string' ? entries[idx].def.group : null; - let j = idx + dir; - while (j >= 0 && j < entries.length) { - const g = typeof entries[j].def.group === 'string' ? entries[j].def.group : null; - if (g === grp) break; - j += dir; - } - if (j < 0 || j >= entries.length) return; - const tmp = entries[idx]; - entries[idx] = entries[j]; - entries[j] = tmp; - onPatch({ fields: writeFields({ shape: view.shape, entries }) }); + applyLayout((layout) => { + const key = containerOf(layout, name); + if (key === undefined) return false; + const names = layout.get(key)!.slice(); + const idx = names.indexOf(name); + const j = idx + dir; + if (j < 0 || j >= names.length) return false; + [names[idx], names[j]] = [names[j], names[idx]]; + layout.set(key, names); + return true; + }); }, - [onPatch, view], + [applyLayout], ); - // Drop a field into a group section's empty space (or onto its header). - // Reassigns Field.group and moves the entry to the end of that group's - // run in the source order so it visually lands where it was dropped. + // Drop a field into a group section's empty space (or onto its header): it + // joins that group, after its current members. const moveToGroup = React.useCallback( (fromName: string, groupKey: string | null) => { - if (!onPatch) return; - const entries = view.entries.slice(); - const fromIdx = entries.findIndex((e) => e.name === fromName); - if (fromIdx < 0) return; - const [moved] = entries.splice(fromIdx, 1); - const currentGroup = typeof moved.def.group === 'string' ? moved.def.group : null; - if (currentGroup === groupKey) { - // No group change — re-insert at original position (effectively no-op). - entries.splice(fromIdx, 0, moved); - return; - } - moved.def = { ...moved.def, group: groupKey ?? undefined }; - // Find end of target group's run; if no members, append at end. - let insertAt = entries.length; - for (let i = entries.length - 1; i >= 0; i -= 1) { - const g = typeof entries[i].def.group === 'string' ? entries[i].def.group : null; - if (g === groupKey) { insertAt = i + 1; break; } - } - entries.splice(insertAt, 0, moved); - onPatch({ fields: writeFields({ shape: view.shape, entries }) }); + applyLayout((layout) => { + const from = containerOf(layout, fromName); + if (from === undefined || from === groupKey || !layout.has(groupKey)) return false; + layout.set(from, layout.get(from)!.filter((n) => n !== fromName)); + layout.set(groupKey, [...layout.get(groupKey)!, fromName]); + return true; + }); }, - [onPatch, view], + [applyLayout], ); // Inline label rename — used by double-click on the field card label. diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts b/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts index 830296834bc..451fc12f141 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts @@ -324,8 +324,9 @@ export function toFieldNameLoose(raw: string): string { /** * A declared field group (a.k.a. "section"). Lives at the object's top level as - * `draft.fieldGroups`; individual fields opt into a group via - * `Field.group === ObjectFieldGroup.key`. + * `draft.fieldGroups`; a group lists its members in display order in its own + * `fields`, or else fields opt into it via the older + * `Field.group === ObjectFieldGroup.key` (see {@link groupMembership}). * * Named `ObjectFieldGroup`, which is the spec's own name for this shape * (`@objectstack/spec/data`, the `ObjectFieldGroupSchema` family), and @@ -359,7 +360,128 @@ export function toFieldNameLoose(raw: string): string { export type ObjectFieldGroup = z.input; import type { z } from 'zod'; -import type { ObjectFieldGroupSchema } from '@objectstack/spec/data'; +import { readFieldGroupMembership, type FieldGroupMembership, type ObjectFieldGroupSchema } from '@objectstack/spec/data'; + +/** + * Who belongs to which declared group, in display order — the spec's own + * resolution (`readFieldGroupMembership`, the one `deriveFieldGroupLayout` + * places sections from): a group's `fields` list first, then fields whose + * older `group` names it. Every editor here reads membership through this, so + * the designer and the rendered record page agree. + */ +export function groupMembership(view: FieldsView, fieldGroups: unknown): FieldGroupMembership { + return readFieldGroupMembership({ fieldGroups, fields: viewFieldMap(view) }); +} + +function viewFieldMap(view: FieldsView): Record> { + // `Object.fromEntries` defines own properties, so a `__proto__` name stays a + // plain key (objectui#9237). + return Object.fromEntries(view.entries.map((e) => [e.name, e.def])); +} + +/** + * Write a new grouped layout back to the draft, the way `fieldGroups[].fields` + * intends: membership and in-group order live on the GROUP, so moving a field + * inside or between groups changes those groups' `fields` lists and never the + * object's field declaration order. + * + * `layout` maps each container to the field names it now shows, in order: a + * declared group key, or `null` for the trailing ungrouped bucket. Fields the + * caller does not show (system / kept-off-layout ones) are absent from it and + * keep their membership: a group's list keeps them after the shown members. + * + * - A group whose shown members (set and order) did not change is left exactly + * as it was, list or no list. + * - A group that changed gets a `fields` list (written even when it had none, + * because the older spelling cannot hold an order). + * - A field that moved: its own `group` is dropped when it would contradict + * the list it now sits in, or when it moved to the ungrouped bucket. + * - The ungrouped bucket has no list to hold an order, so reordering it + * permutes the ungrouped fields among the declaration slots they already + * occupy; no grouped field moves. A caller whose bucket order is not plain + * declaration order (one that pins fields first) passes + * `reorderUngrouped: false` when the bucket's order did not change. + * + * Returns only the keys that changed (`{}` = nothing to write). + */ +export function writeGroupLayout( + view: FieldsView, + groups: ObjectFieldGroup[], + layout: ReadonlyMap, + opts?: { reorderUngrouped?: boolean }, +): { fields?: ReturnType; fieldGroups?: ObjectFieldGroup[] } { + const membership = groupMembership(view, groups); + const shown = new Set(); + for (const names of layout.values()) for (const n of names) shown.add(n); + const containerOf = new Map(); + for (const [key, names] of layout) for (const n of names) containerOf.set(n, key); + + let groupsChanged = false; + const nextGroups = groups.map((g) => { + if (!layout.has(g.key)) return g; + const current = membership.members.get(g.key) ?? []; + const before = current.filter((n) => shown.has(n)); + const after = layout.get(g.key)!; + if (before.length === after.length && before.every((n, i) => n === after[i])) return g; + groupsChanged = true; + const keptOff = current.filter((n) => !shown.has(n)); + return { ...g, fields: [...after, ...keptOff] } as ObjectFieldGroup; + }); + + let fieldsChanged = false; + let entries = view.entries.map((e) => { + if (!containerOf.has(e.name)) return e; + const target = containerOf.get(e.name) ?? null; + const own = typeof e.def.group === 'string' ? e.def.group : undefined; + if (own === undefined || own === target) return e; + // In a group under another key: that group holds the field by its list, + // which the older `group` would contradict. Moved to the ungrouped bucket + // out of a group: `group` would pull it back. (A `group` naming no declared + // group on a field that stays ungrouped says nothing and is kept.) + if (target === null && !membership.groupOf.has(e.name)) return e; + fieldsChanged = true; + const def = { ...e.def }; + delete def.group; + return { name: e.name, def }; + }); + + const ungroupedOrder = opts?.reorderUngrouped === false ? undefined : layout.get(null); + if (ungroupedOrder) { + const slots: number[] = []; + entries.forEach((e, i) => { if (containerOf.get(e.name) === null) slots.push(i); }); + const inOrder = ungroupedOrder.filter((n) => containerOf.get(n) === null); + if (slots.some((slot, i) => entries[slot].name !== inOrder[i])) { + const byName = new Map(entries.map((e) => [e.name, e])); + const next = entries.slice(); + slots.forEach((slot, i) => { next[slot] = byName.get(inOrder[i])!; }); + entries = next; + fieldsChanged = true; + } + } + + return { + ...(fieldsChanged ? { fields: writeFields({ shape: view.shape, entries }) } : {}), + ...(groupsChanged ? { fieldGroups: nextGroups } : {}), + }; +} + +/** + * The current grouped layout as {@link writeGroupLayout} takes it: every + * declared group's members and the ungrouped bucket, in display order, over the + * fields `isShown` admits (all of them by default). + */ +export function currentGroupLayout( + view: FieldsView, + groups: ObjectFieldGroup[], + isShown: (entry: FieldEntry) => boolean = () => true, +): Map { + const membership = groupMembership(view, groups); + const shownNames = new Set(view.entries.filter(isShown).map((e) => e.name)); + const layout = new Map(); + for (const g of groups) layout.set(g.key, (membership.members.get(g.key) ?? []).filter((n) => shownNames.has(n))); + layout.set(null, view.entries.filter((e) => shownNames.has(e.name) && !membership.groupOf.has(e.name)).map((e) => e.name)); + return layout; +} /** * Read `draft.fieldGroups` into a normalized, well-typed list. Unknown/extra @@ -461,9 +583,9 @@ export function moveArray(arr: T[], from: number, to: number): T[] { } /** - * Group entries by their `group` property, in `fieldGroups[]` order. - * Fields with no group (or a group not declared in fieldGroups) land - * in a trailing "Ungrouped" bucket. + * Group entries by membership ({@link groupMembership}), in `fieldGroups[]` + * order, members in display order. Fields no group holds land in a trailing + * "Ungrouped" bucket. * * By default empty *declared* groups are dropped to avoid chrome noise * (read-only / preview). Pass `includeEmptyDeclared` while editing so a @@ -485,15 +607,16 @@ export function groupEntries( for (const g of declared) { buckets.set(g.key!, { key: g.key!, label: String(g.label ?? g.key), entries: [] }); } - const declaredKeys = new Set(declared.map((g) => g.key as string)); + const membership = groupMembership(view, declared); + const byName = new Map(view.entries.map((e) => [e.name, e])); + for (const [key, names] of membership.members) { + const bucket = buckets.get(key); + if (bucket) bucket.entries = names.map((n) => byName.get(n)!).filter(Boolean); + } for (const e of view.entries) { - const g = typeof e.def.group === 'string' ? (e.def.group as string) : null; - if (g && declaredKeys.has(g)) { - buckets.get(g)!.entries.push(e); - } else { - if (!buckets.has(null)) buckets.set(null, { key: null, label: 'Ungrouped', entries: [] }); - buckets.get(null)!.entries.push(e); - } + if (membership.groupOf.has(e.name)) continue; + if (!buckets.has(null)) buckets.set(null, { key: null, label: 'Ungrouped', entries: [] }); + buckets.get(null)!.entries.push(e); } const includeEmpty = !!opts?.includeEmptyDeclared; // Drop empty declared buckets unless asked to keep them (edit mode). diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx index a1bf5631253..9a2dd035cbe 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx @@ -58,8 +58,9 @@ import { removeGroup, moveGroup, clearFieldGroup, + groupMembership, + writeGroupLayout, type FieldEntry, - type FieldsView, } from '../metadata-admin/previews/object-fields-io.js'; import { useSafeFieldLabel } from '@object-ui/i18n'; import { t, tFormat, useMetadataLocale } from '../metadata-admin/i18n.js'; @@ -885,13 +886,10 @@ export function ObjectFormDesigner({ () => view.entries.filter((e) => !isKeptOffLayout(e, systemFieldNames)).map((e) => e.name), [view.entries, systemFieldNames], ); - const groupOf = React.useCallback( - (name: string) => { - const g = entryByName.get(name)?.def.group; - return typeof g === 'string' ? g : undefined; - }, - [entryByName], - ); + // Membership as the record page resolves it: a group's own `fields` list, + // else the field's older `group` (objectstack#35900). + const membership = React.useMemo(() => groupMembership(view, fieldGroups), [view, fieldGroups]); + const groupOf = React.useCallback((name: string) => membership.groupOf.get(name), [membership]); const derived = React.useMemo(() => { const map: Record = {}; for (const c of containerOrder) map[c] = []; @@ -906,14 +904,19 @@ export function ObjectFormDesigner({ map[cid(UNGROUPED)] = shownFields.filter((n) => !placed.has(n)).map(fid); return map; } - for (const e of view.entries) { - if (isKeptOffLayout(e, systemFieldNames)) continue; - const g = typeof e.def.group === 'string' ? e.def.group : ''; - const target = g && map[cid(g)] ? cid(g) : cid(UNGROUPED); - map[target].push(fid(e.name)); + // Each group's members in display order (its `fields` list first), then + // the ungrouped bucket in field declaration order. + const shown = new Set(shownFields); + for (const [key, names] of membership.members) { + if (!map[cid(key)]) continue; + map[cid(key)] = names.filter((n) => shown.has(n)).map(fid); } + map[cid(UNGROUPED)] = shownFields.filter((n) => { + const g = membership.groupOf.get(n); + return g === undefined || !map[cid(g)]; + }).map(fid); return settlePinned(map, pinRank); - }, [view.entries, containerOrder, systemFieldNames, pinRank, formSections, shownFields, groupOf]); + }, [containerOrder, pinRank, formSections, shownFields, groupOf, membership]); const [items, setItems] = React.useState>(derived); const [activeId, setActiveId] = React.useState(null); @@ -982,7 +985,12 @@ export function ObjectFormDesigner({ [items], ); - /** Flatten the container map back to `fields` (stamping group + order) and persist. */ + /** + * Persist the container map. On the object's own groups the layout is + * written where `fieldGroups[].fields` keeps it: each changed group's list, + * never the object's field declaration order (objectstack#35900) — + * `writeGroupLayout` says exactly what moves. + */ const commit = React.useCallback( (next: Record) => { if (formSections && onSectionsChange) { @@ -993,29 +1001,28 @@ export function ObjectFormDesigner({ onSectionsChange(writeFormSectionLayout(formSections, layout, shownFields, fieldGroups, groupOf)); return; } - const editable: FieldEntry[] = []; + // Every field the canvas does not show is absent from the layout and + // keeps its place — the same test that kept it off the containers + // (objectui#11780). + const layout = new Map(); for (const c of containerOrder) { const groupKey = unCid(c); - for (const id of next[c] ?? []) { - const e = entryByName.get(unFid(id)); - if (!e) continue; - const def = { ...e.def }; - if (groupKey === UNGROUPED) delete def.group; - else def.group = groupKey; - editable.push({ name: e.name, def }); - } + layout.set(groupKey === UNGROUPED ? null : groupKey, (next[c] ?? []).map(unFid).filter((n) => entryByName.has(n))); } - // Every field the canvas does not show rides back unchanged — the same - // test that kept it off the containers (objectui#11780). - const system = view.entries.filter((e) => isKeptOffLayout(e, systemFieldNames)); - const finalView: FieldsView = { shape: view.shape, entries: [...system, ...editable] }; - onChange({ fields: writeFields(finalView) }); + // The bucket is drawn pinned-first (`settlePinned`), not in declaration + // order: unless the drag changed it, its order is not the author's to write. + const bucket = cid(UNGROUPED); + const was = derived[bucket] ?? []; + const now = next[bucket] ?? []; + const reorderUngrouped = was.length !== now.length || was.some((id, i) => id !== now[i]); + const patch = writeGroupLayout(view, fieldGroups, layout, { reorderUngrouped }); + if (patch.fields !== undefined || patch.fieldGroups !== undefined) onChange(patch); }, [ containerOrder, entryByName, view, - systemFieldNames, + derived, onChange, formSections, onSectionsChange, diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectGroupInspector.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectGroupInspector.tsx index b459954447a..cd50a51b38b 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectGroupInspector.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectGroupInspector.tsx @@ -24,7 +24,7 @@ import { InspectorSelectField, InspectorEmptyState, } from '../metadata-admin/inspectors/_shared.js'; -import { readFields, readGroups, updateGroup } from '../metadata-admin/previews/object-fields-io.js'; +import { groupMembership, readFields, readGroups, updateGroup } from '../metadata-admin/previews/object-fields-io.js'; import { t, tFormat } from '../metadata-admin/i18n.js'; import { acceptRelatedListEntries, @@ -67,8 +67,9 @@ export function ObjectGroupInspector({ const parentName = objectName || (typeof draft.name === 'string' ? draft.name : ''); const { relationships, ready } = useRelatedListCatalog(parentName, draft); const memberCount = React.useMemo( - () => readFields(draft.fields).entries.filter((e) => e.def.group === groupKey).length, - [draft.fields, groupKey], + // A group's own `fields` list, else the older `Field.group` (objectstack#35900). + () => groupMembership(readFields(draft.fields), draft.fieldGroups).members.get(groupKey)?.length ?? 0, + [draft.fields, draft.fieldGroups, groupKey], ); if (!group) { @@ -223,7 +224,10 @@ function RelatedTablePlacement({ // table rule a group's entry answers to. if (blockedByFields || acceptRelatedListEntries([v], relationships).length === 0) return; if (!namesBodyTablesOnly(v)) return; - onPatch({ fieldGroups: updateGroup(groups, group.key, { relatedList: v }) }); + // A group placing a table holds no fields, so a `fields` list naming none + // of the object's fields (the only kind left once the check above passed) + // goes with the change (objectstack#35900). + onPatch({ fieldGroups: updateGroup(groups, group.key, { relatedList: v, fields: undefined }) }); }; return (
From b9624926b76afeef036cdf0a3afbbac3a0b9b7f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:58:36 +0000 Subject: [PATCH 04/10] test(studio): designer drag pins read the layout the draft resolves to; a reorder writes only the group's fields list Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .../lint/src/validate-semantic-roles.test.ts | 9 ++ packages/lint/src/validate-semantic-roles.ts | 11 ++- .../previews/object-fields-io.test.ts | 87 +++++++++++++++++++ .../previews/object-fields-io.ts | 2 +- ...rmDesigner.dndAnnouncements-11802.test.tsx | 28 +++++- ...ctFormDesigner.keyboardDrop-11871.test.tsx | 63 ++++++++++++-- ...ctFormDesigner.keyboardGrid-11898.test.tsx | 38 ++++++-- ...ctFormDesigner.pinnedFields-27516.test.tsx | 32 ++++--- 8 files changed, 237 insertions(+), 33 deletions(-) diff --git a/packages/lint/src/validate-semantic-roles.test.ts b/packages/lint/src/validate-semantic-roles.test.ts index d9daf70746d..20f2834ee65 100644 --- a/packages/lint/src/validate-semantic-roles.test.ts +++ b/packages/lint/src/validate-semantic-roles.test.ts @@ -347,6 +347,15 @@ describe('validateSemanticRoles — a group that lists its own fields', () => { expect(findings[0].message).toContain('"acount"'); }); + it('a listed injected system column is a field: no warning for owner_id', () => { + const findings = validateSemanticRoles(stack([{ + name: 'quote', + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['owner_id', 'code'] }], + fields: { code: { type: 'text' } }, + }])); + expect(findings.filter((f) => f.rule === FIELD_GROUP_MEMBER_UNKNOWN)).toEqual([]); + }); + it('a list that names only missing fields leaves the group empty (rule b), beside rule (e)', () => { const findings = validateSemanticRoles(stack([{ name: 'quote', diff --git a/packages/lint/src/validate-semantic-roles.ts b/packages/lint/src/validate-semantic-roles.ts index 3d4d1586407..4251797eabc 100644 --- a/packages/lint/src/validate-semantic-roles.ts +++ b/packages/lint/src/validate-semantic-roles.ts @@ -143,7 +143,12 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { // Membership as the layout resolves it: a group's own `fields` list first, // else the older `Field.group` (`readFieldGroupMembership`, the same // resolution `deriveFieldGroupLayout` places sections from). - const membership = readFieldGroupMembership(obj); + // Injected columns count as fields a list may name (they exist at render + // time); declared ones keep their own definitions. + const membership = readFieldGroupMembership({ + fieldGroups: obj.fieldGroups, + fields: { ...Object.fromEntries([...injectedColumnsFor(obj)].map((n) => [n, {}])), ...fields }, + }); const referencedGroups = new Set( [...membership.members].filter(([, names]) => names.length > 0).map(([key]) => key), ); @@ -156,7 +161,9 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { const grp = g as AnyRec; if (!Array.isArray(grp.fields) || typeof grp.relatedList === 'string') return; grp.fields.forEach((name: unknown, fi: number) => { - if (typeof name !== 'string' || Object.prototype.hasOwnProperty.call(fields, name)) return; + // `fieldNames`: declared fields AND the system columns the platform + // injects here — a list may place `owner_id` without redeclaring it. + if (typeof name !== 'string' || fieldNames.has(name)) return; findings.push({ severity: 'warning', rule: FIELD_GROUP_MEMBER_UNKNOWN, diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.test.ts b/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.test.ts index 5252519d131..ac4fd8d640c 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.test.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.test.ts @@ -18,6 +18,8 @@ import { moveGroup, clearFieldGroup, groupEntries, + currentGroupLayout, + writeGroupLayout, diffFields, type FieldsView, } from './object-fields-io'; @@ -422,3 +424,88 @@ describe('newField — a master-detail field starts required (objectui#12326)', expect('required' in newField('subject', 'text').def).toBe(false); }); }); + +/* ─────────────── fieldGroups[].fields (objectstack#35900) ─────────────── */ + +describe('writeGroupLayout — a move lands on the groups\' fields lists, not the field order', () => { + // `fields` declares name, account, valid_until, terms; `basic` holds the + // first two by the older `group`, `terms` is ungrouped. + const view: FieldsView = readFields({ + name: { type: 'text', group: 'basic' }, + account: { type: 'text', group: 'basic' }, + valid_until: { type: 'date', group: 'money' }, + terms: { type: 'textarea' }, + }); + const groups = readGroups([{ key: 'basic', label: 'Basic' }, { key: 'money', label: 'Money' }]); + + it('dragging a field to the top of its group writes only that group\'s list', () => { + const layout = currentGroupLayout(view, groups); + layout.set('basic', ['account', 'name']); + const patch = writeGroupLayout(view, groups, layout); + expect(patch.fields).toBeUndefined(); + expect(patch.fieldGroups).toEqual([ + { key: 'basic', label: 'Basic', fields: ['account', 'name'] }, + { key: 'money', label: 'Money' }, + ]); + // The result is one the spec accepts, and the record page draws it so. + const parsed = ObjectSchema.safeParse({ name: 'quote', label: 'Quote', fields: writeFields(view), ...patch }); + expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true); + }); + + it('an unchanged layout writes nothing', () => { + expect(writeGroupLayout(view, groups, currentGroupLayout(view, groups))).toEqual({}); + }); + + it('moving a field between groups rewrites both lists and drops the group key the list contradicts', () => { + const layout = currentGroupLayout(view, groups); + layout.set('basic', ['name']); + layout.set('money', ['account', 'valid_until']); + const patch = writeGroupLayout(view, groups, layout); + expect(patch.fieldGroups?.map((g) => g.fields)).toEqual([['name'], ['account', 'valid_until']]); + const fields = patch.fields as Record>; + expect(Object.keys(fields)).toEqual(['name', 'account', 'valid_until', 'terms']); + expect(fields.account.group).toBeUndefined(); + expect(fields.name.group).toBe('basic'); + const parsed = ObjectSchema.safeParse({ name: 'quote', label: 'Quote', ...patch }); + expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true); + }); + + it('moving a field to the ungrouped bucket drops its group and leaves the field order alone', () => { + const layout = currentGroupLayout(view, groups); + layout.set('basic', ['name']); + layout.set(null, ['account', 'terms']); + const patch = writeGroupLayout(view, groups, layout); + const fields = patch.fields as Record>; + expect(Object.keys(fields)).toEqual(['name', 'account', 'valid_until', 'terms']); + expect(fields.account.group).toBeUndefined(); + expect(patch.fieldGroups?.[0].fields).toEqual(['name']); + }); + + it('reordering the ungrouped bucket permutes only the ungrouped fields\' slots', () => { + const v = readFields({ a: { type: 'text' }, b: { type: 'text', group: 'basic' }, c: { type: 'text' } }); + const layout = currentGroupLayout(v, groups); + layout.set(null, ['c', 'a']); + const patch = writeGroupLayout(v, groups, layout); + expect(Object.keys(patch.fields as object)).toEqual(['c', 'b', 'a']); + expect(patch.fieldGroups).toBeUndefined(); + expect(writeGroupLayout(v, groups, layout, { reorderUngrouped: false })).toEqual({}); + }); + + it('a field the caller does not show keeps its membership behind the shown ones', () => { + const v = readFields({ name: { type: 'text', group: 'basic' }, secret: { type: 'text', group: 'basic' }, account: { type: 'text', group: 'basic' } }); + const layout = currentGroupLayout(v, groups, (e) => e.name !== 'secret'); + layout.set('basic', ['account', 'name']); + expect(writeGroupLayout(v, groups, layout).fieldGroups?.[0].fields).toEqual(['account', 'name', 'secret']); + }); +}); + +describe('groupEntries reads a group\'s own fields list (objectstack#35900)', () => { + it('orders a listing group by its list, and a field its group names but the list leaves out after it', () => { + const view = readFields({ name: { type: 'text' }, account: { type: 'text' }, terms: { type: 'text', group: 'basic' }, other: { type: 'text' } }); + const buckets = groupEntries(view, [{ key: 'basic', label: 'Basic', fields: ['account', 'name'] }]); + expect(buckets.map((b) => [b.key, b.entries.map((e) => e.name)])).toEqual([ + ['basic', ['account', 'name', 'terms']], + [null, ['other']], + ]); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts b/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts index 451fc12f141..3fa5a305823 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/object-fields-io.ts @@ -599,7 +599,7 @@ export interface GroupedEntries { export function groupEntries( view: FieldsView, - fieldGroups: Array<{ key?: string; label?: string }> | undefined, + fieldGroups: Array<{ key?: string; label?: string; fields?: readonly string[] }> | undefined, opts?: { includeEmptyDeclared?: boolean }, ): GroupedEntries[] { const declared = Array.isArray(fieldGroups) ? fieldGroups.filter((g) => typeof g?.key === 'string') : []; diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.dndAnnouncements-11802.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.dndAnnouncements-11802.test.tsx index 7970876ad1d..8b17e2af7a9 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.dndAnnouncements-11802.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.dndAnnouncements-11802.test.tsx @@ -43,6 +43,7 @@ vi.mock('@dnd-kit/core', async (importOriginal) => { return { ...actual, DndContext: GeometryDndContext }; }); +import { readFieldGroupMembership } from '@objectstack/spec/data'; import { ObjectFormDesigner } from './ObjectFormDesigner'; // The designer rows this suite reads in zh live in `@object-ui/i18n`'s `studio` @@ -82,18 +83,37 @@ const zh = () => }, }); -/** Every `fields` the designer committed, in order. */ +/** Every layout the designer committed, in order (see `resolvedLayout`). */ let commits: Field[][] = []; +/** The draft as the last commit left it. */ +let latest: Record = {}; + +/** + * objectstack#35900 — a move lands on the groups' `fields` lists, not on the + * fields array, so a commit is read as the layout the whole draft now + * resolves to: each field with the group it sits in, groups in order, then + * the ungrouped ones (no `group`). + */ +function resolvedLayout(d: Record): Field[] { + const list = d.fields as Field[]; + const { members, groupOf } = readFieldGroupMembership({ ...d, fields: Object.fromEntries(list.map((f) => [f.name, f])) }); + const byName = new Map(list.map((f) => [f.name, f])); + const out: Field[] = []; + for (const [key, names] of members) for (const n of names) out.push({ ...byName.get(n)!, group: key }); + for (const f of list) if (!groupOf.has(f.name)) out.push({ name: f.name, type: f.type, label: f.label }); + return out; +} function Host(): React.ReactElement { - const [draft, setDraft] = React.useState>(DRAFT); + const [draft, setDraft] = React.useState>(() => (latest = DRAFT)); return ( { - if (patch.fields) commits.push(patch.fields as Field[]); - setDraft((d) => ({ ...d, ...patch })); + latest = { ...latest, ...patch }; + commits.push(resolvedLayout(latest)); + setDraft(latest); }} onSelectField={() => {}} /> diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardDrop-11871.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardDrop-11871.test.tsx index 0b5d2d70c55..bc6bce565ac 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardDrop-11871.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardDrop-11871.test.tsx @@ -29,6 +29,7 @@ import '@testing-library/jest-dom/vitest'; import * as React from 'react'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'; +import { readFieldGroupMembership } from '@objectstack/spec/data'; import { ObjectFormDesigner } from './ObjectFormDesigner'; type Field = { name: string; type: string; label: string; group?: string }; @@ -115,18 +116,37 @@ beforeEach(() => { }; }); -/** Every `fields` the designer committed, in order. */ +/** Every layout the designer committed, in order (see `resolvedLayout`). */ let commits: Field[][] = []; +/** The draft as the last commit left it. */ +let latest: Record = {}; + +/** + * objectstack#35900 — a move lands on the groups' `fields` lists, not on the + * fields array, so a commit is read as the layout the whole draft now + * resolves to: each field with the group it sits in, groups in order, then + * the ungrouped ones (no `group`). + */ +function resolvedLayout(d: Record): Field[] { + const list = d.fields as Field[]; + const { members, groupOf } = readFieldGroupMembership({ ...d, fields: Object.fromEntries(list.map((f) => [f.name, f])) }); + const byName = new Map(list.map((f) => [f.name, f])); + const out: Field[] = []; + for (const [key, names] of members) for (const n of names) out.push({ ...byName.get(n)!, group: key }); + for (const f of list) if (!groupOf.has(f.name)) out.push({ name: f.name, type: f.type, label: f.label }); + return out; +} function Host(): React.ReactElement { - const [draft, setDraft] = React.useState>(DRAFT); + const [draft, setDraft] = React.useState>(() => (latest = DRAFT)); return ( { - if (patch.fields) commits.push(patch.fields as Field[]); - setDraft((d) => ({ ...d, ...patch })); + latest = { ...latest, ...patch }; + commits.push(resolvedLayout(latest)); + setDraft(latest); }} onSelectField={() => {}} /> @@ -169,10 +189,14 @@ async function keyboardMove(label: string, arrows: string[]): Promise return heard; } -/** The last commit, as group key → field names in order (`''` = ungrouped). */ +/** + * The last commit, as group key → field names in order (`''` = ungrouped). + * A drop that changes nothing writes nothing (objectstack#35900), so with no + * commit this reads the draft as it stands. + */ function layoutOfLastCommit(): Record { const out: Record = {}; - for (const f of commits.at(-1) ?? []) (out[f.group ?? ''] ??= []).push(f.name); + for (const f of commits.at(-1) ?? resolvedLayout(latest)) (out[f.group ?? ''] ??= []).push(f.name); return out; } @@ -226,6 +250,33 @@ describe('a keyboard drag in the form designer reaches a drop target (objectui#1 }); }); +describe('a move writes the group\'s own fields list, not the object\'s field order (objectstack#35900)', () => { + it('reordering inside a group changes only that group\'s fields: the fields array is untouched', async () => { + renderDesigner(); + await keyboardMove('Phone', ['ArrowDown']); + expect(said()).toBe('Phone moved to Contact, position 2 of 2.'); + // Same array, same order, same definitions: the list default columns and + // the form order read are where they were. + expect(latest.fields).toBe(DRAFT.fields); + expect(latest.fieldGroups).toEqual([ + { key: 'contact', label: 'Contact', fields: ['email', 'phone'] }, + { key: 'new_group', label: 'New group' }, + ]); + }); + + it('carrying a field into another group lists it there and drops the group key that would contradict the list', async () => { + renderDesigner(); + await keyboardMove('Email', ['ArrowDown']); + const fields = latest.fields as Field[]; + expect(fields.map((f) => f.name)).toEqual(['name', 'industry', 'phone', 'email']); + expect(fields.find((f) => f.name === 'email')!.group).toBeUndefined(); + expect(latest.fieldGroups).toEqual([ + { key: 'contact', label: 'Contact', fields: ['phone'] }, + { key: 'new_group', label: 'New group', fields: ['email'] }, + ]); + }); +}); + describe('control: a pointer drag still answers through pointerWithin (objectui#11871)', () => { /** Press on `from`, cross the 4px activation distance, move to each point in `path`. */ function pointerDrag(from: { x: number; y: number }, path: Array<{ x: number; y: number }>) { diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardGrid-11898.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardGrid-11898.test.tsx index 04519ade4df..fca9e38b4a7 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardGrid-11898.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.keyboardGrid-11898.test.tsx @@ -37,6 +37,7 @@ import '@testing-library/jest-dom/vitest'; import * as React from 'react'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'; +import { readFieldGroupMembership } from '@objectstack/spec/data'; import { ObjectFormDesigner } from './ObjectFormDesigner'; type Field = { name: string; type: string; label: string; group?: string }; @@ -191,18 +192,37 @@ afterEach(() => { Element.prototype.getBoundingClientRect = originalRect; }); -/** Every `fields` the designer committed, in order. */ +/** Every layout the designer committed, in order (see `resolvedLayout`). */ let commits: Field[][] = []; +/** The draft as the last commit left it. */ +let latest: Record = {}; + +/** + * objectstack#35900 — a move lands on the groups' `fields` lists, not on the + * fields array, so a commit is read as the layout the whole draft now + * resolves to: each field with the group it sits in, groups in order, then + * the ungrouped ones (no `group`). + */ +function resolvedLayout(d: Record): Field[] { + const list = d.fields as Field[]; + const { members, groupOf } = readFieldGroupMembership({ ...d, fields: Object.fromEntries(list.map((f) => [f.name, f])) }); + const byName = new Map(list.map((f) => [f.name, f])); + const out: Field[] = []; + for (const [key, names] of members) for (const n of names) out.push({ ...byName.get(n)!, group: key }); + for (const f of list) if (!groupOf.has(f.name)) out.push({ name: f.name, type: f.type, label: f.label }); + return out; +} function Host({ draft: initial }: { draft: Draft }): React.ReactElement { - const [draft, setDraft] = React.useState>(initial); + const [draft, setDraft] = React.useState>(() => (latest = initial)); return ( { - if (patch.fields) commits.push(patch.fields as Field[]); - setDraft((d) => ({ ...d, ...patch })); + latest = { ...latest, ...patch }; + commits.push(resolvedLayout(latest)); + setDraft(latest); }} onSelectField={() => {}} /> @@ -241,16 +261,20 @@ async function keyboardMove(label: string, arrows: string[]): Promise return heard; } -/** The last commit, as group key → field names in order (`''` = ungrouped). */ +/** + * The last commit, as group key → field names in order (`''` = ungrouped). + * A drop that changes nothing writes nothing (objectstack#35900), so with no + * commit this reads the draft as it stands. + */ function layoutOfLastCommit(): Record { const out: Record = {}; - for (const f of commits.at(-1) ?? []) (out[f.group ?? ''] ??= []).push(f.name); + for (const f of commits.at(-1) ?? resolvedLayout(latest)) (out[f.group ?? ''] ??= []).push(f.name); return out; } /** The place the last commit gives a field, in the live region's words: "Group, position N of M". */ function committedPlace(name: string): string { - const fields = commits.at(-1) ?? []; + const fields = commits.at(-1) ?? resolvedLayout(latest); const group = fields.find((f) => f.name === name)?.group; const members = fields.filter((f) => f.group === group).map((f) => f.name); const label = GROUPS.find((g) => g.key === group)?.label ?? 'Ungrouped'; diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.pinnedFields-27516.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.pinnedFields-27516.test.tsx index 43843c847a2..7f47317b8e2 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.pinnedFields-27516.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.pinnedFields-27516.test.tsx @@ -58,6 +58,8 @@ const HOST_SYSTEM_NAMES = new Set(['organization_id', 'created_at', 'created_by' /** Every `fields` the designer committed, in order. */ let commits: Fields[] = []; +/** Every `fieldGroups` the designer committed, in order (objectstack#35900). */ +let groupCommits: Array>> = []; function Host({ initial }: { initial: Record }): React.ReactElement { const [draft, setDraft] = React.useState>(initial); @@ -67,6 +69,7 @@ function Host({ initial }: { initial: Record }): React.ReactEle systemFieldNames={HOST_SYSTEM_NAMES} onChange={(patch) => { if (patch.fields) commits.push(patch.fields as Fields); + if (patch.fieldGroups) groupCommits.push(patch.fieldGroups as Array>); setDraft((d) => ({ ...d, ...patch })); }} onSelectField={() => {}} @@ -76,6 +79,7 @@ function Host({ initial }: { initial: Record }): React.ReactEle function renderDesigner(draft: Record) { commits = []; + groupCommits = []; return render(); } @@ -125,15 +129,13 @@ describe('the form canvas settles the platform’s pinned fields first (objectst expect(said()).toBe('Condition moved to Ungrouped, position 2 of 3.'); const shown = ungroupedCards(); expect(shown).toEqual(['Owner', 'Condition', 'Notes']); - expect(Object.keys(commits.at(-1)!).filter((n) => !HOST_SYSTEM_NAMES.has(n))).toEqual([ - 'owner_id', - 'condition', - 'notes', - ]); + // The settled order is the one the canvas started from, so the drop has + // nothing to write (objectstack#35900: only a change is written) … + expect(commits).toHaveLength(0); - // After the round trip the canvas shows the same order. + // … and the reload of the untouched draft shows the same order. cleanup(); - renderDesigner(served(reload(commits.at(-1)!))); + renderDesigner(served(reload({ owner_id: { ...OWNER_FIELD_DEF }, condition, notes }))); expect(ungroupedCards()).toEqual(shown); }); @@ -160,13 +162,17 @@ describe('the form canvas settles the platform’s pinned fields first (objectst expect(ungroupedCards()).toEqual(['Condition', 'Account manager', 'Notes']); }); - it('Owner moved into a section carries the section and keeps its place there', () => { + it('Owner moved into a section joins its fields list and keeps its place there', () => { renderDesigner(served({ owner_id: { ...OWNER_FIELD_DEF }, condition: { ...condition, group: 'details' }, notes })); pointerDrag(card('Owner'), ['f:condition']); - const committed = commits.at(-1)!; - expect(committed.owner_id.group).toBe('details'); - const authored = (fields: Fields) => Object.keys(fields).filter((n) => ['owner_id', 'condition', 'notes'].includes(n)); - // The section's order is the author's, so the round trip keeps it. - expect(authored(reload(committed))).toEqual(authored(committed)); + // objectstack#35900: the section lists Owner where it was dropped (after Condition), and the + // column stays exactly the platform's, so the write may still strip it and + // the read put it back: the list keeps its place either way. + expect(commits).toHaveLength(0); + expect(groupCommits.at(-1)).toEqual([{ key: 'details', label: 'Details', fields: ['condition', 'owner_id'] }]); + cleanup(); + renderDesigner({ ...served(reload({ condition: { ...condition, group: 'details' }, notes })), fieldGroups: groupCommits.at(-1) }); + const cards = ([...document.querySelectorAll('.cursor-grab')] as HTMLElement[]).map((c) => c.querySelector('.truncate')?.textContent ?? ''); + expect(cards).toEqual(['Condition', 'Owner', 'Notes']); }); }); From 0d42c18e1c04a5279ecd6b4dbd3b2790141fbde8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:01:34 +0000 Subject: [PATCH 05/10] chore(spec): regenerate references, api surface, export origins and liveness for fieldGroups[].fields; changeset Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .changeset/35900-field-group-members.md | 29 +++++++++++++++++++ content/docs/references/api/metadata.mdx | 2 +- content/docs/references/data/field.mdx | 2 +- content/docs/references/data/object.mdx | 12 ++++---- content/docs/references/system/migration.mdx | 8 ++--- packages/spec/api-surface/data.json | 2 ++ packages/spec/export-origins/data.json | 2 ++ packages/spec/liveness/object.json | 7 +++++ packages/spec/liveness/state-counts/object.md | 2 +- 9 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 .changeset/35900-field-group-members.md diff --git a/.changeset/35900-field-group-members.md b/.changeset/35900-field-group-members.md new file mode 100644 index 00000000000..30ccaeec1a6 --- /dev/null +++ b/.changeset/35900-field-group-members.md @@ -0,0 +1,29 @@ +--- +'@objectstack/spec': minor +'@objectstack/lint': minor +'@object-ui/app-shell': minor +--- + +feat(spec): a field group lists its own members and their order (`fieldGroups[].fields`) + +Clause-②: yes (widening) +Metadata-protocol: added + +A field group may now list which fields it shows and in what order: + +```ts +fieldGroups: [ + { key: 'basic', label: 'Basic', fields: ['account', 'name', 'valid_until'] }, + { key: 'terms', label: 'Terms', fields: ['terms'] }, +] +``` + +The record page, the create and edit forms and the drawer show the group's fields in the list's order, whatever order the object's `fields` declares them in, so a group can be reordered without moving any field (and without changing a list view's default column order). + +Nothing changes for an object that writes no `fields` on its groups: a group without the list still holds the fields whose `group` names it, in field declaration order. `Field.group` is the older spelling and is still read; it is not deprecated for removal. + +The two spellings must agree. The object parse refuses a field one group lists while its own `group` names another group (reported at both places), a field two groups list, a name one list repeats, and `fields` on a group that places a related list (`relatedList`). A field whose `group` names a listing group that leaves it out is shown after the listed fields, never dropped. A listed name the object does not declare is skipped, so removing a field never makes the object unparseable; `os lint` warns about it (`field-group-member-unknown`). + +New export: `readFieldGroupMembership` (`@objectstack/spec/data`), the membership `deriveFieldGroupLayout` places sections from, for editors that also show hidden fields. + +Studio: dragging a field inside a group, or into another group, now writes those groups' `fields` lists and leaves the object's field declaration order alone. Only the ungrouped bucket, which has no list, still reorders by declaration order. Moving a field to another group from the field inspector does the same once a list is involved. diff --git a/content/docs/references/api/metadata.mdx b/content/docs/references/api/metadata.mdx index 63baeb2d962..204bb7cf90e 100644 --- a/content/docs/references/api/metadata.mdx +++ b/content/docs/references/api/metadata.mdx @@ -948,7 +948,7 @@ Metadata query with filtering, sorting, and pagination | **fields** | `Record; description?: string; … }>` | ✅ | Field definitions map. Keys must be snake_case identifiers; "__proto__", "constructor" and "prototype" are refused, and so is the "_sync_" prefix, reserved for the platform's sync-in columns. | | **attachedOnRead** | `Record>>` | optional | Blocks a service attaches to each row it serves, computed per caller on read and never stored: block name → `{ leaf key → value type (number \| text \| boolean \| date) }`. NOT a field — no column, form, list view, export, write path or translation bundle reads it, and a block name may not repeat a declared field name. Its reader is the shared build validator (`@objectstack/lint` over `@objectstack/formula`, as `os build` / `os validate` run it), and only where `record` is a row the service served: in an action's `visible` and `disabled` predicates `record.` resolves, and `record..` resolves only to a leaf the block declares. Every other expression site binds the stored row, which never carries a block — a flow condition, a validation rule, a field rule or formula, an option `visibleWhen`, a sharing rule, a hook — and refuses `record.` as an unknown field. | | **indexes** | `{ name?: string; fields: string[]; unique?: false \| 'global' \| 'organization' }[]` | optional | Database performance indexes | -| **fieldGroups** | `{ key: string; label: string; icon?: string; description?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | +| **fieldGroups** | `{ key: string; label: string; fields?: string[]; icon?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | | **tenancy** | `{ enabled: boolean; tenantField?: string }` | optional | Multi-tenancy configuration for SaaS applications | | **access** | `{ default?: Enum<'public' \| 'private'> }` | optional | [ADR-0066 D2] Object exposure posture (public-by-default vs private secure-by-default). | | **requiredPermissions** | `string[] \| { read?: string[]; create?: string[]; update?: string[]; delete?: string[] }` | optional | [ADR-0066 D3/⑤] Capabilities required to access this object (AND-gate) — `string[]` gates all CRUD, or a `{read,create,update,delete}` map gates per operation. | diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index fb9d9820a7c..a26c824ac09 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -106,7 +106,7 @@ const result = CurrencyConfigSchema.parse(data); | **unitConfig** | `{ unitMode: 'fixed'; unit: Enum<'KGM' \| 'GRM' \| 'MGM' \| 'TNE' \| 'LBR' \| 'ONZ' \| 'MTR' \| 'MMT' \| 'CMT' \| 'KMT' \| …> } \| { unitMode: 'record'; unitField: string; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> } \| { unitMode: 'code'; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> }` | optional | Which unit a quantity is in, or that a text field holds a unit code (units of measure). On a `number` field: `{ unitMode: 'fixed', unit }`, one standard UN/ECE Recommendation 20 code checked at build (e.g. `KGM`, `MTR`, `H87`), or `{ unitMode: 'record', unitField, unitDimension? }`, where each record names its own unit in the sibling `text` field `unitField` names. On a `text` field that holds a unit code with no quantity pointing at it: `{ unitMode: 'code', unitDimension? }`. The quantity stays a bare number; a record stores the unit CODE in exact uppercase, never an id. At write, a code must be a standard code or one of the organization's own non-retired units (`sys_unit`), of the restricted dimension when one is declared, and a quantity beside a blank code is refused. Refused on every other field type, `formula` and `summary` included. Absent: the number has no unit. | | **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) | | **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. | -| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") | +| **group** | `string` | optional | Older spelling of field-group membership, still read: the key of one of the object's fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones. | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is shown only when TRUE (else hidden). e.g. P`record.type == 'invoice'`. On a `required` field the server reads it on every write: where it is not TRUE (FALSE, or null such as an unset boolean) the field is not required for that write, and a predicate the server cannot evaluate counts as shown, so the field stays required. Reads the record's own columns, with `formula` fields computed over the record being written, as the form computes them over the record being edited; a read THROUGH a reference field, or a formula that reads through one, calls label(), calls can() on a write that picks no permission-gated option, or reads current_user on a system write with no user, cannot be evaluated there. | | **readonlyWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is read-only when TRUE. e.g. P`record.status == 'paid'`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every update that writes the field — `objectstack validate` refuses it. Put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. | | **requiredWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is required when TRUE. A TRANSITION GATE, not an invariant: the write is refused only when the merged record violates the requirement AND the pre-write record complied — so the write that flips the predicate TRUE, an INSERT born inside the gate, and a write that clears the cell are all refused, while a row that was already missing the value keeps passing unrelated edits and state moves that stay inside the gate (ADR-0113 non-regression: adding the rule to a deployed object never bricks existing rows). Need an invariant every write must satisfy instead ('X may never exceed Y') — declare a `validations[]` `script` rule, which re-checks the merged record with no exemption. Enforced by `evaluateValidationRules`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every write that reaches it — `objectstack validate` refuses it; put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. The only slot; the `conditionalRequired` alias was removed in protocol 17. | diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index 337d3691307..15f2db1db3c 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -160,7 +160,7 @@ const result = ApiMethod.parse(data); | **fields** | `Record; description?: string; … }>` | ✅ | Field definitions map. Keys must be snake_case identifiers; "__proto__", "constructor" and "prototype" are refused, and so is the "_sync_" prefix, reserved for the platform's sync-in columns. | | **attachedOnRead** | `Record>>` | optional | Blocks a service attaches to each row it serves, computed per caller on read and never stored: block name → `{ leaf key → value type (number \| text \| boolean \| date) }`. NOT a field — no column, form, list view, export, write path or translation bundle reads it, and a block name may not repeat a declared field name. Its reader is the shared build validator (`@objectstack/lint` over `@objectstack/formula`, as `os build` / `os validate` run it), and only where `record` is a row the service served: in an action's `visible` and `disabled` predicates `record.` resolves, and `record..` resolves only to a leaf the block declares. Every other expression site binds the stored row, which never carries a block — a flow condition, a validation rule, a field rule or formula, an option `visibleWhen`, a sharing rule, a hook — and refuses `record.` as an unknown field. | | **indexes** | `{ name?: string; fields: string[]; unique?: false \| 'global' \| 'organization' }[]` | optional | Database performance indexes | -| **fieldGroups** | `{ key: string; label: string; icon?: string; description?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | +| **fieldGroups** | `{ key: string; label: string; fields?: string[]; icon?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | | **tenancy** | `{ enabled: boolean; tenantField?: string }` | optional | Multi-tenancy configuration for SaaS applications | | **access** | `{ default?: Enum<'public' \| 'private'> }` | optional | [ADR-0066 D2] Object exposure posture (public-by-default vs private secure-by-default). | | **requiredPermissions** | `string[] \| { read?: string[]; create?: string[]; update?: string[]; delete?: string[] }` | optional | [ADR-0066 D3/⑤] Capabilities required to access this object (AND-gate) — `string[]` gates all CRUD, or a `{read,create,update,delete}` map gates per operation. | @@ -285,7 +285,7 @@ const result = ApiMethod.parse(data); | **unitConfig** | `{ unitMode: 'fixed'; unit: Enum<'KGM' \| 'GRM' \| 'MGM' \| 'TNE' \| 'LBR' \| 'ONZ' \| 'MTR' \| 'MMT' \| 'CMT' \| 'KMT' \| …> } \| { unitMode: 'record'; unitField: string; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> } \| { unitMode: 'code'; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> }` | optional | Which unit a quantity is in, or that a text field holds a unit code (units of measure). On a `number` field: `{ unitMode: 'fixed', unit }`, one standard UN/ECE Recommendation 20 code checked at build (e.g. `KGM`, `MTR`, `H87`), or `{ unitMode: 'record', unitField, unitDimension? }`, where each record names its own unit in the sibling `text` field `unitField` names. On a `text` field that holds a unit code with no quantity pointing at it: `{ unitMode: 'code', unitDimension? }`. The quantity stays a bare number; a record stores the unit CODE in exact uppercase, never an id. At write, a code must be a standard code or one of the organization's own non-retired units (`sys_unit`), of the restricted dimension when one is declared, and a quantity beside a blank code is refused. Refused on every other field type, `formula` and `summary` included. Absent: the number has no unit. | | **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) | | **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. | -| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") | +| **group** | `string` | optional | Older spelling of field-group membership, still read: the key of one of the object's fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones. | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is shown only when TRUE (else hidden). e.g. P`record.type == 'invoice'`. On a `required` field the server reads it on every write: where it is not TRUE (FALSE, or null such as an unset boolean) the field is not required for that write, and a predicate the server cannot evaluate counts as shown, so the field stays required. Reads the record's own columns, with `formula` fields computed over the record being written, as the form computes them over the record being edited; a read THROUGH a reference field, or a formula that reads through one, calls label(), calls can() on a write that picks no permission-gated option, or reads current_user on a system write with no user, cannot be evaluated there. | | **readonlyWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is read-only when TRUE. e.g. P`record.status == 'paid'`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every update that writes the field — `objectstack validate` refuses it. Put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. | | **requiredWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is required when TRUE. A TRANSITION GATE, not an invariant: the write is refused only when the merged record violates the requirement AND the pre-write record complied — so the write that flips the predicate TRUE, an INSERT born inside the gate, and a write that clears the cell are all refused, while a row that was already missing the value keeps passing unrelated edits and state moves that stay inside the gate (ADR-0113 non-regression: adding the rule to a deployed object never bricks existing rows). Need an invariant every write must satisfy instead ('X may never exceed Y') — declare a `validations[]` `script` rule, which re-checks the merged record with no exemption. Enforced by `evaluateValidationRules`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every write that reaches it — `objectstack validate` refuses it; put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. The only slot; the `conditionalRequired` alias was removed in protocol 17. | @@ -328,9 +328,10 @@ const result = ApiMethod.parse(data); | :--- | :--- | :--- | :--- | | **key** | `string` | ✅ | Group machine key (snake_case). Referenced by Field.group, and by a layout section's `group`. | | **label** | `string` | ✅ | Group display label | +| **fields** | `string[]` | optional | The group's members in display order (field names of this object). Written, it decides which fields the group shows and their order on the record page and the forms, without changing the order of the object's fields. Absent, members are the fields whose `group` names this group, in field declaration order (the older spelling, still read). A field whose `group` names this group but that the list does not name follows the listed ones. Refused: a listed field whose own `group` names another group, a field two groups list, a repeated name, and `fields` on a group with `relatedList`. A name the object does not declare is skipped. | | **icon** | `string` | optional | Icon name (Lucide/Material) for the group header | | **description** | `string` | optional | Optional description shown under the group header | -| **relatedList** | `string` | optional | 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. 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): 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). | +| **relatedList** | `string` | optional | 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): 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). | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Section visibility predicate (CEL) — the whole group (header included) is shown only when TRUE, else hidden (fail-closed). e.g. P`record.type == 'invoice'` | | **requiresFeature** | `Enum<'twoFactor' \| 'organization' \| 'multiOrgEnabled' \| 'degradedTenancy' \| …>` | optional | Deployment feature flag gating this group, from the same set an action's `requiresFeature` names (e.g. 'multiOrgEnabled'). Lowered at parse time into the group's `visibleWhen` (AND-composed after an authored `visibleWhen`) and stripped from the output; the whole group is hidden where the flag is off. Presentation only: the fields stay readable through the API. | | **collapse** | `Enum<'none' \| 'expanded' \| 'collapsed'>` | optional (default: `"none"`) | [ADR-0085] Section collapse behaviour: 'none' (always open, no toggle), 'expanded' (collapsible, starts open), 'collapsed' (collapsible, starts closed). | @@ -666,7 +667,7 @@ const result = ApiMethod.parse(data); | **unitConfig** | `{ unitMode: 'fixed'; unit: Enum<'KGM' \| 'GRM' \| 'MGM' \| 'TNE' \| 'LBR' \| 'ONZ' \| 'MTR' \| 'MMT' \| 'CMT' \| 'KMT' \| …> } \| { unitMode: 'record'; unitField: string; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> } \| { unitMode: 'code'; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> }` | optional | Which unit a quantity is in, or that a text field holds a unit code (units of measure). On a `number` field: `{ unitMode: 'fixed', unit }`, one standard UN/ECE Recommendation 20 code checked at build (e.g. `KGM`, `MTR`, `H87`), or `{ unitMode: 'record', unitField, unitDimension? }`, where each record names its own unit in the sibling `text` field `unitField` names. On a `text` field that holds a unit code with no quantity pointing at it: `{ unitMode: 'code', unitDimension? }`. The quantity stays a bare number; a record stores the unit CODE in exact uppercase, never an id. At write, a code must be a standard code or one of the organization's own non-retired units (`sys_unit`), of the restricted dimension when one is declared, and a quantity beside a blank code is refused. Refused on every other field type, `formula` and `summary` included. Absent: the number has no unit. | | **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) | | **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. | -| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") | +| **group** | `string` | optional | Older spelling of field-group membership, still read: the key of one of the object's fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones. | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is shown only when TRUE (else hidden). e.g. P`record.type == 'invoice'`. On a `required` field the server reads it on every write: where it is not TRUE (FALSE, or null such as an unset boolean) the field is not required for that write, and a predicate the server cannot evaluate counts as shown, so the field stays required. Reads the record's own columns, with `formula` fields computed over the record being written, as the form computes them over the record being edited; a read THROUGH a reference field, or a formula that reads through one, calls label(), calls can() on a write that picks no permission-gated option, or reads current_user on a system write with no user, cannot be evaluated there. | | **readonlyWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is read-only when TRUE. e.g. P`record.status == 'paid'`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every update that writes the field — `objectstack validate` refuses it. Put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. | | **requiredWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is required when TRUE. A TRANSITION GATE, not an invariant: the write is refused only when the merged record violates the requirement AND the pre-write record complied — so the write that flips the predicate TRUE, an INSERT born inside the gate, and a write that clears the cell are all refused, while a row that was already missing the value keeps passing unrelated edits and state moves that stay inside the gate (ADR-0113 non-regression: adding the rule to a deployed object never bricks existing rows). Need an invariant every write must satisfy instead ('X may never exceed Y') — declare a `validations[]` `script` rule, which re-checks the merged record with no exemption. Enforced by `evaluateValidationRules`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every write that reaches it — `objectstack validate` refuses it; put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. The only slot; the `conditionalRequired` alias was removed in protocol 17. | @@ -742,9 +743,10 @@ External datasource binding (ADR-0015) | :--- | :--- | :--- | :--- | | **key** | `string` | ✅ | Group machine key (snake_case). Referenced by Field.group, and by a layout section's `group`. | | **label** | `string` | ✅ | Group display label | +| **fields** | `string[]` | optional | The group's members in display order (field names of this object). Written, it decides which fields the group shows and their order on the record page and the forms, without changing the order of the object's fields. Absent, members are the fields whose `group` names this group, in field declaration order (the older spelling, still read). A field whose `group` names this group but that the list does not name follows the listed ones. Refused: a listed field whose own `group` names another group, a field two groups list, a repeated name, and `fields` on a group with `relatedList`. A name the object does not declare is skipped. | | **icon** | `string` | optional | Icon name (Lucide/Material) for the group header | | **description** | `string` | optional | Optional description shown under the group header | -| **relatedList** | `string` | optional | 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. 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): 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). | +| **relatedList** | `string` | optional | 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): 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). | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Section visibility predicate (CEL) — the whole group (header included) is shown only when TRUE, else hidden (fail-closed). e.g. P`record.type == 'invoice'` | | **requiresFeature** | `Enum<'twoFactor' \| 'organization' \| 'multiOrgEnabled' \| 'degradedTenancy' \| 'oidcProvider' \| 'sso' \| 'ssoEnforced' \| 'directSignIn' \| 'deviceAuthorization' \| 'admin' \| … +5 more>` | optional | Deployment feature flag gating this group, from the same set an action's `requiresFeature` names (e.g. 'multiOrgEnabled'). Lowered at parse time into the group's `visibleWhen` (AND-composed after an authored `visibleWhen`) and stripped from the output; the whole group is hidden where the flag is off. Presentation only: the fields stay readable through the API. | | **collapse** | `Enum<'none' \| 'expanded' \| 'collapsed'>` | optional (default: `"none"`) | [ADR-0085] Section collapse behaviour: 'none' (always open, no toggle), 'expanded' (collapsible, starts open), 'collapsed' (collapsible, starts closed). | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index 835ec409c5d..095ac234857 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -109,7 +109,7 @@ Add a new field to an existing object | **unitConfig** | `{ unitMode: 'fixed'; unit: Enum<'KGM' \| 'GRM' \| 'MGM' \| 'TNE' \| 'LBR' \| 'ONZ' \| 'MTR' \| 'MMT' \| 'CMT' \| 'KMT' \| …> } \| { unitMode: 'record'; unitField: string; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> } \| { unitMode: 'code'; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> }` | optional | Which unit a quantity is in, or that a text field holds a unit code (units of measure). On a `number` field: `{ unitMode: 'fixed', unit }`, one standard UN/ECE Recommendation 20 code checked at build (e.g. `KGM`, `MTR`, `H87`), or `{ unitMode: 'record', unitField, unitDimension? }`, where each record names its own unit in the sibling `text` field `unitField` names. On a `text` field that holds a unit code with no quantity pointing at it: `{ unitMode: 'code', unitDimension? }`. The quantity stays a bare number; a record stores the unit CODE in exact uppercase, never an id. At write, a code must be a standard code or one of the organization's own non-retired units (`sys_unit`), of the restricted dimension when one is declared, and a quantity beside a blank code is refused. Refused on every other field type, `formula` and `summary` included. Absent: the number has no unit. | | **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) | | **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. | -| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") | +| **group** | `string` | optional | Older spelling of field-group membership, still read: the key of one of the object's fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones. | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is shown only when TRUE (else hidden). e.g. P`record.type == 'invoice'`. On a `required` field the server reads it on every write: where it is not TRUE (FALSE, or null such as an unset boolean) the field is not required for that write, and a predicate the server cannot evaluate counts as shown, so the field stays required. Reads the record's own columns, with `formula` fields computed over the record being written, as the form computes them over the record being edited; a read THROUGH a reference field, or a formula that reads through one, calls label(), calls can() on a write that picks no permission-gated option, or reads current_user on a system write with no user, cannot be evaluated there. | | **readonlyWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is read-only when TRUE. e.g. P`record.status == 'paid'`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every update that writes the field — `objectstack validate` refuses it. Put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. | | **requiredWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is required when TRUE. A TRANSITION GATE, not an invariant: the write is refused only when the merged record violates the requirement AND the pre-write record complied — so the write that flips the predicate TRUE, an INSERT born inside the gate, and a write that clears the cell are all refused, while a row that was already missing the value keeps passing unrelated edits and state moves that stay inside the gate (ADR-0113 non-regression: adding the rule to a deployed object never bricks existing rows). Need an invariant every write must satisfy instead ('X may never exceed Y') — declare a `validations[]` `script` rule, which re-checks the merged record with no exemption. Enforced by `evaluateValidationRules`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every write that reaches it — `objectstack validate` refuses it; put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. The only slot; the `conditionalRequired` alias was removed in protocol 17. | @@ -340,7 +340,7 @@ Create a new object | **fields** | `Record; description?: string; … }>` | ✅ | Field definitions map. Keys must be snake_case identifiers; "__proto__", "constructor" and "prototype" are refused, and so is the "_sync_" prefix, reserved for the platform's sync-in columns. | | **attachedOnRead** | `Record>>` | optional | Blocks a service attaches to each row it serves, computed per caller on read and never stored: block name → `{ leaf key → value type (number \| text \| boolean \| date) }`. NOT a field — no column, form, list view, export, write path or translation bundle reads it, and a block name may not repeat a declared field name. Its reader is the shared build validator (`@objectstack/lint` over `@objectstack/formula`, as `os build` / `os validate` run it), and only where `record` is a row the service served: in an action's `visible` and `disabled` predicates `record.` resolves, and `record..` resolves only to a leaf the block declares. Every other expression site binds the stored row, which never carries a block — a flow condition, a validation rule, a field rule or formula, an option `visibleWhen`, a sharing rule, a hook — and refuses `record.` as an unknown field. | | **indexes** | `{ name?: string; fields: string[]; unique?: false \| 'global' \| 'organization' }[]` | optional | Database performance indexes | -| **fieldGroups** | `{ key: string; label: string; icon?: string; description?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | +| **fieldGroups** | `{ key: string; label: string; fields?: string[]; icon?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | | **tenancy** | `{ enabled: boolean; tenantField?: string }` | optional | Multi-tenancy configuration for SaaS applications | | **access** | `{ default?: Enum<'public' \| 'private'> }` | optional | [ADR-0066 D2] Object exposure posture (public-by-default vs private secure-by-default). | | **requiredPermissions** | `string[] \| { read?: string[]; create?: string[]; update?: string[]; delete?: string[] }` | optional | [ADR-0066 D3/⑤] Capabilities required to access this object (AND-gate) — `string[]` gates all CRUD, or a `{read,create,update,delete}` map gates per operation. | @@ -546,7 +546,7 @@ Add a new field to an existing object | **unitConfig** | `{ unitMode: 'fixed'; unit: Enum<'KGM' \| 'GRM' \| 'MGM' \| 'TNE' \| 'LBR' \| 'ONZ' \| 'MTR' \| 'MMT' \| 'CMT' \| 'KMT' \| …> } \| { unitMode: 'record'; unitField: string; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> } \| { unitMode: 'code'; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> }` | optional | Which unit a quantity is in, or that a text field holds a unit code (units of measure). On a `number` field: `{ unitMode: 'fixed', unit }`, one standard UN/ECE Recommendation 20 code checked at build (e.g. `KGM`, `MTR`, `H87`), or `{ unitMode: 'record', unitField, unitDimension? }`, where each record names its own unit in the sibling `text` field `unitField` names. On a `text` field that holds a unit code with no quantity pointing at it: `{ unitMode: 'code', unitDimension? }`. The quantity stays a bare number; a record stores the unit CODE in exact uppercase, never an id. At write, a code must be a standard code or one of the organization's own non-retired units (`sys_unit`), of the restricted dimension when one is declared, and a quantity beside a blank code is refused. Refused on every other field type, `formula` and `summary` included. Absent: the number has no unit. | | **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) | | **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. | -| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") | +| **group** | `string` | optional | Older spelling of field-group membership, still read: the key of one of the object's fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones. | | **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is shown only when TRUE (else hidden). e.g. P`record.type == 'invoice'`. On a `required` field the server reads it on every write: where it is not TRUE (FALSE, or null such as an unset boolean) the field is not required for that write, and a predicate the server cannot evaluate counts as shown, so the field stays required. Reads the record's own columns, with `formula` fields computed over the record being written, as the form computes them over the record being edited; a read THROUGH a reference field, or a formula that reads through one, calls label(), calls can() on a write that picks no permission-gated option, or reads current_user on a system write with no user, cannot be evaluated there. | | **readonlyWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is read-only when TRUE. e.g. P`record.status == 'paid'`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every update that writes the field — `objectstack validate` refuses it. Put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. | | **requiredWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is required when TRUE. A TRANSITION GATE, not an invariant: the write is refused only when the merged record violates the requirement AND the pre-write record complied — so the write that flips the predicate TRUE, an INSERT born inside the gate, and a write that clears the cell are all refused, while a row that was already missing the value keeps passing unrelated edits and state moves that stay inside the gate (ADR-0113 non-regression: adding the rule to a deployed object never bricks existing rows). Need an invariant every write must satisfy instead ('X may never exceed Y') — declare a `validations[]` `script` rule, which re-checks the merged record with no exemption. Enforced by `evaluateValidationRules`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every write that reaches it — `objectstack validate` refuses it; put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. The only slot; the `conditionalRequired` alias was removed in protocol 17. | @@ -642,7 +642,7 @@ Create a new object | **fields** | `Record; description?: string; … }>` | ✅ | Field definitions map. Keys must be snake_case identifiers; "__proto__", "constructor" and "prototype" are refused, and so is the "_sync_" prefix, reserved for the platform's sync-in columns. | | **attachedOnRead** | `Record>>` | optional | Blocks a service attaches to each row it serves, computed per caller on read and never stored: block name → `{ leaf key → value type (number \| text \| boolean \| date) }`. NOT a field — no column, form, list view, export, write path or translation bundle reads it, and a block name may not repeat a declared field name. Its reader is the shared build validator (`@objectstack/lint` over `@objectstack/formula`, as `os build` / `os validate` run it), and only where `record` is a row the service served: in an action's `visible` and `disabled` predicates `record.` resolves, and `record..` resolves only to a leaf the block declares. Every other expression site binds the stored row, which never carries a block — a flow condition, a validation rule, a field rule or formula, an option `visibleWhen`, a sharing rule, a hook — and refuses `record.` as an unknown field. | | **indexes** | `{ name?: string; fields: string[]; unique?: false \| 'global' \| 'organization' }[]` | optional | Database performance indexes | -| **fieldGroups** | `{ key: string; label: string; icon?: string; description?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | +| **fieldGroups** | `{ key: string; label: string; fields?: string[]; icon?: string; … }[]` | optional | Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema. | | **tenancy** | `{ enabled: boolean; tenantField?: string }` | optional | Multi-tenancy configuration for SaaS applications | | **access** | `{ default?: Enum<'public' \| 'private'> }` | optional | [ADR-0066 D2] Object exposure posture (public-by-default vs private secure-by-default). | | **requiredPermissions** | `string[] \| { read?: string[]; create?: string[]; update?: string[]; delete?: string[] }` | optional | [ADR-0066 D3/⑤] Capabilities required to access this object (AND-gate) — `string[]` gates all CRUD, or a `{read,create,update,delete}` map gates per operation. | diff --git a/packages/spec/api-surface/data.json b/packages/spec/api-surface/data.json index 29a7899c83d..79f5403adef 100644 --- a/packages/spec/api-surface/data.json +++ b/packages/spec/api-surface/data.json @@ -326,6 +326,7 @@ "Field (const)", "Field (type)", "FieldGroupCollapse (type)", + "FieldGroupMembership (interface)", "FieldGroupSection (interface)", "FieldGroupVisibleWhen (type)", "FieldInput (type)", @@ -1136,6 +1137,7 @@ "provisionPrimary (function)", "readAutonumberCounter (function)", "readBooleanComparand (function)", + "readFieldGroupMembership (function)", "readNumericString (function)", "recordCurrencyDynamicRollupNotHomeError (function)", "recordCurrencyFollowedCodeError (function)", diff --git a/packages/spec/export-origins/data.json b/packages/spec/export-origins/data.json index b7daac2b794..682f418df6d 100644 --- a/packages/spec/export-origins/data.json +++ b/packages/spec/export-origins/data.json @@ -318,6 +318,7 @@ "FeedItemType": "src/data/feed.zod.ts#FeedItemType (type)", "Field": "src/data/field.zod.ts#Field (type)", "FieldGroupCollapse": "src/data/field-group-layout.ts#FieldGroupCollapse (type)", + "FieldGroupMembership": "src/data/field-group-layout.ts#FieldGroupMembership (interface)", "FieldGroupSection": "src/data/field-group-layout.ts#FieldGroupSection (interface)", "FieldGroupVisibleWhen": "src/data/field-group-layout.ts#FieldGroupVisibleWhen (type)", "FieldInput": "src/data/field.zod.ts#FieldInput (type)", @@ -1121,6 +1122,7 @@ "provisionPrimary": "src/data/display-name.ts#provisionPrimary (function)", "readAutonumberCounter": "src/data/autonumber-format.ts#readAutonumberCounter (function)", "readBooleanComparand": "src/data/filter-boolean-comparand-declared-type.ts#readBooleanComparand (function)", + "readFieldGroupMembership": "src/data/field-group-layout.ts#readFieldGroupMembership (function)", "readNumericString": "src/data/filter-number-comparand-declared-type.ts#readNumericString (function)", "recordCurrencyDynamicRollupNotHomeError": "src/data/record-currency-path.ts#recordCurrencyDynamicRollupNotHomeError (function)", "recordCurrencyFollowedCodeError": "src/data/record-currency-path.ts#recordCurrencyFollowedCodeError (function)", diff --git a/packages/spec/liveness/object.json b/packages/spec/liveness/object.json index d137d0b8917..bd8576f2b7a 100644 --- a/packages/spec/liveness/object.json +++ b/packages/spec/liveness/object.json @@ -82,6 +82,13 @@ "evidence": "packages/spec/src/data/field-group-layout.ts#deriveFieldGroupLayout (`label ?? key`); ui/packages/plugin-form/src/fieldGroups.ts#deriveFieldGroupSections (the form section title); ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts#deriveFieldGroupDetailEntries (the detail section label)", "note": "The group heading on forms and detail pages." }, + "fields": { + "status": "live", + "verifiedAt": "2026-11-20", + "evidenceScope": "in-repo", + "evidence": "packages/spec/src/data/field-group-layout.ts#readGroup (reads the list, not on a relatedList group); packages/spec/src/data/field-group-layout.ts#resolveFieldGroupMembership (listed fields join the group in list order, before any field whose own `group` names it); ui/packages/plugin-form/src/fieldGroups.ts#deriveFieldGroupSections and ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts (both pass `fieldGroups` through to deriveFieldGroupLayout)", + "note": "A group's own member list and order. Absent, membership is the older `Field.group` plus declaration order. Read by the one shared derivation every form, drawer and detail surface consumes; the Studio designer writes it on a drag (writeGroupLayout)." + }, "icon": { "status": "live", "verifiedAt": "2026-10-28", diff --git a/packages/spec/liveness/state-counts/object.md b/packages/spec/liveness/state-counts/object.md index f7694a6959c..05655a3b5b8 100644 --- a/packages/spec/liveness/state-counts/object.md +++ b/packages/spec/liveness/state-counts/object.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `object` | 83 | 0 | 0 | 2 | 2 | 87 | +| `object` | 84 | 0 | 0 | 2 | 2 | 88 | From 53409dca9ead9d2e0cd36624168027b043e6f82a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 18:23:00 +0000 Subject: [PATCH 06/10] feat(spec): the object form edits a group's fields list Adds the Fields row to the metadata form's field-group sub-form, flips the batch20 pin that expected fieldGroups[].fields to be refused, and regenerates the translation bundles (zh-CN translated). Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .../translations/ar.metadata-forms.generated.ts | 4 ++++ .../translations/ar.source-hashes.generated.ts | 2 ++ .../translations/de.metadata-forms.generated.ts | 4 ++++ .../translations/de.source-hashes.generated.ts | 2 ++ .../translations/en.metadata-forms.generated.ts | 6 +++++- .../translations/es-ES.metadata-forms.generated.ts | 4 ++++ .../translations/es-ES.source-hashes.generated.ts | 2 ++ .../translations/fr.metadata-forms.generated.ts | 4 ++++ .../translations/fr.source-hashes.generated.ts | 2 ++ .../translations/ja-JP.metadata-forms.generated.ts | 4 ++++ .../translations/ja-JP.source-hashes.generated.ts | 2 ++ .../translations/ko.metadata-forms.generated.ts | 4 ++++ .../translations/ko.source-hashes.generated.ts | 2 ++ .../translations/pt-BR.metadata-forms.generated.ts | 4 ++++ .../translations/pt-BR.source-hashes.generated.ts | 2 ++ .../translations/ru.metadata-forms.generated.ts | 4 ++++ .../translations/ru.source-hashes.generated.ts | 2 ++ .../translations/zh-CN.metadata-forms.generated.ts | 4 ++++ .../zh-Hant.metadata-forms.generated.ts | 4 ++++ .../zh-Hant.source-hashes.generated.ts | 2 ++ .../src/data/object-strictness-batch20.test.ts | 14 ++++++++++---- packages/spec/src/data/object.form.ts | 8 +++++--- 22 files changed, 78 insertions(+), 8 deletions(-) diff --git a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts index ef6e1232aea..b3fc8699396 100644 --- a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const arMetadataForms: NonNullable = { label: "التسمية", helpText: "نص ترويسة قسم المجموعة." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "الأيقونة", helpText: "اسم أيقونة Lucide يظهر بجانب الترويسة في صفحة تفاصيل السجل (مثل \"banknote\"). لا يعرضها نموذج الإدخال." diff --git a/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts index d479df87bc1..7fd49873ab7 100644 --- a/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts @@ -20,6 +20,8 @@ export const arGeneratedSourceHashes: Readonly> = { "metadataForms.email_template.fields.fromOverride.helpText": "c5e29fa12ee1525b", "metadataForms.email_template.fields.variables.helpText": "27197774c2cda633", + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", "metadataForms.permission.fields.objects.helpText": "e2512cfb3b501aae", "metadataForms.permission.fields.tabPermissions.helpText": "8942e2aebe59897c", diff --git a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts index 414d5d22502..125b5fba53e 100644 --- a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const deMetadataForms: NonNullable = { label: "Bezeichnung", helpText: "Überschrift des Abschnitts der Gruppe." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "Symbol", helpText: "Name des Lucide-Symbols, das neben der Überschrift auf der Datensatz-Detailseite angezeigt wird (z. B. „banknote“). Das Eingabeformular zeigt es nicht." diff --git a/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts index 5b0371a36b6..b47fb92aa53 100644 --- a/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts @@ -51,6 +51,8 @@ export const deGeneratedSourceHashes: Readonly> = { "metadataForms.hook.fields.refusals.status.label": "64a420165247654b", "metadataForms.hook.label": "248bb1cdc692252d", "metadataForms.object.fields.enable.feeds.label": "669c64671f632139", + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.object.fields.lifecycle.storage.shards.label": "739988affb36b2e0", "metadataForms.object.fields.name.label": "5274417ff1ccaf01", "metadataForms.object.fields.userActions.import.label": "05c80d3a61ec3290", diff --git a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts index 0232e8c3966..4b9945f618c 100644 --- a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts @@ -82,7 +82,7 @@ export const enMetadataForms: NonNullable = { }, fieldGroups: { label: "Field Groups", - helpText: "Ordered sections that group this object's fields on the entry form and the record detail page (ADR-0085); array order is display order. A field joins a group by naming its key in the field's own group setting. Fields in no group follow the groups, and a group no field joins is not drawn." + helpText: "Ordered sections that group this object's fields on the entry form and the record detail page (ADR-0085); array order is display order. A group lists its fields, in order, in its Fields setting; a group without that list holds the fields that name its key in their own group setting. Fields in no group follow the groups, and a group no field joins is not drawn." }, "fieldGroups.key": { label: "Key", @@ -92,6 +92,10 @@ export const enMetadataForms: NonNullable = { label: "Label", helpText: "Header text of the group's section." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "Icon", helpText: "Lucide icon name shown beside the header on the record detail page (e.g. \"banknote\"). The entry form does not show it." diff --git a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts index 3f978b6e41c..aadbc6c3b74 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const esESMetadataForms: NonNullable = label: "Etiqueta", helpText: "Texto del encabezado de la sección del grupo." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "Icono", helpText: "Nombre de icono Lucide que se muestra junto al encabezado en la página de detalle del registro (p. ej., \"banknote\"). El formulario de entrada no lo muestra." diff --git a/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts index 16a789fc601..f5c8cd4235b 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts @@ -18,6 +18,8 @@ */ export const esESGeneratedSourceHashes: Readonly> = { + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "objects.sys_email.fields.cc_addresses.label": "02946d952cf15623", "objects.sys_email.fields.error.label": "786fed84bd8d5a32", "objects.sys_email.fields.message_id.label": "14cd089a4062f4b1", diff --git a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts index c8e95ad7efc..2524d6d93e6 100644 --- a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const frMetadataForms: NonNullable = { label: "Libellé", helpText: "Texte de l’en-tête de la section du groupe." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "Icône", helpText: "Nom d’icône Lucide affiché à côté de l’en-tête sur la page de détail de l’enregistrement (par ex. « banknote »). Le formulaire de saisie ne l’affiche pas." diff --git a/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts index 0ce08db8d83..1a61da36059 100644 --- a/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts @@ -72,6 +72,8 @@ export const frGeneratedSourceHashes: Readonly> = { "metadataForms.hook.fields.texts.message.label": "2af15199795c25b9", "metadataForms.hook.label": "248bb1cdc692252d", "metadataForms.object.fields.description.label": "779a4342c8eb6707", + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.object.fields.fields.description.label": "779a4342c8eb6707", "metadataForms.object.fields.fields.expression.label": "cd1b52ad1588075e", "metadataForms.object.fields.fields.max.label": "8081d808ef64ff91", diff --git a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts index 30bdf25fa1e..3421ad16285 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const jaJPMetadataForms: NonNullable = label: "表示名", helpText: "グループのセクションの見出しテキスト。" }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "アイコン", helpText: "レコード詳細ページで見出しの横に表示される Lucide アイコン名(例:\"banknote\")。入力フォームには表示されません。" diff --git a/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts index 45d2394e914..07318149ef1 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts @@ -18,6 +18,8 @@ */ export const jaJPGeneratedSourceHashes: Readonly> = { + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "objects.sys_email.fields.bcc_addresses.label": "8674899b7b6d5126", "objects.sys_email.fields.cc_addresses.label": "02946d952cf15623", "objects.sys_email.fields.message_id.label": "14cd089a4062f4b1", diff --git a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts index 4a69b1d0e90..4660c9b0439 100644 --- a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const koMetadataForms: NonNullable = { label: "레이블", helpText: "그룹 섹션의 헤더 텍스트입니다." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "아이콘", helpText: "레코드 상세 페이지에서 헤더 옆에 표시되는 Lucide 아이콘 이름(예: \"banknote\")입니다. 입력 양식에는 표시되지 않습니다." diff --git a/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts index fa0559d9bbc..89642d4656d 100644 --- a/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts @@ -20,6 +20,8 @@ export const koGeneratedSourceHashes: Readonly> = { "metadataForms.email_template.fields.fromOverride.helpText": "c5e29fa12ee1525b", "metadataForms.email_template.fields.variables.helpText": "27197774c2cda633", + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", "metadataForms.permission.fields.objects.helpText": "e2512cfb3b501aae", "metadataForms.permission.fields.tabPermissions.helpText": "8942e2aebe59897c", diff --git a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts index 5ae7d84d63f..8a8c722e3e1 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const ptBRMetadataForms: NonNullable = label: "Rótulo", helpText: "Texto do cabeçalho da seção do grupo." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "Ícone", helpText: "Nome do ícone Lucide exibido ao lado do cabeçalho na página de detalhes do registro (por exemplo \"banknote\"). O formulário de entrada não o exibe." diff --git a/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts index 7b83f1bca2c..5af3de3e7d0 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts @@ -33,6 +33,8 @@ export const ptBRGeneratedSourceHashes: Readonly> = { "metadataForms.hook.fields.refusals.status.label": "64a420165247654b", "metadataForms.hook.label": "248bb1cdc692252d", "metadataForms.object.fields.enable.feeds.label": "669c64671f632139", + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.object.fields.lifecycle.storage.shards.label": "739988affb36b2e0", "metadataForms.page.sections.layout.label": "7f508ea1bb2c3a6b", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", diff --git a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts index 868424dccfa..9a528e5da90 100644 --- a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const ruMetadataForms: NonNullable = { label: "Метка", helpText: "Текст заголовка раздела группы." }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "Значок", helpText: "Имя значка Lucide, показываемого рядом с заголовком на странице записи (например, \"banknote\"). Форма ввода его не показывает." diff --git a/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts index 448291c5695..32ebf1714f4 100644 --- a/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts @@ -20,6 +20,8 @@ export const ruGeneratedSourceHashes: Readonly> = { "metadataForms.email_template.fields.fromOverride.helpText": "c5e29fa12ee1525b", "metadataForms.email_template.fields.variables.helpText": "27197774c2cda633", + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", "metadataForms.permission.fields.objects.helpText": "e2512cfb3b501aae", "metadataForms.permission.fields.tabPermissions.helpText": "8942e2aebe59897c", diff --git a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts index 20e2ad4b211..8a911f5c8ba 100644 --- a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const zhCNMetadataForms: NonNullable = label: "显示名称", helpText: "该分组所在分区的标题文字。" }, + "fieldGroups.fields": { + label: "字段", + helpText: "该分组显示的字段及其顺序(字段名)。填写后,它决定分组内的顺序,不移动任何字段。这里列出的字段,其自身的分组设置不能指向别的分组;一个字段只能被一个分组列出。不能与关联列表同时使用。" + }, "fieldGroups.icon": { label: "图标", helpText: "在记录详情页的标题旁显示的 Lucide 图标名称(例如 \"banknote\")。录入表单不显示它。" diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts index 5ca0d588b77..e5149df9ffc 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts @@ -92,6 +92,10 @@ export const zhHantMetadataForms: NonNullable label: "顯示名稱", helpText: "該分組所在分割區的標題文字。" }, + "fieldGroups.fields": { + label: "Fields", + helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + }, "fieldGroups.icon": { label: "圖示", helpText: "在記錄詳細資料頁面的標題旁顯示的 Lucide 圖示名稱(例如 \"banknote\")。輸入表單不顯示它。" diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts index ddfb741fe91..4fd107c78a5 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts @@ -18,6 +18,8 @@ */ export const zhHantGeneratedSourceHashes: Readonly> = { + "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", + "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "objects.sys_email.fields.message_id.label": "14cd089a4062f4b1", "objects.sys_email_template.fields.id.label": "00b0385c9c152888", "objects.sys_exchange_rate.fields.id.label": "00b0385c9c152888", diff --git a/packages/spec/src/data/object-strictness-batch20.test.ts b/packages/spec/src/data/object-strictness-batch20.test.ts index a387452499a..17fe93b462d 100644 --- a/packages/spec/src/data/object-strictness-batch20.test.ts +++ b/packages/spec/src/data/object-strictness-batch20.test.ts @@ -456,10 +456,16 @@ describe('批 20, unknown keys refused — curation is anchored to the sibling c accept(ObjectSchema, { ...OBJ, enable: { clone: false } }); }); - it('`fieldGroups[].fields` states the direction of the membership edge', () => { - const msg = rejectOnObject({ fieldGroups: [{ key: 'g', label: 'G', fields: ['name'] }] }); - expect(msg).toContain('group'); - // The claim: membership really is declared on the FIELD. + // `fieldGroups[].fields` left this list: it is a real key now (a group + // lists its own members, `ObjectFieldGroupSchema.fields`), so the pin that + // refused it and pointed at `Field.group` flips to acceptance of BOTH + // spellings — the older one is still read. + it('`fieldGroups[].fields` is a real key now, and the older `Field.group` still parses', () => { + accept(ObjectSchema, { + ...OBJ, + fields: { name: { type: 'text', label: 'Name' } }, + fieldGroups: [{ key: 'g', label: 'G', fields: ['name'] }], + }); accept(ObjectSchema, { ...OBJ, fields: { name: { type: 'text', label: 'Name', group: 'g' } }, diff --git a/packages/spec/src/data/object.form.ts b/packages/spec/src/data/object.form.ts index b416e4bfe00..0d9a70d6f1c 100644 --- a/packages/spec/src/data/object.form.ts +++ b/packages/spec/src/data/object.form.ts @@ -98,16 +98,18 @@ export const objectForm = defineForm({ // outranks it (the parse derives `collapse` from an alias only when // `collapse` is absent). // - // No field-name list lives here: a field joins a group through its own - // `group` key, so there is no name for a misspelling to hide in. + // `fields` is the group's own member list (field names, in display + // order), a `tags` row as `hook.form.ts` gives a list of names; a name + // no field declares is skipped by the layout and warned by `os lint`. { field: 'fieldGroups', type: 'repeater', colSpan: 2, - helpText: 'Ordered sections that group this object\'s fields on the entry form and the record detail page (ADR-0085); array order is display order. A field joins a group by naming its key in the field\'s own group setting. Fields in no group follow the groups, and a group no field joins is not drawn.', + helpText: 'Ordered sections that group this object\'s fields on the entry form and the record detail page (ADR-0085); array order is display order. A group lists its fields, in order, in its Fields setting; a group without that list holds the fields that name its key in their own group setting. Fields in no group follow the groups, and a group no field joins is not drawn.', fields: [ { field: 'key', label: 'Key', type: 'text', required: true, helpText: 'Machine key in snake_case, unique within this object — the schema refuses anything else. Fields join the group by naming this key, so renaming it leaves them ungrouped.' }, { field: 'label', label: 'Label', type: 'text', required: true, helpText: 'Header text of the group\'s section.' }, + { field: 'fields', label: 'Fields', type: 'tags', helpText: 'The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List.' }, { field: 'icon', label: 'Icon', type: 'text', helpText: 'Lucide icon name shown beside the header on the record detail page (e.g. "banknote"). The entry form does not show it.' }, { field: 'description', label: 'Description', type: 'textarea', helpText: 'Text shown under the header, on the entry form and the record detail page.' }, { field: 'relatedList', label: 'Related List', type: 'text', helpText: 'Makes this entry a related list\'s table instead of a section of fields: name the child object (or object.field) whose list is drawn at this position in the record\'s details column. Such a group holds no fields; a field that names it as its group is refused, and so is a name that matches no relationship pointing at this object. The record page does not draw this placement yet.' }, From c982c3719928d7003a55d18320825a7def8f7a67 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 19:14:36 +0000 Subject: [PATCH 07/10] chore(changeset): list @objectstack/platform-objects for the regenerated form bundles Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .changeset/35900-field-group-members.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/35900-field-group-members.md b/.changeset/35900-field-group-members.md index 30ccaeec1a6..9b8bb19eb1d 100644 --- a/.changeset/35900-field-group-members.md +++ b/.changeset/35900-field-group-members.md @@ -2,6 +2,7 @@ '@objectstack/spec': minor '@objectstack/lint': minor '@object-ui/app-shell': minor +'@objectstack/platform-objects': minor --- feat(spec): a field group lists its own members and their order (`fieldGroups[].fields`) From ffc028165b1ad35ea6c908a8e94eb64e67e40934 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 19:33:46 +0000 Subject: [PATCH 08/10] fix(i18n): translate the group Fields row in every locale; move the two derived count pins The new fieldGroups.fields sub-row of the object form carried the English source in nine translated locales, which the echo ledgers refuse. Each locale now has its own text, and the open-leaf and translated-leaf counts move by the new row. Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .../src/apps/translations/ar.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/ar.source-hashes.generated.ts | 2 -- .../src/apps/translations/de.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/de.source-hashes.generated.ts | 2 -- .../src/apps/translations/es-ES.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/es-ES.source-hashes.generated.ts | 2 -- .../src/apps/translations/fr.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/fr.source-hashes.generated.ts | 2 -- .../src/apps/translations/ja-JP.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/ja-JP.source-hashes.generated.ts | 2 -- .../src/apps/translations/ko.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/ko.source-hashes.generated.ts | 2 -- .../object-collapsed-sections-echo-decisions.test.ts | 5 ++++- .../object-lifecycle-panel-echo-decisions.test.ts | 5 ++++- .../src/apps/translations/pt-BR.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/pt-BR.source-hashes.generated.ts | 2 -- .../src/apps/translations/ru.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/ru.source-hashes.generated.ts | 2 -- .../apps/translations/zh-Hant.metadata-forms.generated.ts | 4 ++-- .../src/apps/translations/zh-Hant.source-hashes.generated.ts | 2 -- 20 files changed, 26 insertions(+), 38 deletions(-) diff --git a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts index b3fc8699396..ebc95f41d89 100644 --- a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const arMetadataForms: NonNullable = { helpText: "نص ترويسة قسم المجموعة." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "الحقول", + helpText: "الحقول التي تعرضها هذه المجموعة، بترتيب العرض (أسماء الحقول). عند تعبئتها تحدد الترتيب داخل المجموعة دون نقل أي حقل. لا يجوز للحقل المذكور هنا أن يشير إلى مجموعة أخرى في إعداد المجموعة الخاص به، ولا يُذكر الحقل إلا في مجموعة واحدة. غير مسموح مع القائمة المرتبطة." }, "fieldGroups.icon": { label: "الأيقونة", diff --git a/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts index 7fd49873ab7..d479df87bc1 100644 --- a/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.source-hashes.generated.ts @@ -20,8 +20,6 @@ export const arGeneratedSourceHashes: Readonly> = { "metadataForms.email_template.fields.fromOverride.helpText": "c5e29fa12ee1525b", "metadataForms.email_template.fields.variables.helpText": "27197774c2cda633", - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", "metadataForms.permission.fields.objects.helpText": "e2512cfb3b501aae", "metadataForms.permission.fields.tabPermissions.helpText": "8942e2aebe59897c", diff --git a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts index 125b5fba53e..c49aa0d7c7b 100644 --- a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const deMetadataForms: NonNullable = { helpText: "Überschrift des Abschnitts der Gruppe." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "Felder", + helpText: "Die Felder, die diese Gruppe anzeigt, in Anzeigereihenfolge (Feldnamen). Ausgefüllt legt die Liste die Reihenfolge innerhalb der Gruppe fest, ohne ein Feld zu verschieben. Ein hier genanntes Feld darf in seiner eigenen Gruppeneinstellung keine andere Gruppe nennen, und ein Feld darf nur von einer Gruppe aufgeführt werden. Nicht zulässig zusammen mit Verknüpfte Liste." }, "fieldGroups.icon": { label: "Symbol", diff --git a/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts index b47fb92aa53..5b0371a36b6 100644 --- a/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.source-hashes.generated.ts @@ -51,8 +51,6 @@ export const deGeneratedSourceHashes: Readonly> = { "metadataForms.hook.fields.refusals.status.label": "64a420165247654b", "metadataForms.hook.label": "248bb1cdc692252d", "metadataForms.object.fields.enable.feeds.label": "669c64671f632139", - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.object.fields.lifecycle.storage.shards.label": "739988affb36b2e0", "metadataForms.object.fields.name.label": "5274417ff1ccaf01", "metadataForms.object.fields.userActions.import.label": "05c80d3a61ec3290", diff --git a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts index aadbc6c3b74..7a648072388 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const esESMetadataForms: NonNullable = helpText: "Texto del encabezado de la sección del grupo." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "Campos", + helpText: "Los campos que muestra este grupo, en orden de visualización (nombres de campo). Si se rellena, fija el orden dentro del grupo sin mover ningún campo. Un campo que esta lista nombra no puede indicar otro grupo en su propio ajuste de grupo, y un campo solo puede figurar en un grupo. No se permite junto con Lista relacionada." }, "fieldGroups.icon": { label: "Icono", diff --git a/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts index f5c8cd4235b..16a789fc601 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.source-hashes.generated.ts @@ -18,8 +18,6 @@ */ export const esESGeneratedSourceHashes: Readonly> = { - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "objects.sys_email.fields.cc_addresses.label": "02946d952cf15623", "objects.sys_email.fields.error.label": "786fed84bd8d5a32", "objects.sys_email.fields.message_id.label": "14cd089a4062f4b1", diff --git a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts index 2524d6d93e6..914bcde3a4a 100644 --- a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const frMetadataForms: NonNullable = { helpText: "Texte de l’en-tête de la section du groupe." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "Champs", + helpText: "Les champs que ce groupe affiche, dans l'ordre d'affichage (noms de champ). Renseignée, la liste fixe l'ordre à l'intérieur du groupe sans déplacer aucun champ. Un champ nommé ici ne peut pas indiquer un autre groupe dans son propre réglage de groupe, et un champ ne peut être listé que par un seul groupe. Non autorisé avec Liste associée." }, "fieldGroups.icon": { label: "Icône", diff --git a/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts index 1a61da36059..0ce08db8d83 100644 --- a/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.source-hashes.generated.ts @@ -72,8 +72,6 @@ export const frGeneratedSourceHashes: Readonly> = { "metadataForms.hook.fields.texts.message.label": "2af15199795c25b9", "metadataForms.hook.label": "248bb1cdc692252d", "metadataForms.object.fields.description.label": "779a4342c8eb6707", - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.object.fields.fields.description.label": "779a4342c8eb6707", "metadataForms.object.fields.fields.expression.label": "cd1b52ad1588075e", "metadataForms.object.fields.fields.max.label": "8081d808ef64ff91", diff --git a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts index 3421ad16285..ef167963419 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const jaJPMetadataForms: NonNullable = helpText: "グループのセクションの見出しテキスト。" }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "フィールド", + helpText: "このグループが表示するフィールドと表示順(フィールド名)。入力すると、どのフィールドも移動せずにグループ内の順序が決まります。ここに挙げたフィールドは、自身のグループ設定で別のグループを指定できません。また、1 つのフィールドを挙げられるのは 1 つのグループだけです。関連リストとは併用できません。" }, "fieldGroups.icon": { label: "アイコン", diff --git a/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts index 07318149ef1..45d2394e914 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.source-hashes.generated.ts @@ -18,8 +18,6 @@ */ export const jaJPGeneratedSourceHashes: Readonly> = { - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "objects.sys_email.fields.bcc_addresses.label": "8674899b7b6d5126", "objects.sys_email.fields.cc_addresses.label": "02946d952cf15623", "objects.sys_email.fields.message_id.label": "14cd089a4062f4b1", diff --git a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts index 4660c9b0439..f637322728e 100644 --- a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const koMetadataForms: NonNullable = { helpText: "그룹 섹션의 헤더 텍스트입니다." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "필드", + helpText: "이 그룹이 표시하는 필드와 표시 순서(필드 이름)입니다. 입력하면 어떤 필드도 옮기지 않고 그룹 안의 순서를 정합니다. 여기에 나열한 필드는 자체 그룹 설정에서 다른 그룹을 지정할 수 없으며, 한 필드는 한 그룹에만 나열할 수 있습니다. 관련 목록과 함께 사용할 수 없습니다." }, "fieldGroups.icon": { label: "아이콘", diff --git a/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts index 89642d4656d..fa0559d9bbc 100644 --- a/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.source-hashes.generated.ts @@ -20,8 +20,6 @@ export const koGeneratedSourceHashes: Readonly> = { "metadataForms.email_template.fields.fromOverride.helpText": "c5e29fa12ee1525b", "metadataForms.email_template.fields.variables.helpText": "27197774c2cda633", - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", "metadataForms.permission.fields.objects.helpText": "e2512cfb3b501aae", "metadataForms.permission.fields.tabPermissions.helpText": "8942e2aebe59897c", diff --git a/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts b/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts index d50e714d720..0eb27dced01 100644 --- a/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts +++ b/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts @@ -989,7 +989,10 @@ describe('#19403 round 8 — the population, DERIVED from the form and a shape', // 124 since #30692 gave the `fieldGroups` repeater its `requiresFeature` // sub-row (the deployment feature a group needs) — label and help text, // authored in all three locales, so `openEchoes` stays at zero. - expect(OPEN_LEAVES.length).toBe(124); + // 126 since #35900 gave the `fieldGroups` repeater its `fields` sub-row + // (the group's own member list) — label and help text, authored in every + // translated locale by that card, so `openEchoes` stays at zero. + expect(OPEN_LEAVES.length).toBe(126); expect(PANEL_LEAVES.some((l) => l.path === 'fields.placeholder')).toBe(false); expect(OPEN_LEAVES.some((l) => l.path === 'fields.placeholder')).toBe(true); for (const path of ['name', 'label', 'fields', 'fields.valueDomain', 'fields.deleteBehavior', 'fields.expression']) { diff --git a/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts b/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts index da1f6a43fdf..b783b9ef0fe 100644 --- a/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts +++ b/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts @@ -1297,7 +1297,10 @@ describe('#19403 round 10 — the verdicts, on the live bundles', () => { // three locales. // 754 since #34823: the action form offers the `refusals` record and its // five entry fields — six row labels, authored in all three locales. - expect(translated.length, `${locale} positive control`).toBe(754); + // 755 since #35900: the object form's `fieldGroups` repeater offers + // `fields` (the group's own member list) — one row label, authored in + // all three locales. + expect(translated.length, `${locale} positive control`).toBe(755); } // ⭐ DARK — the blindness, executable. On a synthetic two-locale catalog the // all-three predicate returns 0 while the per-locale one returns 1, so the diff --git a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts index 8a8c722e3e1..ece555d7d64 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const ptBRMetadataForms: NonNullable = helpText: "Texto do cabeçalho da seção do grupo." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "Campos", + helpText: "Os campos que este grupo exibe, na ordem de exibição (nomes de campo). Preenchida, a lista define a ordem dentro do grupo sem mover nenhum campo. Um campo citado aqui não pode indicar outro grupo na sua própria configuração de grupo, e um campo só pode ser listado por um grupo. Não permitido junto com Lista relacionada." }, "fieldGroups.icon": { label: "Ícone", diff --git a/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts index 5af3de3e7d0..7b83f1bca2c 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.source-hashes.generated.ts @@ -33,8 +33,6 @@ export const ptBRGeneratedSourceHashes: Readonly> = { "metadataForms.hook.fields.refusals.status.label": "64a420165247654b", "metadataForms.hook.label": "248bb1cdc692252d", "metadataForms.object.fields.enable.feeds.label": "669c64671f632139", - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.object.fields.lifecycle.storage.shards.label": "739988affb36b2e0", "metadataForms.page.sections.layout.label": "7f508ea1bb2c3a6b", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", diff --git a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts index 9a528e5da90..a85f9f5660c 100644 --- a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const ruMetadataForms: NonNullable = { helpText: "Текст заголовка раздела группы." }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "Поля", + helpText: "Поля, которые показывает эта группа, в порядке отображения (имена полей). Если список заполнен, он задаёт порядок внутри группы, не перемещая ни одно поле. Поле из этого списка не может указывать другую группу в собственной настройке группы, и поле может быть указано только одной группой. Нельзя использовать вместе со связанным списком." }, "fieldGroups.icon": { label: "Значок", diff --git a/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts index 32ebf1714f4..448291c5695 100644 --- a/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.source-hashes.generated.ts @@ -20,8 +20,6 @@ export const ruGeneratedSourceHashes: Readonly> = { "metadataForms.email_template.fields.fromOverride.helpText": "c5e29fa12ee1525b", "metadataForms.email_template.fields.variables.helpText": "27197774c2cda633", - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "metadataForms.permission.fields.fields.helpText": "887a0bae04a950e2", "metadataForms.permission.fields.objects.helpText": "e2512cfb3b501aae", "metadataForms.permission.fields.tabPermissions.helpText": "8942e2aebe59897c", diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts index e5149df9ffc..cbe340434f0 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts @@ -93,8 +93,8 @@ export const zhHantMetadataForms: NonNullable helpText: "該分組所在分割區的標題文字。" }, "fieldGroups.fields": { - label: "Fields", - helpText: "The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List." + label: "欄位", + helpText: "此分組顯示的欄位及其順序(欄位名稱)。填寫後,它決定分組內的順序,不移動任何欄位。此處列出的欄位,其自身的分組設定不能指向其他分組;一個欄位只能被一個分組列出。不能與相關清單同時使用。" }, "fieldGroups.icon": { label: "圖示", diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts index 4fd107c78a5..ddfb741fe91 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.source-hashes.generated.ts @@ -18,8 +18,6 @@ */ export const zhHantGeneratedSourceHashes: Readonly> = { - "metadataForms.object.fields.fieldGroups.fields.helpText": "c63503d01551c816", - "metadataForms.object.fields.fieldGroups.fields.label": "f316ec6025047133", "objects.sys_email.fields.message_id.label": "14cd089a4062f4b1", "objects.sys_email_template.fields.id.label": "00b0385c9c152888", "objects.sys_exchange_rate.fields.id.label": "00b0385c9c152888", From ebcbc4932206f1d808a9017a4cce18360f035d64 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 19:49:30 +0000 Subject: [PATCH 09/10] docs: a group lists its own fields; the record:details group reference names the list order Adds the fieldGroups[].fields section to the field grouping page, and corrects the record:details sections[].group description (and its renderer comment), which still said a referenced group's members come in declaration order. Manifest and component reference regenerated. Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .changeset/35900-field-group-members.md | 1 + content/docs/ui/components/record.mdx | 2 +- content/docs/ui/field-grouping-and-order.mdx | 24 +++++++++++++++++++ scripts/sdui-manifest.record.json | 4 ++-- sdui.manifest.json | 2 +- ui/packages/plugin-detail/src/index.tsx | 2 +- .../src/renderers/record-details.tsx | 5 ++-- 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.changeset/35900-field-group-members.md b/.changeset/35900-field-group-members.md index 9b8bb19eb1d..e1270a50e07 100644 --- a/.changeset/35900-field-group-members.md +++ b/.changeset/35900-field-group-members.md @@ -3,6 +3,7 @@ '@objectstack/lint': minor '@object-ui/app-shell': minor '@objectstack/platform-objects': minor +'@object-ui/plugin-detail': minor --- feat(spec): a field group lists its own members and their order (`fieldGroups[].fields`) diff --git a/content/docs/ui/components/record.mdx b/content/docs/ui/components/record.mdx index e4b7c7a98d6..69828015672 100644 --- a/content/docs/ui/components/record.mdx +++ b/content/docs/ui/components/record.mdx @@ -54,7 +54,7 @@ Namespace `record`. | Input | Type | Required | Description | | :--- | :--- | :--- | :--- | | `columns` | `enum`: `1`, `2`, `3`, `4` | | Number of columns for field layout (1-4) | -| `sections` | `array` of `object` | | Field groups rendered as the detail body, in order. Every entry is an OBJECT — `{ name?, label?, columns?, fields }` — a bare section-id string is NOT accepted (the spec retired that spelling in objectstack#5611, and the renderer reads name/label/fields off each entry, so a string entry renders no fields at all). `fields` are the field names shown in this section, in order — required unless `group` supplies the members instead (the spec refuses a section carrying neither, and refuses one carrying both). `label` is the section heading; omit it for an untitled, borderless section. `name` is a stable snake_case identifier and the i18n anchor — the heading resolves through objects.\._sections.\.label, so a section without a name shows its authored label in every locale. `columns` (1-4) is THIS section's field-grid width; omit it and the renderer derives the width. Authoring `sections` at all makes it the only source of the detail body; omit it and the body falls back to the object's highlightFields. @objectstack/spec 17.3.0 declares eight more member keys on an entry, and this renderer honours all eight: `icon` (a Lucide name on the section header), `description` (sub-heading copy under the heading), `collapsible` and `defaultCollapsed` (a foldable section and its initial state), `showBorder` (force the Card wrapper on or off, overriding the heading-derived default) and `headerColor` (a header tint from the shared palette) through DetailSection, plus `group` — the ADR-0085 §5 REFERENCE form, the alternative to enumerating `fields`. `{ group: 'contact_info' }` inherits the object's `fieldGroups` entry with that key: its members (every visible field pointing at it, in declaration order), its presentation (label, icon, description, collapse) and its `visibleWhen` all come from the group, so the section restates none of it — the predicate is evaluated against the bound record exactly as the entry form evaluates it, and a group it hides renders nothing (a `visibleWhen` written on a section itself is refused by the spec and not read: gate the group and reference it) and the spec refuses those keys beside `group`; `columns`, `showBorder` and `headerColor` stay yours because they are how THIS page lays the section out. A `group` naming no declared group renders nothing and is reported to the console (`@objectstack/lint` flags it as `page-section-group-unknown`). `hideEmpty` is the eighth, and it decides whether an ALL-empty section exists: it defaults to on, so a section whose fields are every one of them empty renders nothing at all — no heading, no skeleton — and `hideEmpty: false` is the spelling that keeps the section on a brand-new record: in read-only mode named in the one line that closes the body, beside every other all-empty section kept this way, and expanding that line draws each in its place as its heading plus one fold row that counts the empty fields and reveals them on request (the same fold a partly-filled section uses, objectui#13386), in edit mode as every field an editable row. It decides ONLY the all-empty case; the empty rows of a section that still has a filled one belong to DetailSection's auto-hide heuristic plus the reader's show-empty toggle, which no authored value overrides in either polarity (objectui#7129 Q2-C), and inline-edit mode renders the section either way so its fields stay reachable. Restored under objectui#8603 (maintainer 2026-09-15) after objectui#7129 retired it on the premise, since falsified upstream, that the spec refused the key. None of the eight has a designer control yet; they are authorable in source mode only, tracked as a deferred feature. @objectstack/spec 18 declares a ninth, `count` (`{ field }`): the renderer fills the heading's `{{ count }}` hole with how many values that multi-value field holds on the current record — `{ name: 'tagging', label: '{{ count }} tags', count: { field: 'tags' }, fields: ['tags'] }` reads `3 tags` when three are selected. An absent or empty value counts 0; `count` changes only the heading, never whether the section renders, so with `hideEmpty` on an all-empty section is still absent. The hole is filled after the heading is translated, so each locale of an inline label map and a translated objects.\._sections.\.label write the same `{{ count }}`. The spec refuses `count` beside `group`, on a section with no `label`, and on a label with no hole; a heading on a section without `count` prints as written. Like the eight, `count` has no designer control yet. | +| `sections` | `array` of `object` | | Field groups rendered as the detail body, in order. Every entry is an OBJECT — `{ name?, label?, columns?, fields }` — a bare section-id string is NOT accepted (the spec retired that spelling in objectstack#5611, and the renderer reads name/label/fields off each entry, so a string entry renders no fields at all). `fields` are the field names shown in this section, in order — required unless `group` supplies the members instead (the spec refuses a section carrying neither, and refuses one carrying both). `label` is the section heading; omit it for an untitled, borderless section. `name` is a stable snake_case identifier and the i18n anchor — the heading resolves through objects.\._sections.\.label, so a section without a name shows its authored label in every locale. `columns` (1-4) is THIS section's field-grid width; omit it and the renderer derives the width. Authoring `sections` at all makes it the only source of the detail body; omit it and the body falls back to the object's highlightFields. @objectstack/spec 17.3.0 declares eight more member keys on an entry, and this renderer honours all eight: `icon` (a Lucide name on the section header), `description` (sub-heading copy under the heading), `collapsible` and `defaultCollapsed` (a foldable section and its initial state), `showBorder` (force the Card wrapper on or off, overriding the heading-derived default) and `headerColor` (a header tint from the shared palette) through DetailSection, plus `group` — the ADR-0085 §5 REFERENCE form, the alternative to enumerating `fields`. `{ group: 'contact_info' }` inherits the object's `fieldGroups` entry with that key: its members (the group's own `fields` list in its order, then every other visible field whose `group` names it, in declaration order), its presentation (label, icon, description, collapse) and its `visibleWhen` all come from the group, so the section restates none of it — the predicate is evaluated against the bound record exactly as the entry form evaluates it, and a group it hides renders nothing (a `visibleWhen` written on a section itself is refused by the spec and not read: gate the group and reference it) and the spec refuses those keys beside `group`; `columns`, `showBorder` and `headerColor` stay yours because they are how THIS page lays the section out. A `group` naming no declared group renders nothing and is reported to the console (`@objectstack/lint` flags it as `page-section-group-unknown`). `hideEmpty` is the eighth, and it decides whether an ALL-empty section exists: it defaults to on, so a section whose fields are every one of them empty renders nothing at all — no heading, no skeleton — and `hideEmpty: false` is the spelling that keeps the section on a brand-new record: in read-only mode named in the one line that closes the body, beside every other all-empty section kept this way, and expanding that line draws each in its place as its heading plus one fold row that counts the empty fields and reveals them on request (the same fold a partly-filled section uses, objectui#13386), in edit mode as every field an editable row. It decides ONLY the all-empty case; the empty rows of a section that still has a filled one belong to DetailSection's auto-hide heuristic plus the reader's show-empty toggle, which no authored value overrides in either polarity (objectui#7129 Q2-C), and inline-edit mode renders the section either way so its fields stay reachable. Restored under objectui#8603 (maintainer 2026-09-15) after objectui#7129 retired it on the premise, since falsified upstream, that the spec refused the key. None of the eight has a designer control yet; they are authorable in source mode only, tracked as a deferred feature. @objectstack/spec 18 declares a ninth, `count` (`{ field }`): the renderer fills the heading's `{{ count }}` hole with how many values that multi-value field holds on the current record — `{ name: 'tagging', label: '{{ count }} tags', count: { field: 'tags' }, fields: ['tags'] }` reads `3 tags` when three are selected. An absent or empty value counts 0; `count` changes only the heading, never whether the section renders, so with `hideEmpty` on an all-empty section is still absent. The hole is filled after the heading is translated, so each locale of an inline label map and a translated objects.\._sections.\.label write the same `{{ count }}`. The spec refuses `count` beside `group`, on a section with no `label`, and on a label with no hole; a heading on a section without `count` prints as written. Like the eight, `count` has no designer control yet. | | `fields` | `array` of `string` | | Explicit field list (overrides highlightFields) | | `hideFields` | `array` of `string` | | Field names to omit from the body — applied to the top-level `fields` list AND to every section's `fields`. Bare field names only. Authors rarely need it: the synth pipeline fills it with the fields already shown in `record:highlights`, and hand-authored pages get the same dedup live from HighlightFieldsContext, so its purpose is suppressing a field you do not want repeated (the page H1 title field is dropped for you too). Hiding every field of a section leaves that section out entirely. | | `inlineEdit` | `boolean` | | Offer the per-field double-click / pencil inline-edit affordances in the detail body. On by default, and an OPT-OUT only: the value is combined with the object's own editability (system, engine-owned, append-only and better-auth objects are not user-editable unless they opened userActions.edit) and with the server's effective API operation set for the object, so `false` always wins while `true` cannot open editing the platform refuses. The edit session and the atomic Save bar are hosted by the page, so one draft spans the highlights strip and this body. | diff --git a/content/docs/ui/field-grouping-and-order.mdx b/content/docs/ui/field-grouping-and-order.mdx index aba4a425c42..b1bdc7aa2c1 100644 --- a/content/docs/ui/field-grouping-and-order.mdx +++ b/content/docs/ui/field-grouping-and-order.mdx @@ -52,6 +52,30 @@ export const Contact = ObjectSchema.create({ }); ``` +A group can also **list its own members and their order** with `fields`. Written, the list wins: the group shows those fields in the list's order, whatever order the object declares them in, so a section can be reordered without moving any field (and without changing a list view's default columns). A field the list leaves out but whose own `group` names the group is shown after the listed ones; a group without `fields` keeps the rule above. `field.group` is the older spelling of the same membership and is still read. + +{/* os:check */} +```ts +import { ObjectSchema, Field } from '@objectstack/spec/data'; + +export const Contact = ObjectSchema.create({ + name: 'showcase_contact', + sharingModel: 'private', + label: 'Contact', + fieldGroups: [ + { key: 'contact', label: 'Contact', fields: ['email', 'name'] }, // Email first, then Full name + { key: 'status', label: 'Status', fields: ['stage'] }, + ], + fields: { + name: Field.text({ label: 'Full name' }), + email: Field.email({ label: 'Email' }), + stage: Field.select({ label: 'Stage', options: [{ label: 'New', value: 'new' }] }), + }, +}); +``` + +The two spellings must agree. The object is refused when a field one group lists names another group in its own `group`, when two groups list the same field, when one list repeats a name, and when a group that places a related list (`relatedList`) also lists `fields`. A listed name the object does not declare is skipped, so deleting a field never makes the object unparseable, and `os lint` warns about it as **`field-group-member-unknown`**. In Studio, dragging a field inside a group writes that group's `fields` list. + A group can also hide itself: `visibleWhen` on a `fieldGroups` entry is a CEL predicate over `record` (plus `previous`, and `parent` on a master-detail line item), and it gates the **whole** section, header included. The gate is **fail-closed**: when the predicate is false, or cannot evaluate at all, the section disappears. `os validate`, `os build` and the metadata save door check it with the same rules as a field's own `visibleWhen`, so a predicate that names a field the object does not have (`record.stauts == 'won'`) is refused as **`expression-invalid`** at the group's key instead of silently hiding the section on every form. **2. Layout grouping — form `sections` (on a view).** A specific form's explicit arrangement: which fields, which section, how many columns, collapsible. It can **inherit** the object's declared groups as its default or **override** them per form. diff --git a/scripts/sdui-manifest.record.json b/scripts/sdui-manifest.record.json index aa151782d16..83d138ef01e 100644 --- a/scripts/sdui-manifest.record.json +++ b/scripts/sdui-manifest.record.json @@ -13,8 +13,8 @@ ], "source": "built-tree", "generator": "scripts/gen-sdui-manifest-node.mjs", - "generatedAt": "2026-11-18", - "sha256": "d6baeb81803dba3e0e4cdf4f1fa1f3a6340c9ab2e3df5a063ef2dbe453ffd754", + "generatedAt": "2026-11-20", + "sha256": "95510b0adeaef1efbfdb761325bcb96f034d252e179587f82dd9a7ae2d98f262", "components": 106, "inTree": { "modulesRoot": "ui/apps/console", diff --git a/sdui.manifest.json b/sdui.manifest.json index 83fb44c0dab..9ae116bf56d 100644 --- a/sdui.manifest.json +++ b/sdui.manifest.json @@ -1601,7 +1601,7 @@ "name": "sections", "type": "array", "of": "object", - "description": "Field groups rendered as the detail body, in order. Every entry is an OBJECT — `{ name?, label?, columns?, fields }` — a bare section-id string is NOT accepted (the spec retired that spelling in objectstack#5611, and the renderer reads name/label/fields off each entry, so a string entry renders no fields at all). `fields` are the field names shown in this section, in order — required unless `group` supplies the members instead (the spec refuses a section carrying neither, and refuses one carrying both). `label` is the section heading; omit it for an untitled, borderless section. `name` is a stable snake_case identifier and the i18n anchor — the heading resolves through objects.._sections..label, so a section without a name shows its authored label in every locale. `columns` (1-4) is THIS section's field-grid width; omit it and the renderer derives the width. Authoring `sections` at all makes it the only source of the detail body; omit it and the body falls back to the object's highlightFields. @objectstack/spec 17.3.0 declares eight more member keys on an entry, and this renderer honours all eight: `icon` (a Lucide name on the section header), `description` (sub-heading copy under the heading), `collapsible` and `defaultCollapsed` (a foldable section and its initial state), `showBorder` (force the Card wrapper on or off, overriding the heading-derived default) and `headerColor` (a header tint from the shared palette) through DetailSection, plus `group` — the ADR-0085 §5 REFERENCE form, the alternative to enumerating `fields`. `{ group: 'contact_info' }` inherits the object's `fieldGroups` entry with that key: its members (every visible field pointing at it, in declaration order), its presentation (label, icon, description, collapse) and its `visibleWhen` all come from the group, so the section restates none of it — the predicate is evaluated against the bound record exactly as the entry form evaluates it, and a group it hides renders nothing (a `visibleWhen` written on a section itself is refused by the spec and not read: gate the group and reference it) and the spec refuses those keys beside `group`; `columns`, `showBorder` and `headerColor` stay yours because they are how THIS page lays the section out. A `group` naming no declared group renders nothing and is reported to the console (`@objectstack/lint` flags it as `page-section-group-unknown`). `hideEmpty` is the eighth, and it decides whether an ALL-empty section exists: it defaults to on, so a section whose fields are every one of them empty renders nothing at all — no heading, no skeleton — and `hideEmpty: false` is the spelling that keeps the section on a brand-new record: in read-only mode named in the one line that closes the body, beside every other all-empty section kept this way, and expanding that line draws each in its place as its heading plus one fold row that counts the empty fields and reveals them on request (the same fold a partly-filled section uses, objectui#13386), in edit mode as every field an editable row. It decides ONLY the all-empty case; the empty rows of a section that still has a filled one belong to DetailSection's auto-hide heuristic plus the reader's show-empty toggle, which no authored value overrides in either polarity (objectui#7129 Q2-C), and inline-edit mode renders the section either way so its fields stay reachable. Restored under objectui#8603 (maintainer 2026-09-15) after objectui#7129 retired it on the premise, since falsified upstream, that the spec refused the key. None of the eight has a designer control yet; they are authorable in source mode only, tracked as a deferred feature. @objectstack/spec 18 declares a ninth, `count` (`{ field }`): the renderer fills the heading's `{{ count }}` hole with how many values that multi-value field holds on the current record — `{ name: 'tagging', label: '{{ count }} tags', count: { field: 'tags' }, fields: ['tags'] }` reads `3 tags` when three are selected. An absent or empty value counts 0; `count` changes only the heading, never whether the section renders, so with `hideEmpty` on an all-empty section is still absent. The hole is filled after the heading is translated, so each locale of an inline label map and a translated objects.._sections..label write the same `{{ count }}`. The spec refuses `count` beside `group`, on a section with no `label`, and on a label with no hole; a heading on a section without `count` prints as written. Like the eight, `count` has no designer control yet." + "description": "Field groups rendered as the detail body, in order. Every entry is an OBJECT — `{ name?, label?, columns?, fields }` — a bare section-id string is NOT accepted (the spec retired that spelling in objectstack#5611, and the renderer reads name/label/fields off each entry, so a string entry renders no fields at all). `fields` are the field names shown in this section, in order — required unless `group` supplies the members instead (the spec refuses a section carrying neither, and refuses one carrying both). `label` is the section heading; omit it for an untitled, borderless section. `name` is a stable snake_case identifier and the i18n anchor — the heading resolves through objects.._sections..label, so a section without a name shows its authored label in every locale. `columns` (1-4) is THIS section's field-grid width; omit it and the renderer derives the width. Authoring `sections` at all makes it the only source of the detail body; omit it and the body falls back to the object's highlightFields. @objectstack/spec 17.3.0 declares eight more member keys on an entry, and this renderer honours all eight: `icon` (a Lucide name on the section header), `description` (sub-heading copy under the heading), `collapsible` and `defaultCollapsed` (a foldable section and its initial state), `showBorder` (force the Card wrapper on or off, overriding the heading-derived default) and `headerColor` (a header tint from the shared palette) through DetailSection, plus `group` — the ADR-0085 §5 REFERENCE form, the alternative to enumerating `fields`. `{ group: 'contact_info' }` inherits the object's `fieldGroups` entry with that key: its members (the group's own `fields` list in its order, then every other visible field whose `group` names it, in declaration order), its presentation (label, icon, description, collapse) and its `visibleWhen` all come from the group, so the section restates none of it — the predicate is evaluated against the bound record exactly as the entry form evaluates it, and a group it hides renders nothing (a `visibleWhen` written on a section itself is refused by the spec and not read: gate the group and reference it) and the spec refuses those keys beside `group`; `columns`, `showBorder` and `headerColor` stay yours because they are how THIS page lays the section out. A `group` naming no declared group renders nothing and is reported to the console (`@objectstack/lint` flags it as `page-section-group-unknown`). `hideEmpty` is the eighth, and it decides whether an ALL-empty section exists: it defaults to on, so a section whose fields are every one of them empty renders nothing at all — no heading, no skeleton — and `hideEmpty: false` is the spelling that keeps the section on a brand-new record: in read-only mode named in the one line that closes the body, beside every other all-empty section kept this way, and expanding that line draws each in its place as its heading plus one fold row that counts the empty fields and reveals them on request (the same fold a partly-filled section uses, objectui#13386), in edit mode as every field an editable row. It decides ONLY the all-empty case; the empty rows of a section that still has a filled one belong to DetailSection's auto-hide heuristic plus the reader's show-empty toggle, which no authored value overrides in either polarity (objectui#7129 Q2-C), and inline-edit mode renders the section either way so its fields stay reachable. Restored under objectui#8603 (maintainer 2026-09-15) after objectui#7129 retired it on the premise, since falsified upstream, that the spec refused the key. None of the eight has a designer control yet; they are authorable in source mode only, tracked as a deferred feature. @objectstack/spec 18 declares a ninth, `count` (`{ field }`): the renderer fills the heading's `{{ count }}` hole with how many values that multi-value field holds on the current record — `{ name: 'tagging', label: '{{ count }} tags', count: { field: 'tags' }, fields: ['tags'] }` reads `3 tags` when three are selected. An absent or empty value counts 0; `count` changes only the heading, never whether the section renders, so with `hideEmpty` on an all-empty section is still absent. The hole is filled after the heading is translated, so each locale of an inline label map and a translated objects.._sections..label write the same `{{ count }}`. The spec refuses `count` beside `group`, on a section with no `label`, and on a label with no hole; a heading on a section without `count` prints as written. Like the eight, `count` has no designer control yet." }, { "name": "fields", diff --git a/ui/packages/plugin-detail/src/index.tsx b/ui/packages/plugin-detail/src/index.tsx index 8f3888dc7f0..151a862996c 100644 --- a/ui/packages/plugin-detail/src/index.tsx +++ b/ui/packages/plugin-detail/src/index.tsx @@ -625,7 +625,7 @@ ComponentRegistry.register('details', RecordDetailsRenderer, { // `record:reference_rail`'s own component-level `hideEmpty` input below. inputs: [ { name: 'columns', type: 'enum', enum: ['1', '2', '3', '4'], description: 'Number of columns for field layout (1-4)' }, - { name: 'sections', type: 'array', of: 'object', description: 'Field groups rendered as the detail body, in order. Every entry is an OBJECT — `{ name?, label?, columns?, fields }` — a bare section-id string is NOT accepted (the spec retired that spelling in objectstack#5611, and the renderer reads name/label/fields off each entry, so a string entry renders no fields at all). `fields` are the field names shown in this section, in order — required unless `group` supplies the members instead (the spec refuses a section carrying neither, and refuses one carrying both). `label` is the section heading; omit it for an untitled, borderless section. `name` is a stable snake_case identifier and the i18n anchor — the heading resolves through objects.._sections..label, so a section without a name shows its authored label in every locale. `columns` (1-4) is THIS section\'s field-grid width; omit it and the renderer derives the width. Authoring `sections` at all makes it the only source of the detail body; omit it and the body falls back to the object\'s highlightFields. @objectstack/spec 17.3.0 declares eight more member keys on an entry, and this renderer honours all eight: `icon` (a Lucide name on the section header), `description` (sub-heading copy under the heading), `collapsible` and `defaultCollapsed` (a foldable section and its initial state), `showBorder` (force the Card wrapper on or off, overriding the heading-derived default) and `headerColor` (a header tint from the shared palette) through DetailSection, plus `group` — the ADR-0085 §5 REFERENCE form, the alternative to enumerating `fields`. `{ group: \'contact_info\' }` inherits the object\'s `fieldGroups` entry with that key: its members (every visible field pointing at it, in declaration order), its presentation (label, icon, description, collapse) and its `visibleWhen` all come from the group, so the section restates none of it — the predicate is evaluated against the bound record exactly as the entry form evaluates it, and a group it hides renders nothing (a `visibleWhen` written on a section itself is refused by the spec and not read: gate the group and reference it) and the spec refuses those keys beside `group`; `columns`, `showBorder` and `headerColor` stay yours because they are how THIS page lays the section out. A `group` naming no declared group renders nothing and is reported to the console (`@objectstack/lint` flags it as `page-section-group-unknown`). `hideEmpty` is the eighth, and it decides whether an ALL-empty section exists: it defaults to on, so a section whose fields are every one of them empty renders nothing at all — no heading, no skeleton — and `hideEmpty: false` is the spelling that keeps the section on a brand-new record: in read-only mode named in the one line that closes the body, beside every other all-empty section kept this way, and expanding that line draws each in its place as its heading plus one fold row that counts the empty fields and reveals them on request (the same fold a partly-filled section uses, objectui#13386), in edit mode as every field an editable row. It decides ONLY the all-empty case; the empty rows of a section that still has a filled one belong to DetailSection\'s auto-hide heuristic plus the reader\'s show-empty toggle, which no authored value overrides in either polarity (objectui#7129 Q2-C), and inline-edit mode renders the section either way so its fields stay reachable. Restored under objectui#8603 (maintainer 2026-09-15) after objectui#7129 retired it on the premise, since falsified upstream, that the spec refused the key. None of the eight has a designer control yet; they are authorable in source mode only, tracked as a deferred feature. @objectstack/spec 18 declares a ninth, `count` (`{ field }`): the renderer fills the heading\'s `{{ count }}` hole with how many values that multi-value field holds on the current record — `{ name: \'tagging\', label: \'{{ count }} tags\', count: { field: \'tags\' }, fields: [\'tags\'] }` reads `3 tags` when three are selected. An absent or empty value counts 0; `count` changes only the heading, never whether the section renders, so with `hideEmpty` on an all-empty section is still absent. The hole is filled after the heading is translated, so each locale of an inline label map and a translated objects.._sections..label write the same `{{ count }}`. The spec refuses `count` beside `group`, on a section with no `label`, and on a label with no hole; a heading on a section without `count` prints as written. Like the eight, `count` has no designer control yet.' }, + { name: 'sections', type: 'array', of: 'object', description: 'Field groups rendered as the detail body, in order. Every entry is an OBJECT — `{ name?, label?, columns?, fields }` — a bare section-id string is NOT accepted (the spec retired that spelling in objectstack#5611, and the renderer reads name/label/fields off each entry, so a string entry renders no fields at all). `fields` are the field names shown in this section, in order — required unless `group` supplies the members instead (the spec refuses a section carrying neither, and refuses one carrying both). `label` is the section heading; omit it for an untitled, borderless section. `name` is a stable snake_case identifier and the i18n anchor — the heading resolves through objects.._sections..label, so a section without a name shows its authored label in every locale. `columns` (1-4) is THIS section\'s field-grid width; omit it and the renderer derives the width. Authoring `sections` at all makes it the only source of the detail body; omit it and the body falls back to the object\'s highlightFields. @objectstack/spec 17.3.0 declares eight more member keys on an entry, and this renderer honours all eight: `icon` (a Lucide name on the section header), `description` (sub-heading copy under the heading), `collapsible` and `defaultCollapsed` (a foldable section and its initial state), `showBorder` (force the Card wrapper on or off, overriding the heading-derived default) and `headerColor` (a header tint from the shared palette) through DetailSection, plus `group` — the ADR-0085 §5 REFERENCE form, the alternative to enumerating `fields`. `{ group: \'contact_info\' }` inherits the object\'s `fieldGroups` entry with that key: its members (the group\'s own `fields` list in its order, then every other visible field whose `group` names it, in declaration order), its presentation (label, icon, description, collapse) and its `visibleWhen` all come from the group, so the section restates none of it — the predicate is evaluated against the bound record exactly as the entry form evaluates it, and a group it hides renders nothing (a `visibleWhen` written on a section itself is refused by the spec and not read: gate the group and reference it) and the spec refuses those keys beside `group`; `columns`, `showBorder` and `headerColor` stay yours because they are how THIS page lays the section out. A `group` naming no declared group renders nothing and is reported to the console (`@objectstack/lint` flags it as `page-section-group-unknown`). `hideEmpty` is the eighth, and it decides whether an ALL-empty section exists: it defaults to on, so a section whose fields are every one of them empty renders nothing at all — no heading, no skeleton — and `hideEmpty: false` is the spelling that keeps the section on a brand-new record: in read-only mode named in the one line that closes the body, beside every other all-empty section kept this way, and expanding that line draws each in its place as its heading plus one fold row that counts the empty fields and reveals them on request (the same fold a partly-filled section uses, objectui#13386), in edit mode as every field an editable row. It decides ONLY the all-empty case; the empty rows of a section that still has a filled one belong to DetailSection\'s auto-hide heuristic plus the reader\'s show-empty toggle, which no authored value overrides in either polarity (objectui#7129 Q2-C), and inline-edit mode renders the section either way so its fields stay reachable. Restored under objectui#8603 (maintainer 2026-09-15) after objectui#7129 retired it on the premise, since falsified upstream, that the spec refused the key. None of the eight has a designer control yet; they are authorable in source mode only, tracked as a deferred feature. @objectstack/spec 18 declares a ninth, `count` (`{ field }`): the renderer fills the heading\'s `{{ count }}` hole with how many values that multi-value field holds on the current record — `{ name: \'tagging\', label: \'{{ count }} tags\', count: { field: \'tags\' }, fields: [\'tags\'] }` reads `3 tags` when three are selected. An absent or empty value counts 0; `count` changes only the heading, never whether the section renders, so with `hideEmpty` on an all-empty section is still absent. The hole is filled after the heading is translated, so each locale of an inline label map and a translated objects.._sections..label write the same `{{ count }}`. The spec refuses `count` beside `group`, on a section with no `label`, and on a label with no hole; a heading on a section without `count` prints as written. Like the eight, `count` has no designer control yet.' }, { name: 'fields', type: 'array', of: 'string', description: 'Explicit field list (overrides highlightFields)' }, // `hideFields` is DECLARED, not merely honoured (objectui#3808). The spec // declares it (objectstack#5611) and `RecordDetailsRenderer` has read it diff --git a/ui/packages/plugin-detail/src/renderers/record-details.tsx b/ui/packages/plugin-detail/src/renderers/record-details.tsx index e8c63e5d429..cf77683a7c1 100644 --- a/ui/packages/plugin-detail/src/renderers/record-details.tsx +++ b/ui/packages/plugin-detail/src/renderers/record-details.tsx @@ -898,8 +898,9 @@ const RecordDetailsBody: React.FC = ({ // ── `sections[].group` — the ADR-0085 §5 REFERENCE form ────────────────── // // `{ group: 'parties' }` inherits the object's `fieldGroups` entry with that - // key: its members (every visible field pointing at it, in declaration - // order) and its own presentation (label, icon, description, collapse) — + // key: its members (the group's own `fields` list first, in its order, then + // every other visible field pointing at it, in declaration order) and its + // own presentation (label, icon, description, collapse) — // `@objectstack/spec` 17.3.0 `RecordDetailsProps.sections[].group` // (objectstack#13855), whose semantics are single-sourced in // `deriveFieldGroupLayout`. This renderer used to read the key NOWHERE, and From e010381489b0cd259652b6a121070254423536d0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 20:46:54 +0000 Subject: [PATCH 10/10] fix(spec, metadata-core): the served-document mask keeps a group's fields list; only a declared group disagrees with a list The field-level-security mask of the served object document did not classify fieldGroups[].fields, so one denied name dropped the whole list and the caller's record page and forms fell back to the older rule. It is now a name list: the denied name is filtered out and the readable ones keep their order. The agreement refusal now judges a listed field's own group only when it names another DECLARED group; a group naming no declared key means ungrouped, so renaming a group's key no longer makes its listed members unparseable. The key row's help text says what a rename does (retranslated in every locale), and the orphaned guidance comment above order is gone. Claude-Session: https://claude.ai/code/session_01L6bhgW2k3CdkgnLxXGxAfq Co-authored-by: Claude --- .changeset/35900-field-group-members.md | 5 +++- .../src/object-schema-fls-references.test.ts | 24 +++++++++++++++++++ .../src/object-schema-fls-references.ts | 11 ++++++--- .../ar.metadata-forms.generated.ts | 2 +- .../de.metadata-forms.generated.ts | 2 +- .../en.metadata-forms.generated.ts | 2 +- .../es-ES.metadata-forms.generated.ts | 2 +- .../fr.metadata-forms.generated.ts | 2 +- .../ja-JP.metadata-forms.generated.ts | 2 +- .../ko.metadata-forms.generated.ts | 2 +- .../pt-BR.metadata-forms.generated.ts | 2 +- .../ru.metadata-forms.generated.ts | 2 +- .../zh-CN.metadata-forms.generated.ts | 2 +- .../zh-Hant.metadata-forms.generated.ts | 2 +- .../spec/src/data/field-group-layout.test.ts | 13 ++++++++++ packages/spec/src/data/object.form.ts | 2 +- packages/spec/src/data/object.zod.ts | 22 +++++++++++------ 17 files changed, 76 insertions(+), 23 deletions(-) diff --git a/.changeset/35900-field-group-members.md b/.changeset/35900-field-group-members.md index e1270a50e07..8ec13f53dc0 100644 --- a/.changeset/35900-field-group-members.md +++ b/.changeset/35900-field-group-members.md @@ -4,6 +4,7 @@ '@object-ui/app-shell': minor '@objectstack/platform-objects': minor '@object-ui/plugin-detail': minor +'@objectstack/metadata-core': minor --- feat(spec): a field group lists its own members and their order (`fieldGroups[].fields`) @@ -24,8 +25,10 @@ The record page, the create and edit forms and the drawer show the group's field Nothing changes for an object that writes no `fields` on its groups: a group without the list still holds the fields whose `group` names it, in field declaration order. `Field.group` is the older spelling and is still read; it is not deprecated for removal. -The two spellings must agree. The object parse refuses a field one group lists while its own `group` names another group (reported at both places), a field two groups list, a name one list repeats, and `fields` on a group that places a related list (`relatedList`). A field whose `group` names a listing group that leaves it out is shown after the listed fields, never dropped. A listed name the object does not declare is skipped, so removing a field never makes the object unparseable; `os lint` warns about it (`field-group-member-unknown`). +The two spellings must agree. The object parse refuses a field one group lists while its own `group` names another declared group (reported at both places; a `group` naming no declared key is not another group, so the list wins), a field two groups list, a name one list repeats, and `fields` on a group that places a related list (`relatedList`). A field whose `group` names a listing group that leaves it out is shown after the listed fields, never dropped. A listed name the object does not declare is skipped, so removing a field never makes the object unparseable; `os lint` warns about it (`field-group-member-unknown`). New export: `readFieldGroupMembership` (`@objectstack/spec/data`), the membership `deriveFieldGroupLayout` places sections from, for editors that also show hidden fields. Studio: dragging a field inside a group, or into another group, now writes those groups' `fields` lists and leaves the object's field declaration order alone. Only the ungrouped bucket, which has no list, still reorders by declaration order. Moving a field to another group from the field inspector does the same once a list is involved. + +Field-level security: the object document served to a caller who cannot read some fields keeps each group's `fields` list, with the hidden names filtered out and the rest in order, so the record page and forms keep the layout for that caller. diff --git a/packages/metadata-core/src/object-schema-fls-references.test.ts b/packages/metadata-core/src/object-schema-fls-references.test.ts index 958f03610ec..173716fe76e 100644 --- a/packages/metadata-core/src/object-schema-fls-references.test.ts +++ b/packages/metadata-core/src/object-schema-fls-references.test.ts @@ -291,6 +291,30 @@ describe('[ADR-0106 D1] references to a denied field — object level', () => { expect(served.fields.title.group).toBe('secret_score'); }); + it('[#35900] filters the denied field out of a group\'s own fields list and keeps the readable rest in order', () => { + const served = mask({ + name: 'thing', + fields: fieldsWith({}), + fieldGroups: [ + { key: 'main', label: 'Main', fields: ['secret_score', 'title', 'id'] }, + { key: 'other', label: 'Other', fields: ['id'] }, + ], + }); + expect(served.fieldGroups).toEqual([ + { key: 'main', label: 'Main', fields: ['title', 'id'] }, + { key: 'other', label: 'Other', fields: ['id'] }, + ]); + }); + + it('[#35900] CONTROL: a fields list naming only readable fields is served as written', () => { + const served = mask({ + name: 'thing', + fields: fieldsWith({}), + fieldGroups: [{ key: 'main', label: 'Main', fields: ['title', 'id'] }], + }); + expect(served.fieldGroups).toEqual([{ key: 'main', label: 'Main', fields: ['title', 'id'] }]); + }); + it('[#27069] serves relatedLists and a group relatedList naming a child that shares the denied field\'s name', () => { // The entries name CHILD objects (or `object.field`), never a field of // this object, so a child called like the denied field is still served. diff --git a/packages/metadata-core/src/object-schema-fls-references.ts b/packages/metadata-core/src/object-schema-fls-references.ts index 0a025040805..10699735dff 100644 --- a/packages/metadata-core/src/object-schema-fls-references.ts +++ b/packages/metadata-core/src/object-schema-fls-references.ts @@ -85,9 +85,11 @@ * well as whole, so a dotted path through a denied lookup (`owner.city` * with `owner` denied) is a reference to it. * - A `fieldGroups[].key` is a group name, not a field reference — the - * readable fields join a group through their own `group: ` — so a group - * keyed like a denied field is served; dropping it would regroup fields the - * caller IS entitled to. A `listViews` key, by contrast, is the view's whole + * readable fields join a group through the group's own `fields` list or + * their own `group: ` — so a group keyed like a denied field is served; + * dropping it would regroup fields the caller IS entitled to. The `fields` + * list is a name list: a denied name is filtered out of it, and the readable + * names keep their place and order. A `listViews` key, by contrast, is the view's whole * identity and nothing else points at it, so a view keyed like a denied field * is dropped. * @@ -819,6 +821,9 @@ export const OBJECT_REFERENCE_POSITIONS: Readonly> = { // [#27069] A child relationship (child object, or `object.field`), as a // `relatedLists` entry is: no field of this object. relatedList: keep, + // [#35900] The group's own member list: field names of this object, so + // a denied one is filtered out and the readable rest keep their order. + fields: names, })), tenancy: block({ enabled: keep, tenantField: pointer }), lifecycle: block({ diff --git a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts index ebc95f41d89..8f456635caa 100644 --- a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const arMetadataForms: NonNullable = { }, "fieldGroups.key": { label: "المفتاح", - helpText: "مفتاح برمجي بصيغة snake_case، فريد داخل هذا الكائن — ويرفض المخطط أي شيء غير ذلك. تنضم الحقول إلى المجموعة بذكر هذا المفتاح، لذا فإن إعادة تسميته تتركها بلا مجموعة." + helpText: "مفتاح برمجي بصيغة snake_case، فريد داخل هذا الكائن — ويرفض المخطط أي شيء غير ذلك. الحقول التي تذكرها المجموعة في «الحقول» تبقى معها عند إعادة تسمية المفتاح؛ أما الحقل الذي ينضم بذكر هذا المفتاح في إعداد المجموعة الخاص به فيصبح بلا مجموعة." }, "fieldGroups.label": { label: "التسمية", diff --git a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts index c49aa0d7c7b..15ef87a6ab0 100644 --- a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const deMetadataForms: NonNullable = { }, "fieldGroups.key": { label: "Schlüssel", - helpText: "Maschinenschlüssel in snake_case, eindeutig innerhalb dieses Objekts – das Schema lehnt alles andere ab. Felder treten der Gruppe bei, indem sie diesen Schlüssel nennen; eine Umbenennung lässt sie daher ohne Gruppe." + helpText: "Maschinenschlüssel in snake_case, eindeutig innerhalb dieses Objekts – das Schema lehnt alles andere ab. Felder, die die Gruppe in ihren Feldern aufführt, bleiben bei einer Umbenennung in der Gruppe; ein Feld, das über diesen Schlüssel in seiner eigenen Gruppeneinstellung beitritt, ist danach ohne Gruppe." }, "fieldGroups.label": { label: "Bezeichnung", diff --git a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts index 4b9945f618c..acd2781e39e 100644 --- a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const enMetadataForms: NonNullable = { }, "fieldGroups.key": { label: "Key", - helpText: "Machine key in snake_case, unique within this object — the schema refuses anything else. Fields join the group by naming this key, so renaming it leaves them ungrouped." + helpText: "Machine key in snake_case, unique within this object — the schema refuses anything else. Fields the group lists in its Fields stay with it when the key is renamed; a field that joins by naming this key in its own group setting is left ungrouped." }, "fieldGroups.label": { label: "Label", diff --git a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts index 7a648072388..9bc1f39aefb 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const esESMetadataForms: NonNullable = }, "fieldGroups.key": { label: "Clave", - helpText: "Clave de máquina en snake_case, única dentro de este objeto: el esquema rechaza cualquier otra cosa. Los campos se unen al grupo indicando esta clave, así que renombrarla los deja sin grupo." + helpText: "Clave de máquina en snake_case, única dentro de este objeto: el esquema rechaza cualquier otra cosa. Los campos que el grupo lista en Campos siguen en él al renombrar la clave; un campo que se une indicando esta clave en su propio ajuste de grupo queda sin grupo." }, "fieldGroups.label": { label: "Etiqueta", diff --git a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts index 914bcde3a4a..cd304e3d3bb 100644 --- a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const frMetadataForms: NonNullable = { }, "fieldGroups.key": { label: "Clé", - helpText: "Clé technique en snake_case, unique au sein de cet objet — le schéma refuse tout autre format. Les champs rejoignent le groupe en indiquant cette clé : la renommer les laisse donc sans groupe." + helpText: "Clé technique en snake_case, unique au sein de cet objet — le schéma refuse tout autre format. Les champs que le groupe liste dans Champs y restent quand la clé est renommée ; un champ qui rejoint le groupe en indiquant cette clé dans son propre réglage de groupe se retrouve sans groupe." }, "fieldGroups.label": { label: "Libellé", diff --git a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts index ef167963419..bd4fd6fe86d 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const jaJPMetadataForms: NonNullable = }, "fieldGroups.key": { label: "キー", - helpText: "snake_case のマシンキーで、このオブジェクト内で一意です。それ以外はスキーマが拒否します。フィールドはこのキーを指定してグループに加わるため、キーを変更するとそれらのフィールドはどのグループにも属さなくなります。" + helpText: "snake_case のマシンキーで、このオブジェクト内で一意です。それ以外はスキーマが拒否します。グループの「フィールド」に挙げたフィールドは、キーを変更してもグループに残ります。自身のグループ設定でこのキーを指定して加わったフィールドは、どのグループにも属さなくなります。" }, "fieldGroups.label": { label: "表示名", diff --git a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts index f637322728e..d87d485d30b 100644 --- a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const koMetadataForms: NonNullable = { }, "fieldGroups.key": { label: "키", - helpText: "이 객체 안에서 고유한 snake_case 머신 키입니다. 스키마는 다른 형식을 거부합니다. 필드는 이 키를 지정해 그룹에 들어가므로, 이름을 바꾸면 필드가 그룹에서 빠집니다." + helpText: "이 객체 안에서 고유한 snake_case 머신 키입니다. 스키마는 다른 형식을 거부합니다. 그룹의 필드 목록에 나열된 필드는 키 이름을 바꿔도 그룹에 남고, 자체 그룹 설정에서 이 키를 지정해 들어온 필드는 그룹에서 빠집니다." }, "fieldGroups.label": { label: "레이블", diff --git a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts index ece555d7d64..2b2f158e419 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const ptBRMetadataForms: NonNullable = }, "fieldGroups.key": { label: "Chave", - helpText: "Chave de máquina em snake_case, única dentro deste objeto — o esquema recusa qualquer outra coisa. Os campos entram no grupo ao nomear esta chave, portanto renomeá-la os deixa sem grupo." + helpText: "Chave de máquina em snake_case, única dentro deste objeto — o esquema recusa qualquer outra coisa. Os campos que o grupo lista em Campos continuam nele quando a chave é renomeada; um campo que entra ao nomear esta chave na sua própria configuração de grupo fica sem grupo." }, "fieldGroups.label": { label: "Rótulo", diff --git a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts index a85f9f5660c..9be6dd50896 100644 --- a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const ruMetadataForms: NonNullable = { }, "fieldGroups.key": { label: "Ключ", - helpText: "Машинный ключ в snake_case, уникальный в пределах этого объекта, — всё остальное схема отклоняет. Поля входят в группу по этому ключу, поэтому его переименование оставит их без группы." + helpText: "Машинный ключ в snake_case, уникальный в пределах этого объекта, — всё остальное схема отклоняет. Поля, перечисленные в списке полей группы, остаются в ней при переименовании ключа; поле, которое входит в группу по этому ключу в собственной настройке группы, останется без группы." }, "fieldGroups.label": { label: "Метка", diff --git a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts index 8a911f5c8ba..84cc7bf239a 100644 --- a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const zhCNMetadataForms: NonNullable = }, "fieldGroups.key": { label: "键", - helpText: "snake_case 格式的机器键,在本对象内唯一——其他写法会被 schema 拒绝。字段通过填写此键加入分组,因此重命名它会使这些字段变为未分组。" + helpText: "snake_case 格式的机器键,在本对象内唯一——其他写法会被 schema 拒绝。分组在「字段」中列出的字段,重命名此键后仍留在分组里;通过自身分组设置填写此键加入的字段会变为未分组。" }, "fieldGroups.label": { label: "显示名称", diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts index cbe340434f0..683d563d826 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts @@ -86,7 +86,7 @@ export const zhHantMetadataForms: NonNullable }, "fieldGroups.key": { label: "鍵", - helpText: "snake_case 格式的機器鍵,在本物件內唯一——其他寫法會被 schema 拒絕。欄位透過填寫此鍵加入分組,因此重新命名它會使這些欄位變為未分組。" + helpText: "snake_case 格式的機器鍵,在本物件內唯一——其他寫法會被 schema 拒絕。分組在「欄位」中列出的欄位,重新命名此鍵後仍留在分組裡;透過自身分組設定填寫此鍵加入的欄位會變為未分組。" }, "fieldGroups.label": { label: "顯示名稱", diff --git a/packages/spec/src/data/field-group-layout.test.ts b/packages/spec/src/data/field-group-layout.test.ts index fa75bdcfe5a..76049d23185 100644 --- a/packages/spec/src/data/field-group-layout.test.ts +++ b/packages/spec/src/data/field-group-layout.test.ts @@ -320,6 +320,19 @@ describe('fieldGroups[].fields — the object parse holds the two spellings in a expect(found[0].message).toContain("'money'"); }); + it('parses a listed field whose own group names an UNDECLARED key — not another group, so the list wins', () => { + // A group renamed after a list was written leaves its members' older + // `group` naming a key no group declares any more (lint's + // `field-group-undeclared`); the members stay in the list. + const def = { + ...base, + fields: { ...base.fields, account: { ...base.fields.account, group: 'basics_old' } }, + fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['account', 'name'] }], + }; + expect(issues(def)).toEqual([]); + expect(deriveFieldGroupLayout(def)!.find((s) => s.key === 'basic')!.fields).toEqual(['account', 'name']); + }); + it('refuses a field two groups list, at the second listing', () => { const found = issues({ ...base, diff --git a/packages/spec/src/data/object.form.ts b/packages/spec/src/data/object.form.ts index 0d9a70d6f1c..1e25ba41ca6 100644 --- a/packages/spec/src/data/object.form.ts +++ b/packages/spec/src/data/object.form.ts @@ -107,7 +107,7 @@ export const objectForm = defineForm({ colSpan: 2, helpText: 'Ordered sections that group this object\'s fields on the entry form and the record detail page (ADR-0085); array order is display order. A group lists its fields, in order, in its Fields setting; a group without that list holds the fields that name its key in their own group setting. Fields in no group follow the groups, and a group no field joins is not drawn.', fields: [ - { field: 'key', label: 'Key', type: 'text', required: true, helpText: 'Machine key in snake_case, unique within this object — the schema refuses anything else. Fields join the group by naming this key, so renaming it leaves them ungrouped.' }, + { field: 'key', label: 'Key', type: 'text', required: true, helpText: 'Machine key in snake_case, unique within this object — the schema refuses anything else. Fields the group lists in its Fields stay with it when the key is renamed; a field that joins by naming this key in its own group setting is left ungrouped.' }, { field: 'label', label: 'Label', type: 'text', required: true, helpText: 'Header text of the group\'s section.' }, { field: 'fields', label: 'Fields', type: 'tags', helpText: 'The fields this group shows, in display order (field names). Written, it sets the order inside the group without moving any field. A field this list names may not name another group in its own group setting, and a field may be listed by one group only. Not allowed with Related List.' }, { field: 'icon', label: 'Icon', type: 'text', helpText: 'Lucide icon name shown beside the header on the record detail page (e.g. "banknote"). The entry form does not show it.' }, diff --git a/packages/spec/src/data/object.zod.ts b/packages/spec/src/data/object.zod.ts index c8799e665b2..d0bcda4db63 100644 --- a/packages/spec/src/data/object.zod.ts +++ b/packages/spec/src/data/object.zod.ts @@ -1337,9 +1337,6 @@ export const ObjectFieldGroupSchema = lazySchema(() => strictObject({ helpText: 'description', }, guidance: { - // Membership is declared the OTHER WAY ROUND, and this is the single most - // likely thing an author reaches for here — a group that lists its fields - // is what every other layout system in this space looks like. order: '`order` is not a group key — ARRAY ORDER is display order. `fieldGroups: [...]` ' + 'renders top to bottom, so move the entry rather than numbering it.', @@ -3366,9 +3363,12 @@ function refuseFieldsInRelatedListGroups(fieldGroups: unknown, fields: unknown, * group holds no fields — at `['fieldGroups', i, 'fields']`; * - a name one list repeats — at the repeat; * - a field two groups list — at the second listing, naming the first group; - * - a listed field whose own `group` names a different group — at the - * listing AND at `['fields', , 'group']`, each naming the other, so - * the author sees both places to fix. + * - a listed field whose own `group` names a different DECLARED group — at + * the listing AND at `['fields', , 'group']`, each naming the other, + * so the author sees both places to fix. A `group` naming no declared key + * is not another group (it means ungrouped, and lint reports it as + * `field-group-undeclared`), so the list wins and nothing is refused — + * renaming a group's key never makes its listed members unparseable. * * A listed name the object declares no field for is NOT judged: the layout * skips it, and refusing it would make the object unparseable the moment any @@ -3384,6 +3384,14 @@ function refuseFieldGroupMembershipConflicts(fieldGroups: unknown, fields: unkno if (!Array.isArray(fieldGroups)) return; const fieldMap = fields !== null && typeof fields === 'object' ? (fields as Record) : {}; const listedIn = new Map(); + // Only a `group` naming ANOTHER DECLARED group disagrees with a list: one + // naming no declared key means ungrouped (lint reports it as + // `field-group-undeclared`), so the list simply wins. + const declaredKeys = new Set( + fieldGroups + .map((g: unknown) => (g !== null && typeof g === 'object' ? (g as { key?: unknown }).key : undefined)) + .filter((k): k is string => typeof k === 'string'), + ); fieldGroups.forEach((group: unknown, index: number) => { if (group === null || typeof group !== 'object') return; const { key, relatedList, fields: members } = group as { key?: unknown; relatedList?: unknown; fields?: unknown }; @@ -3421,7 +3429,7 @@ function refuseFieldGroupMembershipConflicts(fieldGroups: unknown, fields: unkno listedIn.set(name, key); const field = fieldMap[name]; const own = field !== null && typeof field === 'object' ? (field as { group?: unknown }).group : undefined; - if (typeof own !== 'string' || own === key) return; + if (typeof own !== 'string' || own === key || !declaredKeys.has(own)) return; const message = `Field '${name}' is listed by the field group '${key}' (its \`fields\`), but its own \`group\` names ` + `'${own}'. The two say different things: keep the field in '${key}'s list and drop its \`group\` `