diff --git a/.changeset/34770-skill-router-ui.md b/.changeset/34770-skill-router-ui.md new file mode 100644 index 00000000000..c7c94e25ccc --- /dev/null +++ b/.changeset/34770-skill-router-ui.md @@ -0,0 +1,26 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): objectstack-ui's SKILL.md is a router: first checks, run-time traps, where each rule lives + +Clause-②: no +Metadata-protocol: none + +`skills/objectstack-ui/SKILL.md` goes from 15.7 KB to 9.0 KB and now holds three things. No rule's teaching changes; text moved, and the page says where it went. + +- **First checks.** The installed `@objectstack/spec` version against the skill's `compatibility` line; the object's declaration and the project's own view, app, action and dataset files; the type's contract (`references/_index.md` points at the Zod source in `node_modules/@objectstack/spec/src/`, which decides what to write; a running environment serves the parsed shape as JSON Schema at `GET /api/v1/meta/types`, where a defaulted key reads as required); `os validate` before reporting done. +- **Seven traps that parse and then fail at run time.** A long form stays `simple`; a record with its line items is `inlineEdit` on the child's `master_detail` field (and `enable.apiMethods` must list `'bulk'`); a persisted chart binds a declared dataset; a filter token is presentation scope, not security; the object declares its record page. Two keep their own headings: `List Views` (keep the view kind the request names, with the nine kinds) and `Actions` (an operation is an `action` whose body calls the API). +- **Where to go.** One table from the task to the file to open: list views, form views, navigation, record page, actions, dashboards and reports, pages and docs, and the React-tier block contract. + +The Navigation Item Types, Action Types and Report Types tables stay in `SKILL.md`, with the item and action keys behind their homes. + +Where the rest moved, each under its old heading text: + +- `rules/list-views.md` now carries **Form Views** (the three types, the long-form paragraph, the public form), **Master-Detail Forms (parent + child line items)** and **Field Conditional Rules in Forms**, plus the column-count pitfall under Column Features. +- `rules/navigation.md` opens with `App.create`, the one-App-per-package rule, each navigation item type's keys (`label` and `icon` on every type but `separator`), `requiresObject` / `requiresService` and the `AppContextSelector` note. +- `rules/actions.md` opens with what an action is, where it is registered, and why a record button needs a placement and a `js` body with `api.write`; a bare field ref in `visible` or `disabled` fails `os validate`, and a parameterized bulk mutation is `script`. +- `rules/dashboards.md` says an omitted widget `layout` auto-flows, `position` is not a widget key, and a widget binding that resolves to nothing declared fails `os validate`. +- `rules/pages.md` points at objectstack-query `rules/filters.md` for relative-date placeholders. + +A reader who linked `SKILL.md#date-macros--filter-placeholders`, `#master-detail-forms-parent--child-line-items`, `#form-views`, `#common-pitfalls` or `#verify-your-work` finds those headings gone from `SKILL.md`: the first is trap 4 and objectstack-query `rules/filters.md`; the second and third are in `rules/list-views.md`; `#common-pitfalls` is in `rules/list-views.md` (Column Features) and `rules/dashboards.md`; `#verify-your-work` is first check 4, with what the gate catches in `rules/actions.md` and `rules/dashboards.md`. diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index cfd2beb27fe..8c2a1fef0c5 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -917,7 +917,27 @@ export const CEILINGS = new Map([ // above; same standing ruling (record 6513306068). 15569 bytes (15549 priced) -> 15704 // (15684 priced) -> 3921 tokens, pinned AT the measurement, zero headroom. // ceil(($(wc -c < skills/objectstack-ui/SKILL.md) - 20) / 4) == ceil(15684 / 4) - ['skills/objectstack-ui/SKILL.md', 3921], + // 3921 -> 2239 (#34770 part 1, the entry file becomes a router; decision record + // 6943107981, S3 = A, whose target reads "a router-sized `SKILL.md` (6–9 KB, at most 500 + // lines)" with "pointers to the contract instead of restated lists"): LOWERED. The entry + // keeps four first checks (the installed version, what the project already has, the + // type's contract, `os validate`), the run-time traps, the routing table, the two + // sections the hosted cloud serves by exact heading (`### List Views`: the nine kinds and + // the keep-the-kind rule; `## Actions`: the write-button rule and the Action Types + // table), and the three Leg 2 enumerations `check-skill-identifier-liveness` binds to + // this file by heading (`### Navigation Item Types`, `### Action Types`, + // `## Report Types`). What left, and its home: Form Views, Master-Detail Forms and Field + // Conditional Rules in Forms -> `rules/list-views.md`; the App intro, the one-App-per- + // package paragraph, the nav-item keys column and the `requiresObject` / + // `AppContextSelector` notes -> `rules/navigation.md`; the action intro and the + // placement / write-discarded detail -> `rules/actions.md`; what `os validate` catches + // (a bare field ref, an unresolved widget binding) -> `rules/actions.md` and + // `rules/dashboards.md`; the `layout` auto-flow clause -> `rules/dashboards.md`. The + // Detailed Rules list and the CRM blueprint are the routing table now. 15704 bytes + // (15684 priced) -> 8974 (8954 priced) -> 2239 tokens; the ceiling follows the file down + // to the measurement, the ratchet's ordinary direction. + // ceil(($(wc -c < skills/objectstack-ui/SKILL.md) - 20) / 4) == ceil(8954 / 4) + ['skills/objectstack-ui/SKILL.md', 2239], // 8333 -> 6193: RE-LOCK at the landed count after the #19715 split (decision // batch #213 item 1, maintainer 「1 2 4 同意」): the worked R1, the report // template and the v17-canonical shapes block moved VERBATIM into @@ -1329,7 +1349,23 @@ export const CEILINGS = new Map([ // half carries it: the file is 11106 -> 11231 bytes -> 2808 tokens, zero headroom before, // ceiling +31, pinned AT the measurement. // ceil($(wc -c < skills/objectstack-ui/rules/actions.md) / 4) == ceil(11231 / 4) - ['skills/objectstack-ui/rules/actions.md', 2808], + // 2808 -> 3031 (#34770 part 1): RECEIVES text the router split moved out of SKILL.md, + // no new teaching: from § Actions the two-sentence intro (what an action is, where it is + // registered, a link back to the Action Types table) and the placement / write detail + // the entry's Actions section no longer spells (`objectName` folds the action into + // record surfaces, `rowActions` / `bulkActions` name it, the two lint codes, why the + // body is `js` and why it declares `api.write`); from § Verify your work one sentence + // on the `disabled` bullet (a bare field ref in `visible` or `disabled`, `done` for + // `record.done`, fails `os validate`); from the CRM blueprint's User actions row, that a + // parameterized bulk mutation is `script`. The file is 11231 -> 12123 bytes (+892) -> + // 3031 tokens, zero headroom before, ceiling +223, pinned AT the measurement. Authority: the ruling of record that + // orders the entry file down to router size, decision record 6943107981 S3 = A (this + // header: a ruling of record that orders text into a file authorises its own measured + // delta), quoted in the PR body beside the standing 2026-10-27 ruling + // 「A:先削重复,余额按实测提高」 (record 6513306068). The seven hand-authored + // objectstack-ui files net -149 bytes across the move (100990 -> 100841). + // ceil($(wc -c < skills/objectstack-ui/rules/actions.md) / 4) == ceil(12123 / 4) + ['skills/objectstack-ui/rules/actions.md', 3031], // 6090 -> 6252 (#19715, card item 4): a 5-line table of contents at the top, // anchors to the file's existing headings, nothing else changed. +162 tokens, // zero headroom to absorb any of it, ceiling +162. Maintainer ruling @@ -1355,7 +1391,16 @@ export const CEILINGS = new Map([ // `DATASET_INVALID` at compile); paid by the `compareTo` paragraph's restated "no second // widget-side vocabulary" sentence and the `DatasetSchema` source pointer that // `references/_index.md` already carries; 24926 bytes -> 6232 tokens, zero headroom. - ['skills/objectstack-ui/rules/dashboards.md', 6232], + // 6232 -> 6274 (#34770 part 1): RECEIVES two clauses from SKILL.md, no new teaching. + // From § Common Pitfalls 2: an omitted widget `layout` auto-flows, and `position` is not + // a widget key (the closed schema refuses it by name, which is why the rest of that + // pitfall left the skill). From § Verify your work: a widget naming a `dataset` / + // `dimensions` / `values` that resolves to nothing declared (an empty chart) fails + // `os validate`. The file is 24928 -> 25094 bytes (+166) -> 6274 tokens, zero headroom + // before, ceiling +42, pinned AT the measurement. Authority as the `rules/actions.md` + // row above. + // ceil($(wc -c < skills/objectstack-ui/rules/dashboards.md) / 4) == ceil(25094 / 4) + ['skills/objectstack-ui/rules/dashboards.md', 6274], // 3011 -> 3141 (#19715, card item 4): a 5-line table of contents at the top, // anchors to the file's existing headings, nothing else changed. +132 tokens, // of which the row's 2 tokens of headroom absorb 2; the CEILING moves 130. @@ -1384,7 +1429,20 @@ export const CEILINGS = new Map([ // SKILL.md row above: cloud#3659 letter A (6682024726) via record 6513306068, quoted // verbatim in the PR body. // ceil($(wc -c < skills/objectstack-ui/rules/list-views.md) / 4) == ceil(13802 / 4) - ['skills/objectstack-ui/rules/list-views.md', 3451], + // 3451 -> 4448 (#34770 part 1): RECEIVES the form half of SKILL.md § View Types, moved + // whole and no new teaching: `## Form Views` (the three-type table, the long-form + // paragraph, the public-form row of the CRM blueprint as one sentence), `## Master-Detail + // Forms (parent + child line items)` and `## Field Conditional Rules in Forms`, each + // under its SKILL.md heading text; one table-of-contents line for them; and Common + // Pitfalls 1 as one sentence under Column Features. This file already teaches the + // `defineView` container the form views live in, so they did not need a file of their + // own. The list half stays in SKILL.md under `### List Views`, the section the hosted + // cloud serves by that heading. Dropped on the way, with a home: the "Read side" pointer + // (the entry's routing table names Record Page). The file is 13776 -> 17790 bytes + // (+4014) -> 4448 tokens, the row's 7 tokens of headroom absorbed, ceiling +997, pinned + // AT the measurement. Authority as the `rules/actions.md` row above. + // ceil($(wc -c < skills/objectstack-ui/rules/list-views.md) / 4) == ceil(17790 / 4) + ['skills/objectstack-ui/rules/list-views.md', 4448], // 2273 -> 2196 (#27059): LOWERED. The Surface bullet points at `rules/record-page.md`, // says create / edit is a modal or the `editMode: 'page'` route, and the Overlay-width // bullet moved there whole (the `size` bucket, the deprecated pixel keys); the ceiling @@ -1393,7 +1451,18 @@ export const CEILINGS = new Map([ // list are English (the shipped skill text is English-only), and the bullet's repeated // objectui ADR-0055 citation (the section heading carries it) is gone; the ceiling follows // the file down to the measurement (8734 bytes). - ['skills/objectstack-ui/rules/navigation.md', 2184], + // 2184 -> 2564 (#34770 part 1): RECEIVES SKILL.md § App Navigation, no new teaching: + // the `App.create` / `defineStack({ apps })` sentence, the one-App-per-package paragraph + // whole, the Navigation Item Types table's Properties column as one keys-by-type + // sentence (`label` and `icon` on every type but `separator`, as that column had it) + // with the `componentRef` registry-key gloss (the type and purpose columns stay + // in SKILL.md, where the Leg 2 binding reads them), the `requiresObject` / + // `requiresService` callout, and the `AppContextSelector` bullet of § Date Macros. The + // file is 8727 -> 10255 bytes (+1528) -> 2564 tokens, the row's 2 tokens of headroom + // absorbed, ceiling +380, pinned AT the measurement. Authority as the `rules/actions.md` + // row above. + // ceil($(wc -c < skills/objectstack-ui/rules/navigation.md) / 4) == ceil(10255 / 4) + ['skills/objectstack-ui/rules/navigation.md', 2564], // 5501 -> 5692 (#19715, card item 4): a 5-line table of contents at the top, // anchors to the file's existing headings, nothing else changed. +191 tokens, // zero headroom to absorb any of it, ceiling +191. Maintainer ruling @@ -1401,7 +1470,11 @@ export const CEILINGS = new Map([ // 「1 2 4 同意」. // 5692 -> 5669 (#27059): LOWERED. The `tabs`-slot sentence is a one-line pointer at // `rules/record-page.md`; the ceiling follows the file down to the measurement (22673 bytes). - ['skills/objectstack-ui/rules/pages.md', 5669], + // 5669 -> 5661 (#34770 part 1): LOWERED. The variable-substitution note points at the + // owner of the relative-date vocabulary (objectstack-query `rules/filters.md`) in place + // of the SKILL.md § Date Macros anchor the router no longer has; the ceiling follows the + // file down to the measurement (22644 bytes). + ['skills/objectstack-ui/rules/pages.md', 5661], // objectstack-ui `rules/record-page.md` — the sixth rules file, ordered by card #27059 // (record-page epic #26676 child 8, dispatched by ui seat 1 2026-11-01, with the seat's // ruling that the record page gets its own rules file rather than rows in the files diff --git a/skills/objectstack-ui/SKILL.md b/skills/objectstack-ui/SKILL.md index 5639025b606..b8413811154 100644 --- a/skills/objectstack-ui/SKILL.md +++ b/skills/objectstack-ui/SKILL.md @@ -25,157 +25,136 @@ metadata: # UI Design — ObjectStack UI Protocol ---- +## First checks + +1. **Version.** This skill targets the `@objectstack/spec` major in its + `compatibility` line. Read the installed one + (`node_modules/@objectstack/spec/package.json`); where they differ, the + installed contract is right. +2. **Read what exists.** Read the object's declaration (fields, `fieldGroups`, + relationships) and the project's own files for it (the globs under Where to + go). Add beside what is there; reuse a declared dataset, field group or view. +3. **Read the type's contract.** [references/_index.md](./references/_index.md) + points at each type's Zod source in `node_modules/@objectstack/spec/src/`. + `Read` it for exact keys, enum members and refusals, never from memory: it + decides what to write. A running environment serves the parsed shape as + JSON Schema (`GET /api/v1/meta/types`, `entries[].schema`): a defaulted + key reads as required and a bare-string predicate as `{}`. +4. **Verify before reporting done.** `os validate` (`npm run validate` in a + scaffolded project; `os build` runs the same gates). Most traps below pass + it. + +## Traps — each parses, then fails at run time + +Two more: [List Views](#list-views), [Actions](#actions). + +1. **A long form stays `simple`**: collapse what is rarely filled and size it + with `columns` and `modalSize`. `tabbed` flags a required field only on its + own tab and overflows on a phone + ([Form Views](./rules/list-views.md#form-views)). +2. **A record entered with its line items is `inlineEdit` on the child's + `master_detail` field**, before any custom page, and its grid needs no "Add + line" button. A parent or child declaring `enable.apiMethods` must list + `'bulk'`, or the save is refused `405` + ([Master-Detail Forms](./rules/list-views.md#master-detail-forms-parent--child-line-items)). +3. **A persisted chart binds a declared dataset.** A widget or report names a + `defineDataset` and selects its `dimensions` / `values` by name; an object + without one has no analytics face. A dataset is narrow: a window, a to-many + rollup or a computed dimension is a stored field or app code, never forced + into one; an ad-hoc chart in a `kind: 'react'` page needs none. Read + [Dashboards](./rules/dashboards.md#dataset-bound-widgets) before writing any + widget, dataset or chart. +4. **A filter token is presentation scope, not security.** `{current_user_id}`, + `{today}` and the rest (vocabulary: objectstack-query → `rules/filters.md`, + load it before writing one; an unrecognised token is a build error) decide + what a surface *shows*; RLS decides what a caller may *read*. Such a filter + must never be what keeps a user from someone else's data. +5. **The object declares its record page.** Related lists, their order and + filter are flags on the object and its fields, not a page file; how a record + opens is one list-view key, and the reader's own display choices are never + metadata ([Record Page](./rules/record-page.md)). + +## Where to go + +| Authoring | In | Open first | +|:--|:--|:--| +| A list, board, calendar, gallery or gantt: columns, `filter`, quick filters, toolbar search, sorting, grouping | `src/views/*.view.ts` | [List Views](./rules/list-views.md) | +| A form (`simple` / `tabbed` / `wizard`): width, columns and `sections`; master-detail (a parent with line items), a public form, field conditional rules | `src/views/*.view.ts` | [Form Views](./rules/list-views.md#form-views) | +| An app and its navigation; who sees or opens it; object nav, a `filters` slice or an interface page | `src/apps/*.app.ts` | [Navigation](./rules/navigation.md) | +| What a record page shows: related lists, a slotted or full page, drawer or page | the object | [Record Page](./rules/record-page.md) | +| A button or operation: `locations`, visibility, dialog and toast copy, params, new tab, the body's `ctx` | `src/actions/*.actions.ts` | [Actions](./rules/actions.md) | +| A number, chart, KPI or report over records: datasets, widgets, dashboard filters, `compareTo`, date bucketing, drilldown, cubes | `src/datasets/*.dataset.ts`, `src/dashboards/*.dashboard.ts`, `src/reports/*.report.ts` | [Dashboards](./rules/dashboards.md) | +| A page (regions, components, print, `kind: 'html'` / `'react'` source, styling) or package docs | `*.page.ts`, `src/docs/*.md` | [Pages & Docs](./rules/pages.md) | +| The props of a block in a `kind: 'react'` page | | [react-blocks.md](./references/react-blocks.md) | ## View Types ### List Views -| Type | When to Use | -|:-----|:------------| -| `grid` | Standard data table — default for most objects | -| `kanban` | Visual board with columns (status-driven workflows) | -| `gallery` | Card-based masonry layout (visual catalogues, contacts) | -| `calendar` | Date-based scheduling (events, tasks, bookings) | -| `timeline` | Chronological activity stream | -| `gantt` | Project management with dependency tracking | -| `map` | Geospatial records with `location` fields | -| `chart` | Aggregate visualisation over the object (mini chart view) | -| `tree` | Self-referencing hierarchy (tree-grid) | +A list view's `type`: `grid` (the default table), `kanban` (a board by status), +`gallery` (cards over an image, avatar or file field), `calendar`, `timeline` +(a chronological stream), `gantt` (start/end bars with dependencies), `map` +(`location` fields), `chart` (an aggregate over the object), `tree` (a +self-referencing hierarchy). **Keep the kind the request names.** A photo wall, card wall or catalogue of covers is `gallery` (an image, avatar or file field as `gallery.coverField`), a schedule or timeline over a start/end date pair is `gantt`, a board is `kanban`; never downgrade a named kind to `grid`: the file parses and the user -opens a table where they asked for a board. Adding one beside the list, and -the empty board over a field added in the same change: +opens a table. "Add a board" is a NEW `listViews` entry, never `list` retyped, +and a board over a field added in the same change opens empty: [List Views](./rules/list-views.md#adding-a-board-calendar-gallery-or-gantt-beside-the-list). -### Form Views - -| Type | When to Use | -|:-----|:------------| -| `simple` | Stacked sections on one scrolling page — the default, at any field count | -| `tabbed` | One tab per section — only for sections read apart; a required field on another tab is flagged only on its tab, and the tab strip overflows on a phone | -| `wizard` | Step-by-step flow — guided data entry (onboarding, applications) | - -**A long form stays `simple`: collapse what is rarely filled** with -`collapse: 'collapsed'` on the object's `fieldGroups` entry, or `collapsed: true` -on a form section listing its own `fields`. `columns` (form or section) is a -per-row ceiling a narrow screen lowers; unset, a section draws two, so set `3` -for a wide data-entry form. `modalSize` (`sm` to `full`) sizes the New / Edit -dialog; unset, the field count picks `lg` or `xl`. - -### Master-Detail Forms (parent + child line items) - -To let users enter a record **together with its child line items** (invoice + -lines, project + tasks) and save them **atomically**, you almost never need a -custom page or form config. Prefer, in order: - -1. **Relationship `inlineEdit` (default, zero UI config).** Declare it in the - DATA MODEL — set `inlineEdit` on the child's `master_detail` field that - references the parent. Every standard New/Edit form for the parent (modal, - drawer, full-page) then auto-renders the children and saves parent + children - in one atomic `/api/v1/batch`. **No view metadata needed.** A parent or child - declaring `enable.apiMethods` must list `'bulk'`, or that save is refused - `405 OBJECT_API_METHOD_NOT_ALLOWED`. The - `true` / `'grid'` / `'form'` ladder and what each value picks: - **objectstack-data → Relationships → Inline Editing**. - -2. **Form view `subforms` (override / tuning).** Add to a form view only when you - need to override the derived columns/order, or expose a child the - relationship didn't mark inline: - - ```typescript - form: { - type: 'simple', - sections: [{ group: 'invoice_header' }], // a declared fieldGroup - subforms: [ - { childObject: 'invoice_line', // set `columns` only to override - title: 'Line Items', addLabel: 'Add line' }, - ], - }, - ``` - -3. **`object-master-detail-form` page block (bespoke layout).** Use a page only - for free-form layouts. Same `details: [{ childObject }]` shorthand. - -**Line-item grid behaviors (`grid` mode).** The editable grid is a real -spreadsheet-style line editor, and -every behaviour is derived from the DATA MODEL — computed columns, catalog -typeahead auto-fill, persisted drag-reorder, and the live Subtotal → Tax → Total -stack: **objectstack-data → Relationships → Inline Editing**. Three things are -authored on this side: a trailing **ghost** row always exists, so never add an -"Add line" button to the grid (typing in the ghost materialises a row; an -untouched one is never persisted; a record-header action that inserts a priced -line is [Actions](./rules/actions.md)); `autofill: false` opts one column out of the typeahead copy; -and the form's `taxRateField` overrides which parent field drives the totals. - -**Read side — the record page.** Child relationships are related lists on the -parent's record page by default; the flags, slots and open mode: [Record Page](./rules/record-page.md). - -### Field Conditional Rules in Forms - -Conditions that belong to a field's lifecycle — `visibleWhen`, `readonlyWhen`, -`requiredWhen` — are declared on the **DATA MODEL field**, not in the form view; -ObjectUI forms consume them. Their semantics and server behaviour: -[objectstack-data → Conditional Field Rules](../objectstack-data/SKILL.md#conditional-field-rules). - ---- - -## Detailed Rules - -- [List, Kanban & Gantt Views](./rules/list-views.md) — `defineView`, `data`, columns, filtering, `userFilters`, toolbar search, sorting, kanban, gantt. -- [Navigation & Run Modes](./rules/navigation.md) — `App.create`, the three run modes, record presentation. -- [Dashboards, Reports & Cubes](./rules/dashboards.md) — widgets, dataset binding, filters, `compareTo`, bucketing, `options`, drilldown, report config, cubes. -- [Pages & Docs](./rules/pages.md) — page types, regions, components, print pages, the html/react source tiers, styling, package docs. -- [Record Page](./rules/record-page.md) — declarations → page, relationship flags, slotted / full overrides, drawer vs `page`, the reader's own choices. -- [Actions](./rules/actions.md) — `locations`, visibility, examples, `ctx`, new tab, params. - ---- - ## App Navigation -Build an App with `App.create({...})` from -`@objectstack/spec/ui` and register under `defineStack({ apps: [...] })`. +One App per package: `defineStack` refuses a second, so audiences sharing a +product are `requiredPermissions`-gated groups inside it. Hiding an app +(`tabPermissions`) is not gating it: its URL still opens. Both, and each item +type's keys: [Navigation](./rules/navigation.md). -⛔ **At most one App per package** (ADR-0019 (app-as-consumer-unit) D3 as -amended): `defineStack` refuses a second app in a `type: 'app'` and a -`type: 'module'` package alike. A suite (an app package plus its modules) may -surface more apps: each further app goes in a module of its own with the -objects it shows (gone when it is disabled), and the suite composes with -`composeStacks(stacks, { manifest: 'preserve' })`, which serves each app under -its own package id; a flat composition puts them under one and is refused. -Audiences sharing one product and its objects stay -`requiredPermissions`-gated groups **inside** one app. +### Navigation Item Types -Who sees an app (`tabPermissions`) and who may open it (app -`requiredPermissions`): [Navigation](./rules/navigation.md#who-sees-or-opens-an-app). +| Type | Purpose | +|:--|:--| +| `group` | Collapsible group of items | +| `object` | An object list, a named view, a record deep-link, or a `filters` slice | +| `dashboard` | A dashboard | +| `report` | A report | +| `page` | A custom Page | +| `url` | External or custom URL | +| `action` | Run an action instead of navigating | +| `component` | Built-in platform component | +| `doc` | Package docs | +| `separator` | Visual separator | -### Navigation Item Types +## Actions + +**An operation is an `action`, never a view, and a write button must write.** +"Mark as done", "approve", "set status to X" is `defineAction` with +`objectName` and `locations`; with neither `locations` nor a view naming it, +it renders nowhere. `ctx.record` is a read-only snapshot and the body's return +value is applied to nothing: a body that returns or assigns the new values +reports success and changes nothing. Call the API: `type: 'script'`, +`body: { language: 'js', source: "await ctx.api.object('task').update({ id: ctx.recordId, status: 'done' });", capabilities: ['api.write'] }`, +with the option `value`, never its label ([Actions](./rules/actions.md)). -| Type | Properties | Purpose | -|:-----|:-----------|:--------| -| `group` | `label`, `icon`, `expanded`, `children[]` | Collapsible group of items | -| `object` | `objectName`, `viewName?`, `recordId?`, `filters?`, `label`, `icon` | Link to an object list, a named view, a record deep-link, or a `filters` slice on the bare data surface | -| `dashboard` | `dashboardName`, `label`, `icon` | Link to a dashboard | -| `report` | `reportName?`, `label`, `icon` | A report; no `reportName` = the app's report index | -| `page` | `pageName`, `label`, `icon` | Link to a custom Page | -| `url` | `url`, `label`, `icon` | External or custom URL | -| `action` | `actionDef` (`{ actionName, params? }`), `label`, `icon` | Run an action instead of navigating | -| `component` | `componentRef`, `params?`, `label`, `icon` | Built-in platform component; `componentRef` is a colon-joined registry key (`metadata:resource`) | -| `doc` | `book?` / `doc?` (one required), `label`, `icon` | Package docs; inherits docs audience | -| `separator` | — | Visual separator | +### Action Types -> **`requiresObject` / `requiresService`** hide an item whose optional -> system object or kernel service is missing — never hard-code conditional UI. +| `type` | Purpose | +|:--|:--| +| `script` | Run an inline L2 hook body (sandboxed JS) on the server: `body`, or `target` naming a registered function | +| `url` | Navigate to an internal route or external URL | +| `modal` | Open the page named by `target`; a `body` runs only on `script` | +| `flow` | Launch a screen/auto-launched flow by name; a multi-step operation is this, with a flow you also author | +| `api` | Call a registered API endpoint | +| `form` | Open a FormView by name (routed to `/_console/forms/:name`) | ---- +Every type but `script` requires `target`. ## Report Types | Type | When to Use | -|:-----|:------------| +|:--|:--| | `tabular` | Flat data table with columns and filters | | `summary` | Grouped data with subtotals (e.g., revenue by region) | | `matrix` | Cross-tab / pivot table (`rows` down × `columns` across) | @@ -183,122 +162,3 @@ Who sees an app (`tabPermissions`) and who may open it (app There is no `chart` report type — a report *visualizes* via its embedded `chart:` config. - ---- - -## CRM UI Blueprint (Metadata-First) - -| UI Surface | Typical Location | Pattern to Follow | -|:--|:--|:--| -| Multi-view object UI | `src/views/*.view.ts` | Define default `list` + `form`, then named `listViews` / `formViews` for scenarios | -| **Public form** | `src/views/*.view.ts` (formView with `sharing: { enabled: true, allowAnonymous: true, publicLink: 'slug' }`) | Web-to-Lead at `GET/POST /api/v1/forms/:slug` | -| App navigation | `src/apps/*.app.ts` | Grouped nav trees, `viewName` shortcuts, `requiresObject` | -| **Analytics dataset** | `src/datasets/*.dataset.ts` | One per object you want reportable — dashboards and reports bind a **declared** dataset by name, so an object without one has no analytics face | -| Dashboards | `src/dashboards/*.dashboard.ts` | Combine KPI + chart + table widgets with shared `dateRange` and `globalFilters` | -| Reports | `src/reports/*.report.ts` | Select `rows` (dimensions) + `values` (measures) from that dataset; tabular/summary/matrix/joined | -| Record pages | — (synthesized) | The object's declarations produce the page ([Record Page](./rules/record-page.md)) | -| User actions | `src/actions/*.actions.ts` | Use `flow` for orchestration and `script` for parameterized bulk mutations | - ---- - -## Date Macros — Filter Placeholders - -Filter values in list views, dashboards, reports and pages accept relative-date -tokens (`{today}`, `{current_month_start}`, `{30_days_ago}`) and the two session -tokens `{current_user_id}` / `{current_org_id}`. **The vocabulary, both accepted -spellings, the two resolvers and the near-miss list are owned by -objectstack-query → `rules/filters.md` — load it before writing a filter token.** -An unrecognised token is a build error and a runtime throw, never a silent -literal. - -Two rules this package owns, because they are about UI surfaces rather than the -token vocabulary: - -* A filter token is **presentation scope, not security**. It decides what a - surface *shows*; RLS decides what a caller may *read*. Removing a - `{current_user_id}` filter widens a view — it must never be the thing standing - between a user and someone else's data. -* `AppContextSelector` ids (e.g. `{active_package}`) resolve in navigation - `recordId` / `params` only. Filters are not evaluated with the sidebar's - selector state. - ---- - -## Actions - -Actions are user-triggered operations attached to an object or a view. -Register them under `defineStack({ actions: [...] })`. - -### Action Types - -| `type` | Purpose | Required field | -|:---------|:-------------------------------------------------------------------|:---------------| -| `script` | Run an inline L2 hook body (sandboxed JS) on the server | `body` (or `target` = registered function name) | -| `url` | Navigate to an internal route or external URL | `target` | -| `modal` | Open the page named by `target`; a `body` runs only on `script` | `target` | -| `flow` | Launch a screen/auto-launched flow by name | `target` | -| `api` | Call a registered API endpoint | `target` | -| `form` | Open a FormView by name (routed to `/_console/forms/:name`) | `target` | - -**An operation is an `action`, never a view.** "Mark as done", "approve", -"submit", "set status to X" — anything that DOES something to a record — is -`defineAction` metadata; a view only displays. A record button carries -`objectName` (what folds it into that object's record surfaces) and -`locations`; with neither `locations` nor a view naming it in `rowActions` / -`bulkActions` it renders nowhere (`action-no-placement`). **A write button must -write:** `ctx.record` is a read-only snapshot and the body's return value is -applied to nothing, so a body that only returns the new values or assigns to -`ctx.record` changes nothing and still reports success -(`action-record-write-discarded`). Write with `type: 'script'` and -`body: { language: 'js', source: "await ctx.api.object('task').update({ id: ctx.recordId, status: 'done' });", capabilities: ['api.write'] }`: -`js`, because an `expression` body is a pure formula with no I/O; `api.write`, -because the sandbox throws on `ctx.api…update` / `insert` / `delete` without -it; the option `value`, never its label. A multi-step operation is -`type: 'flow'` with `target` naming a flow you also author. - ---- - -## Common Pitfalls - -1. **Too many default columns, or no `link: true` on the primary one.** 6–8 - visible columns is plenty (`hidden` the rest); the name/subject column is - the record link ([Columns](./rules/list-views.md#column-features)). - -2. **Putting widget grid placement in `position`.** - The grid-placement field is `layout: { x, y, w, h }` — `position` is not a - widget key and the closed schema REJECTS it by name. - `layout` is optional: omit it and the widget - auto-flows. - ---- - -## Verify your work - -After authoring any `*.view.ts` / `*.action.ts` / `*.dashboard.ts`, run the -author-time gate before reporting done: - -```bash -os validate # CEL predicates (record.) + widget bindings + schema -# or: os build # the same gates, plus emits dist/ -``` - -Two UI-specific traps it catches, otherwise met only at runtime: - -- **Action / field predicate** — a bare field ref in an action `visible` / - `disabled` or a field `visibleWhen` (`done` instead of `record.done`) - faults on *every* record: the action hides (`visible`) or greys out - (`disabled`), the field shows; the console logs the fault. -- **Dashboard widget binding** — a widget `dataset` / `dimensions` / `values` - that doesn't resolve to a declared dataset/field renders an empty chart - (ADR-0021). - -In a scaffolded project the gate is `npm run validate`. - ---- - -## References - -See [references/_index.md](./references/_index.md) for the full list of Zod -schemas (with one-line descriptions) — pointers into -`node_modules/@objectstack/spec/src/`. Always `Read` the source for exact field -shapes; do not rely on memory of property names. diff --git a/skills/objectstack-ui/rules/actions.md b/skills/objectstack-ui/rules/actions.md index e4020ec62ec..6da87a0d9fc 100644 --- a/skills/objectstack-ui/rules/actions.md +++ b/skills/objectstack-ui/rules/actions.md @@ -1,5 +1,20 @@ # Actions +Actions are user-triggered operations attached to an object or a view. +Register them under `defineStack({ actions: [...] })`; the six types: +[Action Types](../SKILL.md#action-types). A parameterized bulk mutation is +`script`. + +**A record button needs a placement and a body that writes.** `objectName` +folds the action into that object's record surfaces; with neither `locations` +nor a view naming it in `rowActions` / `bulkActions` it renders nowhere +(`action-no-placement`). A body that returns or assigns the new values writes +nothing (`action-record-write-discarded`): it calls +`ctx.api.object(...).update(...)` in `language: 'js'`, because an `expression` +body is a pure formula with no I/O, with `capabilities: ['api.write']`, +because the sandbox throws on `ctx.api…update` / `insert` / `delete` without +it. + ## Where Actions Appear (`locations`) | Value | Surface | @@ -14,7 +29,7 @@ ## Visibility, Disable & Feedback - `visible` — a bare CEL predicate over the current record (prefer the `P\`...\`` template; `record.` resolves identically on every surface, never `${…}`- or `{…}`-wrapped — see `objectstack-formula`); when false the action is **hidden**. -- `disabled` — `boolean` **or** a CEL predicate; when true the action **shows but greys out**. +- `disabled` — `boolean` **or** a CEL predicate; when true the action **shows but greys out**. A bare field ref in either (`done` for `record.done`) fails `os validate`. - `disabledReason` — an I18nLabel (a sentence or an inline locale map) a greyed action shows as its hover title and accessible description. Display-only: never a predicate and never a gate (the hook or permission still refuses). Omit it to keep the console's default "Not available for this record"; a blank one is refused, and `disabledMessage` / `disabledTooltip` / `disabledHint` / `disabledText` are refused naming this key. The reason goes here, not in `description`. - `pressed` — a CEL predicate over the same scope as `visible` that marks the action as already done by this reader: while TRUE the record header draws it pressed (`aria-pressed`). Display-only, never a gate; a boolean literal is refused (a constant is a style, not a reader's state), and `active` / `activeWhen` / `pressedWhen` are refused naming this key. A per-reader fact (the reader's vote) is a block the object declares under `attachedOnRead`, filled per caller by a service or `afterFind` hook, read as `has(record.viewer) && record.viewer.vote == 'helpful'`. - `confirmText` — set for any destructive or irreversible operation; the confirm dialog of a param-less action. A registered action is refused it beside a non-empty `params` (put the question on `description`); a view's `bulkActionDefs` entry pairs the two by its own contract. diff --git a/skills/objectstack-ui/rules/dashboards.md b/skills/objectstack-ui/rules/dashboards.md index 530549890ee..9ad6649b065 100644 --- a/skills/objectstack-ui/rules/dashboards.md +++ b/skills/objectstack-ui/rules/dashboards.md @@ -10,7 +10,8 @@ Dashboards are a grid of widgets (`columns` × `rowHeight`) sharing a `dateRange` scrubber and `globalFilters`. Each widget binds a `dataset` -(below), picks a chart `type`, and sets a `layout: {x,y,w,h}`. +(below), picks a chart `type`, and sets a `layout: {x,y,w,h}` (omitted, the +widget auto-flows; `position` is not a widget key). ### Widget Types @@ -36,8 +37,9 @@ dashboard widget, a report, and a list `type:'chart'` view all **bind a `dataset and select named `dimensions` + `values`**; the dataset owns the base object, allowed joins, intrinsic filter, dimensions, and certified measures. A widget **requires `dataset` + `values`**; the closed schema rejects `object` / -`categoryField` / `valueField` / `aggregate` by name, and one lacking `dataset` -fails `os validate`. +`categoryField` / `valueField` / `aggregate` by name, and one lacking `dataset`, +or naming a `dataset` / `dimensions` / `values` that resolves to nothing +declared (an empty chart), fails `os validate`. A widget's presentation-scope `filter` flows into the query as the runtime filter; keep `filter` on the widget when binding a dataset. diff --git a/skills/objectstack-ui/rules/list-views.md b/skills/objectstack-ui/rules/list-views.md index 5357aeb80ed..ff5e666d98d 100644 --- a/skills/objectstack-ui/rules/list-views.md +++ b/skills/objectstack-ui/rules/list-views.md @@ -5,6 +5,7 @@ - [End-User Quick Filters](#end-user-quick-filters-userfilters-adr-0047) · [Toolbar Search](#toolbar-search-searchablefields-adr-0061) - [Configuring Kanban Views](#configuring-kanban-views) - [Configuring Gantt Views](#configuring-gantt-views) +- [Form Views](#form-views) · [Master-Detail Forms](#master-detail-forms-parent--child-line-items) ## Configuring a List View @@ -81,6 +82,9 @@ columns: [ | `link` | Make this the primary navigation link | | `summary` | Footer aggregation: `count`, `sum`, `avg`, `min`, `max`, etc. | +6–8 visible columns is plenty (`hidden` the rest); the name/subject column +carries `link: true`. + **Inline editing is on by default**, under the permission gate: a user who may `update` the object edits a cell in place. A list whose records are read-only by nature — a log, an audit trail, a history, a report roll-up — declares @@ -332,3 +336,79 @@ const timeline: ListView = { Rows with children (or `type: 'summary'`) are **summary bars**: dragged as a group, **no resize handles**. Leaf tasks resize unless `locked: true`. + +--- + +## Form Views + +Field width, column count and the `sections` ladder: +[Record Presentation](./navigation.md#record-presentation--surface-width--columns-are-auto-derived). + +| Type | When to Use | +|:-----|:------------| +| `simple` | Stacked sections on one scrolling page — the default, at any field count | +| `tabbed` | One tab per section — only for sections read apart; a required field on another tab is flagged only on its tab, and the tab strip overflows on a phone | +| `wizard` | Step-by-step flow — guided data entry (onboarding, applications) | + +**A long form stays `simple`: collapse what is rarely filled** with +`collapse: 'collapsed'` on the object's `fieldGroups` entry, or `collapsed: true` +on a form section listing its own `fields`. `columns` (form or section) is a +per-row ceiling a narrow screen lowers; unset, a section draws two, so set `3` +for a wide data-entry form. `modalSize` (`sm` to `full`) sizes the New / Edit +dialog; unset, the field count picks `lg` or `xl`. + +**A public form** is a form view with +`sharing: { enabled: true, allowAnonymous: true, publicLink: 'slug' }`: +Web-to-Lead at `GET/POST /api/v1/forms/:slug`. + +## Master-Detail Forms (parent + child line items) + +To let users enter a record **together with its child line items** (invoice + +lines, project + tasks) and save them **atomically**, you almost never need a +custom page or form config. Prefer, in order: + +1. **Relationship `inlineEdit` (default, zero UI config).** Declare it in the + DATA MODEL — set `inlineEdit` on the child's `master_detail` field that + references the parent. Every standard New/Edit form for the parent (modal, + drawer, full-page) then auto-renders the children and saves parent + children + in one atomic `/api/v1/batch`. **No view metadata needed.** A parent or child + declaring `enable.apiMethods` must list `'bulk'`, or that save is refused + `405 OBJECT_API_METHOD_NOT_ALLOWED`. The + `true` / `'grid'` / `'form'` ladder and what each value picks: + **objectstack-data → Relationships → Inline Editing**. + +2. **Form view `subforms` (override / tuning).** Add to a form view only when you + need to override the derived columns/order, or expose a child the + relationship didn't mark inline: + + ```typescript + form: { + type: 'simple', + sections: [{ group: 'invoice_header' }], // a declared fieldGroup + subforms: [ + { childObject: 'invoice_line', // set `columns` only to override + title: 'Line Items', addLabel: 'Add line' }, + ], + }, + ``` + +3. **`object-master-detail-form` page block (bespoke layout).** Use a page only + for free-form layouts. Same `details: [{ childObject }]` shorthand. + +**Line-item grid behaviors (`grid` mode).** The editable grid is a real +spreadsheet-style line editor, and +every behaviour is derived from the DATA MODEL — computed columns, catalog +typeahead auto-fill, persisted drag-reorder, and the live Subtotal → Tax → Total +stack: **objectstack-data → Relationships → Inline Editing**. Three things are +authored on this side: a trailing **ghost** row always exists, so never add an +"Add line" button to the grid (typing in the ghost materialises a row; an +untouched one is never persisted; a record-header action that inserts a priced +line is [Actions](./actions.md)); `autofill: false` opts one column out of the typeahead copy; +and the form's `taxRateField` overrides which parent field drives the totals. + +## Field Conditional Rules in Forms + +Conditions that belong to a field's lifecycle — `visibleWhen`, `readonlyWhen`, +`requiredWhen` — are declared on the **DATA MODEL field**, not in the form view; +ObjectUI forms consume them. Their semantics and server behaviour: +[objectstack-data → Conditional Field Rules](../../objectstack-data/SKILL.md#conditional-field-rules). diff --git a/skills/objectstack-ui/rules/navigation.md b/skills/objectstack-ui/rules/navigation.md index d7952a24ec7..22ecb750e17 100644 --- a/skills/objectstack-ui/rules/navigation.md +++ b/skills/objectstack-ui/rules/navigation.md @@ -1,5 +1,32 @@ # App Navigation & Run Modes +Build an App with `App.create({...})` from +`@objectstack/spec/ui` and register under `defineStack({ apps: [...] })`. + +⛔ **At most one App per package** (ADR-0019 (app-as-consumer-unit) D3 as +amended): `defineStack` refuses a second app in a `type: 'app'` and a +`type: 'module'` package alike. A suite (an app package plus its modules) may +surface more apps: each further app goes in a module of its own with the +objects it shows (gone when it is disabled), and the suite composes with +`composeStacks(stacks, { manifest: 'preserve' })`, which serves each app under +its own package id; a flat composition puts them under one and is refused. +Audiences sharing one product and its objects stay +`requiredPermissions`-gated groups **inside** one app. + +Keys by type ([the ten](../SKILL.md#navigation-item-types); `label`, `icon` +on all but `separator`): `group` `expanded`, `children[]`; `object` +`objectName`, `viewName?`, `recordId?`, `filters?`; `dashboard` +`dashboardName`; `report` `reportName?`; `page` `pageName`; `url` `url`; +`action` `actionDef` (`{actionName, params?}`); `component` `componentRef` +(a colon-joined registry key, `metadata:resource`), `params?`; `doc` `book?` / +`doc?` (one required). + +> **`requiresObject` / `requiresService`** hide an item whose optional +> system object or kernel service is missing — never hard-code conditional UI. +> `AppContextSelector` ids (e.g. `{active_package}`) resolve in navigation +> `recordId` / `params` only: filters are not evaluated with the sidebar's +> selector state. + ```typescript import { App } from '@objectstack/spec/ui'; diff --git a/skills/objectstack-ui/rules/pages.md b/skills/objectstack-ui/rules/pages.md index 92ddc1595f8..e2817e29133 100644 --- a/skills/objectstack-ui/rules/pages.md +++ b/skills/objectstack-ui/rules/pages.md @@ -59,7 +59,7 @@ A `slotted` record page has no `tabs` slot — see [Record Page](./record-page.m > `{current_quarter_start}` etc. resolve from the page's `variables` block, > the bound record, and the runtime context. Declare `variables: [...]` at > the page root for any non-record value; relative-date placeholders: -> [Date Macros](../SKILL.md#date-macros--filter-placeholders). +> objectstack-query → `rules/filters.md`. ### Print pages