Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .changeset/39182-action-notices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'@objectstack/spec': minor
'@objectstack/lint': minor
'@objectstack/metadata-core': minor
'@object-ui/core': patch
---

feat(spec): `notices` on an action, warnings its dialog draws before submit, in `record:alert`'s vocabulary

Clause-②: yes (widening)
Metadata-protocol: added

An action that opens a dialog before it runs (a param dialog, or the confirm dialog of `confirmText`) can now declare `notices`: a map from a snake_case notice name to a notice the dialog draws above its description, each while its condition holds.

```yaml
notices:
mail_not_delivered:
severity: warning
title: No email will be sent
body: This deployment does not deliver mail.
visible: features.emailDelivery != true
```

- **`record:alert`'s vocabulary.** A notice takes the record page banner's names: `severity`, `title`, `body`, and `visible` for its condition. `severity` is the banner's own closed set (`info`, `warning`, `error`, `success`), one schema mounted by both: `RecordAlertProps.severity` now mounts it too, with the same values. The banner's `icon`, `action`, `dismissible` and `dismissKey` are refused on a notice, each with a sentence saying why; `label` renames to `title`, as it does in a translation bundle.
- **Plain text.** `title` and `body` are `I18nLabel`s: a non-blank string or an inline locale map, with no markup, link, button or template. A notice declares at least one of them. An unknown severity, a non-string label, a blank one, or a notice with neither is refused at parse.
- **Named, so each notice has a stable translation key.** The text is translated at `objects.<object>._actions.<action>.notices.<notice>.title` / `.body` (`globalActions.<action>.notices.<notice>.*` for an action with no object). `translateAction` overlays it leaf by leaf, only for the leaves a declared notice authors. `os validate` reports a translated notice the action does not declare, or a translated leaf the notice does not author (`translation-target-unknown`), and the translation extractor lists each declared leaf.
- **The action's own condition.** `visible` takes the shape of the action's `visible` and reads the same scope (the record the surface holds, the signed-in user, `features`), with no new root. `os validate` checks it as it checks the action's `visible`. Omitted, the notice is drawn whenever the dialog opens.
- **Only on a dialog host.** `notices` on an action with neither `confirmText` nor a non-empty `params` is refused at parse: no dialog opens to draw it.
- **Display only.** Nothing gates on a notice. The action's endpoint, its outcome and its outcome copy are unchanged by it. The served object schema's field mask reads only a notice's `visible`: a notice whose `title` or `body` mentions a field the caller cannot read does not remove the action from what that caller is served, and a notice whose `visible` reads such a field removes the action, as any other condition on it does.
- `alerts` and `warnings` on an action are refused with a rename to `notices`.

