You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7f60e9d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(core): refuse a single-record action's row count before its dialog, and translate the refusal (objectui#13384) (#13395)
Closes#13384
Clause-②: yes (widening: ActionRunnerHandler / ServerActionHandler gain
optional refuseBeforeInput; ServerActionRecordIdResolution gains
optional errorKey; nothing is refused)
## What changed
A single-record action launched from a list toolbar with 0 or 2+ rows
selected is now refused before any confirmation or param dialog opens.
It gets the same toast as before and sends nothing. With exactly one row
the dialog behaves as before. The refusal is also translated now: it
read English under zh-CN.
- **`@object-ui/core` `ActionRunner`**: `ActionRunnerHandler` gains an
optional `refuseBeforeInput(action, context)`. `execute` asks the
handler it will dispatch to, after the `condition` / `disabled` gates
and before `confirmText` and the param collection. A refusal goes
through the usual post-execution (error toast, `onFailure`), and nothing
is dispatched. If the refusal names an `errorKey`, the runner translates
it through `setTranslator`'s translator, with the English as default.
This is the same channel the runner's own `RUNNER_TEXT` uses, so core
still takes no i18n dependency.
- **`@object-ui/core` `serverActionHandler`**:
- The two refusal strings come from a keyed table
(`actions.selectExactlyOneRow`, `actions.selectRowFirst`).
- `resolveServerActionRecordId` returns the key as `errorKey` beside the
English `error`.
- `createServerActionHandler` attaches `refuseBeforeInput`, which runs
the same resolver the dispatch runs, including an injected
`resolveRecordId`. So a record page, which resolves against its own
record, is never refused.
- It skips the early check when the dialog itself collects a param named
`recordId`.
- The check at dispatch time stays for callers that invoke the handler
directly.
- **`@object-ui/app-shell` `createConsoleServerActionHandler`**:
forwards `refuseBeforeInput` from core's handler, which it builds with
the wrapper's own `resolveRecordId`. Without the forward the runner
never saw the member and the console kept its dialog-first order.
- **`@object-ui/i18n`**: both keys are added to all ten packs. No German
low-high quote span is added, so the `de-quote-pairing-3876` counts are
unchanged.
- One changeset: core, i18n and app-shell, patch.
Why the runner asks the handler instead of holding the row rule itself:
on a record page, a related-list grid publishes `selectedRecords: []`
into the page's runner context. A runner-side copy of the rule would
refuse every `record_header` action there. Only the handler knows its
own resolver.
## Tests
Run on head `024092b03`:
- `pnpm exec vitest run --maxWorkers=2` over
`packages/core/src/actions/__tests__/`, `packages/i18n/`, and the 21
app-shell test files that read `consoleServerAction`,
`resolveServerActionRecordId` or `toolbarScriptSelection`: **146/146
files, 2113 passed, 13 skipped**.
- New `ActionRunner.recordRowGuard-13384` (core):
- 0 rows and 2 rows: the toast shows, no param dialog and no
confirmation open, and nothing is sent.
- 1 row: the dialog opens and the one request carries that row.
- Controls: an object-level toolbar action with 0 rows still opens its
dialog; an injected record resolver is not refused; a dialog that
collects `recordId` is not judged early.
- The translator is asked by key, with the English default; an empty
answer falls back to English.
- `serverActionHandler.test.ts`: pins for `errorKey` and
`refuseBeforeInput`.
- `consoleServerAction.test.tsx`: pins the forward, both alone and
through a real `ActionRunner`. 0 and 2 rows open no dialog, pre-open no
tab and send nothing. 1 row opens the dialog.
- `ObjectView.toolbarScriptSelection-12331`: its five 0- and 2-row cases
now also assert that no dialog opened, beside the toast and the absent
request. Every other claim in that suite is unchanged.
- New `recordSelectionRefusal-13384` (i18n): pins the zh-CN text; every
other pack defines both keys with its own text.
- Type-check, `NODE_OPTIONS=--max-old-space-size=8192 pnpm exec turbo
run type-check --concurrency=2`:
- `--filter=@object-ui/core`: 3/3 tasks
- `--filter=@object-ui/app-shell`: 30/30 tasks, including `tsc -p
tsconfig.test.json`
- `pnpm check:i18n-keys`, `check:i18n-drift`, `check:i18n-dead-keys`:
exit 0. Dead-keys is report-only. It lists the two new keys as
needs-review, the same class as their `actions.*` siblings, which are
also reached only through a key table.
- eslint on the touched files: 0 errors. The warnings are pre-existing
`no-explicit-any`; none is added.
- `check:new-line-citations`: 0 new. `check-changeset-presence`: pass.
### Ablation
Each run used `ablation-replace` with on-disk proof, and was restored to
`git diff HEAD` empty:
| Mutation | Result |
|---|---|
| The runner's early refusal disabled | 5 core cases red (0 rows, 2
rows, confirmation, two translator cases) |
| `errorKey` dropped from the refusal | 4 red |
| The console wrapper's forward deleted | 8 red: 3 in
`consoleServerAction.test.tsx`, plus all five 0- and 2-row cases of
`ObjectView.toolbarScriptSelection-12331` |
## Acceptance notes
- **Out of scope, still open:** the console `flowHandler` in
`useConsoleActionRuntime.tsx` calls `resolveServerActionRecordId`
directly and is not a forwarded handler. A `type: 'flow'` action with
params, launched from a list toolbar with 0 or 2+ rows, still opens its
dialog first, and its refusal still reads English. It could read the new
`errorKey`. That file belongs to objectui#13379's claim, so it was not
touched here.
- **Out of scope, still open:** the console wrapper's own `newTabUrl`
fast-path refusal ("This action runs on a single record — no record id
available.") is still a hard-coded English string with no pack key.
- [x] Adds no product-specific widget, dialog, hook or string (see
AGENTS.md › Product-neutral renderer)
Session: `https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj
---------
Co-authored-by: Claude <noreply@anthropic.com>
A single-record action launched with 0 or several rows selected is refused before any dialog opens, and the refusal is translated (objectui#13384).
8
+
9
+
`ActionRunner` now asks the handler it will dispatch to for an early refusal (`ActionRunnerHandler`'s optional `refuseBeforeInput`) before the confirmation and the param dialog. The handlers `createServerActionHandler` builds answer it with the row-count check the dispatch already runs, so "select a row first" and "select exactly one row" are shown before the user fills anything in, and nothing is sent. With exactly one row the dialog behaves as before. A host that wraps the built handler in its own function keeps the early refusal only by forwarding `refuseBeforeInput`; the console's `createConsoleServerActionHandler` now forwards it, so on a list page (HotCRM's "Add to Campaign" on My Leads) the refusal toast shows and no dialog opens.
10
+
11
+
Both refusals now carry a pack key (`actions.selectRowFirst`, `actions.selectExactlyOneRow`, defined in every shipped pack). `resolveServerActionRecordId` returns it as `errorKey` beside the English `error`, and the runner's early refusal goes through its translator by that key.
0 commit comments