diff --git a/.changeset/35902-skills-extension-place.md b/.changeset/35902-skills-extension-place.md new file mode 100644 index 00000000000..6a34046a1bc --- /dev/null +++ b/.changeset/35902-skills-extension-place.md @@ -0,0 +1,12 @@ +--- +'@objectstack/skills': patch +--- + +Clause-②: no +Metadata-protocol: none + +The skills teach where an object extension's additions go on the object it extends: + +- `objectstack-data` Object Extension Model: `place` puts the extension's own fields, groups and child lists after (or before) a named item of the target, where the target declares `fieldGroups` / `relatedLists`. Example: `place: [{ field: 'tax_id', group: 'basic', after: 'industry' }, { list: 'acme_contract', after: 'crm_opportunity' }]`; a group of the extension's own is `{ group: { key, label }, after }`. +- `objectstack-ui` record-page rule: on a parent that declares `relatedLists`, a child list another package adds still shows, after the named lists or where that package's extension places it. The rule no longer says such a list is hidden until the parent names it. +- Eval: a new `objectstack-data` case places an add-on package's field after Industry in the account's Basic group and its child list after the Opportunities tab. diff --git a/.changeset/35902-skills-related-lists-tabs.md b/.changeset/35902-skills-related-lists-tabs.md index 1ad9056b55f..7860f10a2ef 100644 --- a/.changeset/35902-skills-related-lists-tabs.md +++ b/.changeset/35902-skills-related-lists-tabs.md @@ -7,7 +7,7 @@ Metadata-protocol: none The record-page skills teach the parent-declared record page: -- `objectstack-ui` record-page rule: the parent's `relatedLists` is the tab list. Without it nothing changes; declared, only the named lists show, in order, with the attachments, approvals and activity tabs named by object (`sys_attachment`, `sys_approval_request`, `sys_activity`), and an entry `{ list, label, columns }` titles one list. "Put the tasks tab first" lists every tab to keep, tasks first, because a list naming only the task hides the rest. A child list another package adds is hidden by a `relatedLists` that does not name it. +- `objectstack-ui` record-page rule: the parent's `relatedLists` is the tab list. Without it nothing changes; declared, only the named lists show, in order, with the attachments, approvals and activity tabs named by object (`sys_attachment`, `sys_approval_request`, `sys_activity`), and an entry `{ list, label, columns }` titles one list. "Put the tasks tab first" lists every tab to keep, tasks first, because a list naming only the task hides the rest. A child list another package adds still shows, after the named lists or where that package's extension places it. - The same rule's step 1 no longer teaches a stage bar or a key-field strip: the stage is the status tag beside the title, whose menu moves it, and `highlightFields` feed hover cards, pickers and related-list columns. A field group lists its own members in `fields`. The wide full page pins the details left beside the tabs, unless the details hold a child table or there is no other tab; the right summary rail and its switch are gone from the text, and the details column's dragged width joins the reader's own choices. - A `master_detail` child is a tab by default (`objectstack-data` relationships rule, the record-page rule and an eval); a parent field group naming the child list places its table among the fields, written only when asked, and the list keeps its tab too unless a declared `relatedLists` leaves it out. - `objectstack-data` field-groups example lists each group's members in `fields`; `objectstack-ui` navigation names `fieldGroups` alone. diff --git a/content/docs/ui/pages.mdx b/content/docs/ui/pages.mdx index d074d725f38..55ea7b8364e 100644 --- a/content/docs/ui/pages.mdx +++ b/content/docs/ui/pages.mdx @@ -214,9 +214,10 @@ keys nothing changes. (the activity stream: when unlisted, last). An entry `{ list, label, columns }` gives one list its own title and child-field columns, winning over the child field's `relatedListTitle` / `relatedListColumns`; a built-in is written only as its bare name. To put one tab first, list - every tab the page keeps with that one first. A child list another package adds is hidden by a - `relatedLists` that does not name it (letting a package place its own list is a later change), - and `relatedList: false` on the child's reference field still hides a list. + every tab the page keeps with that one first. A child list another package adds is not hidden + by a `relatedLists` that does not name it: it shows where that package's extension places it + (below), or at the end of the tabs, before the approvals and activity-stream tabs. + `relatedList: false` on the child's reference field still hides a list. - **A field group lists its fields.** `fieldGroups` are the Details sections, in array order. A group lists its members, in order, in `fields`; without `fields`, its members are the fields whose `group` names it, the older spelling, still read. @@ -260,6 +261,28 @@ export const Quote = ObjectSchema.create({ }); ``` +A package that adds to an object it does not own says where its additions go, with `place` on +its [object extension](/docs/data-modeling/object-extensions#placing-what-you-bring): a field +into one of the target's groups, a group of its own between the target's, a child list among +the tabs, each right after or before a named item. Placement arranges what the target +declares. Where the target declares no `fieldGroups` (or no `relatedLists`), its automatic +arrangement stays and the additions still show in it. An extension places only what it brings. + +{/* os:check */} +```typescript +import { defineObjectExtension, Field } from '@objectstack/spec/data'; + +// A contracts package adds a field and a child list to `account`, and places both. +export const AccountContractsExtension = defineObjectExtension({ + extend: 'account', + fields: { tax_id: Field.text({ label: 'Tax ID' }) }, + place: [ + { field: 'tax_id', group: 'basic', after: 'industry' }, + { list: 'contract', after: 'opportunity', columns: ['name', 'amount', 'end_date'] }, + ], +}); +``` + ### How the page is laid out The Console lays the page out by the width of the surface it occupies, never by the viewport. diff --git a/examples/app-crm/src/objects/account.object.ts b/examples/app-crm/src/objects/account.object.ts index 3c3f5683cce..86fbd4b0443 100644 --- a/examples/app-crm/src/objects/account.object.ts +++ b/examples/app-crm/src/objects/account.object.ts @@ -46,4 +46,26 @@ export const Account = ObjectSchema.create({ label: 'Website', }), }, + + // The Details sections of the record page and the form. Each group lists its + // own fields, in order, so no field carries a `group` key. + fieldGroups: [ + { key: 'basic', label: 'Basic', fields: ['name', 'industry', 'website'] }, + { key: 'financials', label: 'Financials', fields: ['annual_revenue'] }, + ], + + // The record page's tabs, declared in one place: only the lists named here + // show, in this order. An entry may carry its own columns (fields of the + // child); the built-in tabs are named by object. Leaving a list out hides its + // tab, except a child list another package brings: that one still shows, at + // the end of the tabs or where that package's extension places it. Without + // this key every related list is a tab, in the automatic order. + relatedLists: [ + { list: 'crm_contact', columns: ['full_name', 'email'] }, + 'crm_opportunity', + 'crm_activity', + 'crm_lead', + 'sys_approval_request', + 'sys_activity', + ], }); diff --git a/examples/app-crm/src/translations/crm.translation.ts b/examples/app-crm/src/translations/crm.translation.ts index 63777e73ada..d1f436d18db 100644 --- a/examples/app-crm/src/translations/crm.translation.ts +++ b/examples/app-crm/src/translations/crm.translation.ts @@ -128,6 +128,11 @@ export const CrmTranslationBundle = defineTranslationBundle({ website: { label: '官网' }, owner_id: { label: '负责人' }, }, + // The account's field groups, keyed by `fieldGroups[].key`. + _sections: { + basic: { label: '基本信息' }, + financials: { label: '财务信息' }, + }, }, crm_contact: { label: '联系人', diff --git a/skills/objectstack-data/SKILL.md b/skills/objectstack-data/SKILL.md index d892c6eb66e..a1f48e49367 100644 --- a/skills/objectstack-data/SKILL.md +++ b/skills/objectstack-data/SKILL.md @@ -51,8 +51,7 @@ metadata: ### Object Definition -An **Object** is the fundamental data entity in ObjectStack. It maps to a -database table and exposes automatic CRUD APIs. As JSON (in TypeScript the +An **Object** maps to a database table and exposes automatic CRUD APIs. As JSON (in TypeScript the same literal goes inside `ObjectSchema.create({...})`): ```json @@ -83,8 +82,8 @@ Choose the posture from the request, not by habit: a business object a team shares is `public_read_write` (`private` would hide every colleague's records from everyone else); `private` fits personal or sensitive data only its owner should see (HR reviews, pay, personal notes); `public_read` fits reference data -everyone reads and the owner maintains (price lists, policies, notices). This -axis is distinct from `ownership`, which decides whether `owner_id` exists at +everyone reads and the owner maintains (price lists, policies, notices). +`ownership` is a separate axis: whether `owner_id` exists at all (Relationship Patterns below). **Important optional properties:** @@ -92,8 +91,8 @@ all (Relationship Patterns below). | Property | Default | Description | |:---------|:--------|:------------| | `label` | Auto from `name` | Human-readable singular label | -| `pluralLabel` | — | Plural form (e.g., "Accounts") — on 31/31 objects in the reference apps; author it alongside `label` | -| `icon` | — | Icon name for nav, list headers and lookup pickers — on 31/31 objects in the reference apps | +| `pluralLabel` | — | Plural form (e.g., "Accounts"); author it alongside `label` | +| `icon` | — | Icon for nav, list headers and lookup pickers; give every object one | | `color` | `gray` | Tile colour, one of `gray` `blue` `teal` `green` `amber` `orange` `red` `pink` `purple` (no hex); the console draws `icon` white on it. Give every object one; avoid repeats in one app | | `highlightFields` | derived | Ordered field keys used as a record's compact face: the columns a **related list** renders on the parent's detail page, and what a lookup picker shows. Declare it on the CHILD object (see [Relationships](./rules/relationships.md)) | | `namespace` | — | **Not a schema key** — an unknown key is refused, so authoring it is a build error. Embed the prefix directly in `name` instead | @@ -274,12 +273,11 @@ column by declaring `storage: { notNull: true }`. CLI details: see ### Naming Rules Summary `snake_case` object names and field keys, `camelCase` schema properties, -lowercase option values — incorrect/correct examples: [rules/naming.md](./rules/naming.md). +lowercase option values — examples: [rules/naming.md](./rules/naming.md). ### Field Type Selection -The full table, per-type config and traps: [rules/field-types.md](./rules/field-types.md). -From here, three to get right: credentials are `secret` (**encrypted-at-rest**, ADR-0100) — +Three to get right here (the rest: [rules/field-types.md](./rules/field-types.md)): credentials are `secret` (**encrypted-at-rest**, ADR-0100) — never `password`, which on a generic object is **plaintext at rest**; `user` is the person picker; `formula` takes CEL in `expression` (a `{ dialect: 'cel', source }` envelope — `F\`...\`` in TypeScript; see **objectstack-formula**). @@ -312,9 +310,8 @@ picker; `formula` takes CEL in `expression` (a `{ dialect: 'cel', source }` enve | Approval, review, routing, audit trail | not objects: an approval is a flow node (**objectstack-automation**) and its trail is platform history; model only the people it references (approver, reviewer), as `user` fields beside the owner | | Record owner | the platform's `owner_id` (`ownership: 'user'`, the default), also when the request says assignee, 负责人 or 处理人 — never a hand-added owner field, a second owner that owner-scoped visibility and "My records" views never read. A handler the request names apart from the owner is a `user` field that grants no access, with a label no other visible field carries, injected ones included: `owner_id` (Owner, 负责人), `created_by` (创建人), `updated_by` (更新人), `created_at` (创建时间), `updated_at` (更新时间). `ownership: 'none'` only for a shared catalog or a pure junction table | -> **`multiple: true` lookup ≠ junction object.** A multi-value lookup is stored -> and read as an **array of ids** on the record — reference elements positionally -> (`{record.tags.0}` in flow values). +> **`multiple: true` lookup ≠ junction object.** Its value is an **array of ids**: +> reference elements positionally (`{record.tags.0}` in flow values). ### Validation Patterns @@ -359,12 +356,15 @@ database layer. ## Object Extension Model To add fields/validations/indexes to an object you do not own, author -`defineObjectExtension({ extend, fields, fieldPatches, priority })` and register it on +`defineObjectExtension({ extend, fields, fieldPatches, place, priority })` and register it on `defineStack({ objectExtensions: [...] })`. `priority` sets merge order (default -`200`, range `0–999`); an extension can add but never remove, except that a new -`label` without `pluralLabel` clears the base plural unless a tenant authored it (set both). ⛔ Not the same key -as object-level `ownership` (the record-ownership enum -`'user' | 'business_unit' | 'org' | 'none'`). +`200`, `0–999`); an extension adds, never removes, except that a new +`label` without `pluralLabel` clears the base plural unless a tenant authored it (set both). ⛔ `extend` +is not object-level `ownership` (`'user' | 'business_unit' | 'org' | 'none'`). + +`place: [{ field: 'tax_id', group: 'basic', after: 'industry' }, { list: 'acme_contract', after: 'crm_opportunity' }]` +puts the extension's own fields, groups (`{ group: { key, label }, after }`) and child lists +after (or `before`) a named item, where the target declares `fieldGroups` / `relatedLists`. **Relabel a field the owner declares with `fieldPatches` — never by redeclaring it in `fields`**, which takes the field over whole and cuts it off from the diff --git a/skills/objectstack-data/evals/README.md b/skills/objectstack-data/evals/README.md index 8859097f135..4d2473e2efc 100644 --- a/skills/objectstack-data/evals/README.md +++ b/skills/objectstack-data/evals/README.md @@ -6,7 +6,8 @@ JSON fixtures in the objectui shape (`skill_name`, `evals[]`: `prompt`, - `objects-fields-relationships.json` — naming, field types (`secret` vs `password`), relationships (junction vs multi-value lookup, `deleteBehavior`, on a `user` field too), validation (`state_machine`, unique **index**), - conditional field rules, the record owner (负责人 is `owner_id`). + conditional field rules, the record owner (负责人 is `owner_id`), an + object extension placing what it brings (`place`). - `hooks-security-seeds-datasources.json` — search mirrors via hooks, permission-set scopes, external datasources, seeds (`externalId`, CEL dynamic values). diff --git a/skills/objectstack-data/evals/objects-fields-relationships.json b/skills/objectstack-data/evals/objects-fields-relationships.json index 30462bf6f54..f5e2e27086b 100644 --- a/skills/objectstack-data/evals/objects-fields-relationships.json +++ b/skills/objectstack-data/evals/objects-fields-relationships.json @@ -446,6 +446,25 @@ "definePage" ] } + }, + { + "id": 26, + "prompt": "Our add-on package `acme_contracts` depends on HotCRM (`hotcrm`, namespace `crm`). Its extension of `crm_account` adds a `tax_id` text field, and the package ships an `acme_contract` object whose `account` lookup points at `crm_account`. On the account record page, show Tax ID right after Industry in the Basic section, and the Contracts tab right after Opportunities. `crm_account` declares `fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['name', 'industry', 'website'] }]` and `relatedLists: ['crm_contact', 'crm_opportunity', 'crm_lead', 'sys_activity']`. We cannot edit HotCRM.", + "expected_output": "Two `place` entries on the package's own object extension, registered in its stack's `objectExtensions`: `defineObjectExtension({ extend: 'crm_account', fields: { tax_id: Field.text({ label: 'Tax ID' }) }, place: [{ field: 'tax_id', group: 'basic', after: 'industry' }, { list: 'acme_contract', after: 'crm_opportunity' }] })`. `place` arranges only what the extension brings (its own field, its package's child list), each right after (or `before`) an item the account already has, and it applies here because the account declares `fieldGroups` and `relatedLists`. Without it the field arrives after the account's own and the Contracts tab at the end of the tabs, before the activity stream. The extension does not carry `fieldGroups` or `relatedLists` of its own (an extension has neither key), does not redeclare the account, and nothing in HotCRM is edited.", + "files": [], + "assertions": { + "must_contain": [ + "defineObjectExtension", + "extend: 'crm_account'", + "place:", + "after: 'industry'", + "after: 'crm_opportunity'" + ], + "must_not_contain": [ + "name: 'crm_account'", + "overrides:" + ] + } } ] } diff --git a/skills/objectstack-ui/rules/record-page.md b/skills/objectstack-ui/rules/record-page.md index 5cba44f3975..71d994c9ee3 100644 --- a/skills/objectstack-ui/rules/record-page.md +++ b/skills/objectstack-ui/rules/record-page.md @@ -20,8 +20,8 @@ every related list is a tab, then `sys_attachment` (with `enable.files`), lists show, in order (unlisted approvals and the stream still follow): "tasks first" lists every tab to keep, `'task'` first; leaving out `'sys_attachment'` drops attachments. `{ list, label, columns }` (child field names) titles one list; -a built-in is a bare name. A child list another package adds is hidden by a -`relatedLists` that does not name it (no package places its own list yet). On the +a built-in is a bare name. A child list another package adds still shows, after +the named lists or where its extension's `place` puts it (objectstack-data). On the CHILD's reference field `relatedList: false` hides the list and `relatedListFilter` (Query-DSL) is AND-composed with the parent condition; rows follow the child's default list view `sort`. Only when asked for a child