The key is `planned` in the liveness ledger: it parses, translates and is checked, and the console's dialogs do not draw it yet. `@object-ui/core` lists `notices` among the spec's action keys, so the console stops treating it as an unknown key.
31 changes: 31 additions & 0 deletions content/docs/protocol/objectui/actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ interface Action {
params?: ActionParam[]; // Inputs collected before execution
submitText?: I18nLabel; // The param dialog's submit button verb (default "Confirm")
cancelText?: I18nLabel; // The confirm or param dialog's dismiss button label (default "Cancel")
notices?: Record<string, ActionNotice>; // Notices the confirm or param dialog draws above its description, each while its condition holds
preflight?: Preflight; // A same-origin GET the param dialog sends and shows above the params before submit
method?: 'POST' | 'PATCH' | 'PUT' | 'DELETE'; // for type: 'api'

Expand Down Expand Up @@ -565,6 +566,36 @@ cancelText: Keep invitation
- `cancelLabel` (the button's spelling on the console's `form` and `alert-dialog` renderers) is refused with a rename to `cancelText`.
- The console draws it on the dismiss button of both dialogs, from the translation bundle first and then the authored text. Without it, the button says **Cancel**. `sys_invitation`'s **Cancel Invitation** action declares **Keep invitation**.

### Warning before submit: `notices`

> **Planned.** The key parses, translates and is checked at build time, but the console's dialogs do not draw it yet. An author who writes it today sees no notice in the dialog.

Some actions need to tell the user something before they click, and only when a condition holds: no mail is delivered on this deployment, so the invitation will not reach anyone by email; this quote is past its expiry. `description` says the same thing every time. `notices` says it when it applies.

```yaml
name: invite_user
label: Invite User
objectName: sys_member
type: api
target: /api/v1/auth/organization/invite-member
params:
- { name: email, type: email, required: true }
notices:
mail_not_delivered:
severity: warning
title: No email will be sent
body: This deployment does not deliver mail. Only an invitee who signs in with a social or SSO account that verifies the address can accept.
visible: features.emailDelivery != true
```

- **`record:alert`'s vocabulary.** Each notice takes the record page banner's field names: `severity` (`info`, `warning`, `error` or `success`, the same closed set; omitted, the console draws `info`), `title`, `body`, and `visible` for its condition. The banner's `icon`, `action`, `dismissible` and `dismissKey` are not declared here, and each is refused with a sentence that says why.
- **Plain text.** `title` and `body` are `I18nLabel`s: a plain string or an inline locale map, never blank, with no markup, link, button or `${…}` template. A notice declares at least one of the two.
- **Named, so each has a stable translation key.** The map key is a snake_case notice name, and the text is translated at `objects.<object>._actions.<action>.notices.<notice>.title` and `.body` (`globalActions.<action>.notices.<notice>.*` for an action with no `objectName`). A translation keyed to a notice the action does not declare is reported by `os validate` (`translation-target-unknown`). Several notices are drawn in the order they are declared.
- **The condition is the action's own.** `visible` takes the shape of the action's `visible` (a boolean, a CEL string or a `{ dialect, source }` envelope) and reads the same scope: the record the surface holds, the signed-in user and `features`. It does not see the values typed into the dialog. Omit it to draw the notice whenever the dialog opens. `os validate` checks it as it checks the action's `visible`.
- **Either pre-run dialog.** The confirm dialog of a param-less action with `confirmText` and the param dialog of an action with a non-empty `params` draw the notices above the description. An action that declares neither opens no dialog, so `notices` there is refused at parse.
- **Display only.** The action's endpoint, its `outcome` answer and its outcome copy are the same with or without a notice. A notice that is wrong or not drawn misleads the reader and gates nothing.
- `alerts` and `warnings` are refused with a rename to `notices`.

### Showing a server read before submit: `preflight`

> **Live.** The console's param dialog sends the read once every `${param.NAME}` hole in `read.url` has a value, draws the answer at `path` above the params (each `fields` row as the result dialog draws it), and applies each `seed` only from the answer to the current URL. A seeded param is drawn read-only and submitted as shown. A refused, unbound or failed read leaves the seeds empty.
Expand Down
1 change: 1 addition & 0 deletions content/docs/references/data/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ const result = ApiMethod.parse(data);
| **params** | `{ name?: string; field?: string; objectOverride?: string; label?: string \| Record<string, string>; … }[]` | optional | Input parameters required from user — an ActionParam[] DEFINITION array, never a payload map (a static request body goes in `bodyExtra`). A param name (its `name`, or the `field` a field-backed param reads) may repeat only for per-gate variants of ONE input (declarations that differ in `visible` / `requiresFeature`, e.g. one optional and one required); the params check treats the name as `required` only when EVERY declaration of it requires it, and judges its value by the FIRST declaration's shape (`type`, `multiple`, `options`), so keep that shape identical across them. |
| **submitText** | `string \| Record<string, string>` | optional | Label of the submit button in the action's param dialog, the verb the button performs (e.g. "Send", "Log Call"), in place of the default "Confirm" — the default-language string, or an inline locale map; translated at `objects.OBJECT._actions.ACTION.submitText` (`globalActions.ACTION.submitText` for an object-less action). Only on an action with a non-empty `params`: without one no param dialog opens, so it is refused. Not `confirmText`, which is the message of a param-less action's confirm dialog. A blank label is refused. |
| **cancelText** | `string \| Record<string, string>` | optional | Label of the dismiss button on the dialog the action opens before it runs — the confirm dialog of a param-less action that declares `confirmText`, or the param dialog of an action with a non-empty `params` — in place of the default "Cancel". Name what dismissing keeps where the action's own verb is "Cancel …" or "Close …" (e.g. "Keep invitation" beside "Cancel Invitation"). The default-language string, or an inline locale map; translated at `objects.OBJECT._actions.ACTION.cancelText` (`globalActions.ACTION.cancelText` for an object-less action). Only on an action that opens one of those dialogs: with neither `confirmText` nor a non-empty `params` no dialog opens, so it is refused. The dismiss twin of `submitText`, as on `object-form`. A blank label is refused. |
| **notices** | `Record<string, { severity?: Enum<'info' \| 'warning' \| 'error' \| 'success'>; title?: string \| Record<string, string>; body?: string \| Record<string, string>; visible?: boolean \| string \| object }>` | optional | Notices the dialog the action opens before it runs (the confirm dialog of a param-less action that declares `confirmText`, or the param dialog of an action with a non-empty `params`) draws above its description, each while its condition holds — keyed by a snake_case notice name, drawn in declared order. Each notice takes `record:alert`'s vocabulary: `severity` (info / warning / error / success), `title` and `body` (plain text, a string or an inline locale map, at least one of the two; translated at `objects.OBJECT._actions.ACTION.notices.NAME.title` / `.body`, `globalActions.ACTION.notices.NAME.*` for an object-less action), and `visible`, a condition in the shape and scope of the action's own `visible`, without the dialog's typed values. Display only: the action runs and answers the same with or without a notice. Only on an action that opens one of those dialogs, else refused. |
| **variant** | `Enum<'primary' \| 'secondary' \| 'danger' \| 'ghost' \| 'link'>` | optional | Button visual variant for styling (primary = highlighted, danger = destructive, ghost = transparent) |
| **order** | `number` | optional | Sort order within a location group (lower = higher). Promotes/demotes an action toward the record page header's primary button; stable, so actions without `order` keep their registration order. |
| **confirmText** | `string \| { dialect: 'template'; source?: string; ast?: any; meta?: object } \| string \| Record<string, string>` | optional | Confirmation message before execution — a `template` slot (ADR-0032): a bare string is shorthand for `{ dialect: 'template', source }`, and text with no hole is shown as written. Holes are `{{ path }}` or `{{ path \| formatter[:arg] }}` over `record`, the record the action runs against (the clicked row on a list, else the page's record), and — only when the action's `params` is an object of static values — `params` (`{{ params.tier }}`); an input list binds nothing, since its values are collected after the confirmation. Formatters come from the template engine's whitelist (`TEMPLATE_FORMATTERS`, `@objectstack/formula`); a hole holds no logic (no CEL, no arithmetic). Example: 'Delete `{{ record.name }}`?'. A hole over any other root, a `${…}` or single-brace `{x}` token (each named with its `{{ }}` spelling), a hole holding logic or an unknown formatter, and a blank sentence are named and refused at `objectstack validate`, `compile` and the publish gate; the text still parses, so a stored one loads until its next save. An inline locale map (`{ en, "zh-CN" }`) is accepted too, each value such a sentence. Pairing this with a non-empty `params` is refused — that opens a second dialog for one decision; put the question on `description` instead. Correct on a param-LESS action, where the confirm is the only dialog there is. |
Expand Down
Loading
Loading