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 4c32b96
Browse filesBrowse the repository at this point in the historyBrowse files
fix(console): Studio's home currency amount editor holds a partial pick instead of autosaving it (#33530)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XHsf1U8yNgEUjndccDbmTsg)_
domain:ui#2 · os-project-manager · session_01FEkQ5o9zCzQRoUJ5gP8r6H
Fixes#33102
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:Studio
字段编辑器里「本位币金额」的三个选择(本位币金额字段、单据日期、汇率字段)在只选了一两个时先留在编辑器里、不写进草稿,下方一行提示还缺哪几个;三个选齐或全部清空时才一次性写入。汇率字段的候选按屏幕上(尚未保存的)单据日期判定。
- 为什么改:spec 要求三个指针要么全有要么全无,原来每选一个就提交一次,自动保存把半成品发给服务端,连续两次 422「Changes
not saved」后第三次才成功;清空时也一样。
- 风险与回滚:只动 app-shell 的这一个编辑器和两条 i18n 文案,spec
与服务端零改动;编辑一个已完整的本位币金额到另一个完整值时照旧立即保存。回滚即还原本 PR。
- 先看:`CurrencyConfigField.tsx` 的 `pickHomePointer`(何时提交、何时留住)与
`ObjectCurrencyConfigField`(按字段 `key` 与 `homeCandidatesFor`)。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/app-shell/src/views/metadata-admin/inspectors/CurrencyConfigField.recordMode-27188.test.tsx`,预期
19 条全绿。
- 需要你做的:无,席位落地。
## What changes
`ui/packages/app-shell/src/views/metadata-admin/inspectors/CurrencyConfigField.tsx`:
- **The hold.** `CurrencyConfigField` keeps a partial `homeAmount` (one
or two of `field`, `rateDate`, `rateField` set) in its own state,
`heldHome`, and does not call `onCommit` for it. `pickHomePointer`
applies the pick with the existing `setHomeAmountPointer` to what is on
screen, then commits only when the result has all three pointers or
none. The three pickers show the held picks. The hold is stamped with
the committed `homeAmount` it was picked against, so a change to that
from elsewhere (a reload, an undo) ends it instead of being overridden
by it. A commit from elsewhere in the section (the currency field, the
mode) carries the committed `homeAmount`, never the held one.
- **The hint.** While a pick is held, one line under the pickers
(`data-testid="currency-config-home-amount-held"`, `role="status"`) says
the change is not saved yet and names the pointers still to pick, by
their picker labels. It is not the red refusal banner, and it stays
until the pick is completed or cleared: nothing auto-reverts. New key
`designer.field.currency.homeAmountHeld` in the studio namespace, `en`
and `zh` (the only two packs that namespace has).
- **Candidates judged against the held pick.** `homeAmountCandidates`
offers a rate field shared with another amount only when that amount
uses the same code field and document date, judged from the object's
committed definition. With the document date now held,
`ObjectCurrencyConfigField` passes a new optional
`homeCandidatesFor(home)` that judges the candidates against the object
with the held `homeAmount` in place; the existing pin "picking the three
pointers writes homeAmount, and the object parses" (pick `shared_rate`
after the date) caught this.
- **One field's hold stays on that field.** `ObjectCurrencyConfigField`
renders the editor with `key={self}`, so a held pick on one amount never
shows on the next field the inspector opens. Selecting another field
drops the held pick, which the hint said was not saved.
Not changed: `packages/spec` (`CurrencyConfigSchema.homeAmount` still
takes all three or none), the server, `setHomeAmountPointer`,
`homeAmountCandidates`, and every host of the editor. No client-side
fallback value is written.
## Why
- **Measured on `origin/main` `f068cde8`** (a throwaway test, not
committed, rendering `ObjectFieldInspector` on a record-mode `amount`
with a live draft, recording each `onPatch` and parsing the object with
`ObjectSchema` from `@objectstack/spec/data`, the judge behind the
server's `422 INVALID_METADATA`). The pick is committed by the
`onCommit` of each `homeAmount` picker, which called
`setHomeAmountPointer` and committed the result. Readings:
- pick Home amount field: 1 commit,
`homeAmount={"field":"amount_home"}`, refused at
`fields.amount.currencyConfig.homeAmount.rateDate` and
`...homeAmount.rateField` ("`homeAmount` needs `rateDate`", "needs
`rateField`");
- pick Document date: 1 commit, refused at `...homeAmount.rateField`;
- pick Rate field: 1 commit, parses.
- Clearing a complete one: 1 commit refused at `...homeAmount.field`, 1
commit refused at `...homeAmount.field` and `...homeAmount.rateDate`,
then 1 commit with no `homeAmount`, parses.
- **The precedent.** The hooks panel holds a CEL error back from its
autosave: the inspector reports a blocking count and `useDraftAutoSave`
is blocked while it stands. The order's ruling keeps the partial state
local and uncommitted instead, so no draft carries a half-built
`homeAmount`, nothing else in the draft is held back with it, and the
page shows no save-blocked line; the hold is the editor's own, as the
CEL editor's verdict is.
## Tests
`CurrencyConfigField.recordMode-27188.test.tsx`, new top-level
`describe` "Studio homeAmount editor holds a partial pick back from the
draft" (the file is this editor's shared harness; it drives the rendered
`ObjectFieldInspector` through its real Radix selects and spies on
`onPatch`, the commit the autosave sends):
- the first pick commits nothing, keeps the pick on screen, and names
the two pointers still to pick;
- the second pick commits nothing; the third commits once, with all
three, and the object parses;
- clearing a complete `homeAmount` holds until the last pointer is
cleared, then commits once with none;
- a commit from elsewhere in the section keeps the held picks and the
hint, and sends no partial `homeAmount`;
- CONTROL: a complete `homeAmount` edited to another complete one
commits once (green on base too);
- the fixture parses bare and with a complete `homeAmount`.
<details><summary>Red on base, green on the fix, ablation red</summary>
- Base `f068cde8` (pins only): `Tests 4 failed | 15 passed (19)`, the
four hold pins red, CONTROL and fixture green.
- Fix: `CurrencyConfigField.recordMode-27188.test.tsx` +
`CurrencyConfigField.parentPath-31912.test.tsx`: `Test Files 2 passed
(2)`, `Tests 25 passed (25)`.
- Ablation (`scripts/ablation-replace.mjs`, anchor `setHeldHome({
against: committedHome, home: next.homeAmount! });` replaced by
`onCommit(next);`, anchor 1 → 0, replacement 0 → 1, blob `63492afeba7e`
→ `79389c3d2790`; the test imports the editor from `src/`, no dist in
the path): `Tests 4 failed | 15 passed (19)`, the first pin among them;
restored, blob equals HEAD, `git diff HEAD` empty.
</details>
## Acceptance notes
- None.
## Verification
All readings on head `8e67a26c` unless named.
- Tests: `pnpm --dir ui exec vitest run
packages/app-shell/src/views/metadata-admin/inspectors/CurrencyConfigField.recordMode-27188.test.tsx
packages/app-shell/src/views/metadata-admin/inspectors/CurrencyConfigField.parentPath-31912.test.tsx`:
exit 0, `Tests 25 passed (25)`. Every `ObjectFieldInspector*` test
(`--maxWorkers=2
packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector`):
exit 0, `Test Files 31 passed (31)`, `Tests 344 passed (344)`.
`packages/i18n/` with the two currency files: exit 0, `Test Files 104
passed (104)`, `Tests 1919 passed | 13 skipped`.
- Type-check (`tsc --noEmit` and `tsc -p tsconfig.test.json`, so the
tests compile too): `pnpm --filter @object-ui/app-shell run type-check`
exit 0; `pnpm --filter @object-ui/i18n run type-check` exit 0 (after
`pnpm --filter '@object-ui/app-shell^...' build`).
- `pnpm exec eslint` on the four changed source files (from `ui/`): exit
0, 0 errors; the `react-refresh/only-export-components` warnings are the
file's existing exports, none added (the new helper is module-private).
- Derived gates (`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`, 36 families) run in full on `8e67a26c`: 36
exit 0, among them `pnpm --dir ui exec vitest run scripts/`, `node
scripts/check-sdui-manifest.mjs`, `node
scripts/check-empty-changeset.mjs --base origin/main`, `pnpm
check:test-source-alias`, `pnpm check:type-check-debt`, `pnpm
check:nul-bytes`. `--ran`: "36 derived famil(ies) accounted for — 36
run, 0 NOT-MEASURED".
- `dispatch-gates --tier`: no path-derived mandate; 175 changed lines,
under the 3000 threshold; no governed surface.
- Changeset `.changeset/33102-home-amount-autosave-hold.md`:
`@object-ui/console` (its dist ships the private `@object-ui/app-shell`)
and `@object-ui/i18n` (its `dist` ships the new string), both `patch`;
`Clause-②: no`, `Metadata-protocol: none`, measured on the diff: no
spec, server or authorable key changed, and the only new prop
(`homeCandidatesFor`) is on a private package's component.
- CI families are read from this PR's check-runs, not re-run here.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5o9zCzQRoUJ5gP8r6H
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(console): Studio's home currency amount editor holds a partial pick instead of autosaving it
7
+
8
+
Clause-②: no
9
+
Metadata-protocol: none
10
+
11
+
A record-mode currency field's home currency amount (`currencyConfig.homeAmount`) names three fields together or none: the home amount field, the document date and the rate field. The Studio field editor committed each pick on its own, so the autosave sent the field with one, then two, of the three, the server refused both (`422 INVALID_METADATA`) and "Changes not saved" showed twice before the third pick saved. Clearing the three showed the same twice. A pick that leaves one or two of the three set now stays in the editor and is not saved, with one line under the pickers naming the fields still to pick; the field saves once, when all three are set or all three are cleared. Editing a complete home amount to another complete one saves at once, as before. The rate field picker is judged against the document date on screen, picked or not yet saved. Nothing the server accepts changed.
'designer.field.currency.rateFieldNone': '— Pick a number field —',
529
529
'designer.field.currency.homeAmountHint': "When a record is saved, the server converts this amount into the organization's home currency at the exchange rate in force on the document date, and stores the result and the rate it used. Lists the read-only fields that can hold them: a dynamic-mode currency field for the amount, a number field for the rate.",
530
+
'designer.field.currency.homeAmountHeld': 'Not saved yet: a home currency amount needs all three fields, or none. Still to pick: {missing}.',
0 commit comments