Repository navigation
Commit 82838e8
fix(fields): a read-only record-mode amount with homeAmount shows the live home-amount preview in an editable form (#33296)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XGdQDG3Qbiw4wgeGVbMvF55)_
Fixes #32941
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:编辑表单里,一个声明了 `homeAmount` 的记录币种金额即使被画成只读(例如由 `expression`
计算的发票总额),金额下面也会显示「≈ 本位币金额 at 汇率 on
日期」的实时预览,改币种或单据日期时跟着变。只读表单(查看模式)和记录详情页不显示这一行。
- 为什么改:showcase 发票的 `amount`
是表达式计算字段,表单把它画成只读,而只读分支在挂载预览之前就返回了,所以编辑发票时完全看不到保存后会存多少本位币金额。测试清单
`records-forms.home-amount-preview-states` 和
`records-forms.multi-currency-invoice` acceptance[5] 都要求这一行。
- 风险与回滚:只改 `@object-ui/fields` 里 `CurrencyField` 只读分支的一个条件分支,复用已有的
`HomeAmountPreview` 和已有的 `fields.currencyHome.*` 文案;不改
spec、不改服务端、不加属性和文案。回滚即 revert。
- 先看:`ui/packages/fields/src/widgets/CurrencyField.tsx` 只读分支里新增的 `if
(!props.disabled && … homeAmount)`
块;`ui/packages/plugin-form/src/__tests__/sectionFormHomeAmount-27196.test.tsx`
末尾新增的 `objectstack#32941` describe。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/fields/src/__tests__/homeAmountPreview-27196.test.tsx
packages/plugin-form/src/__tests__/sectionFormHomeAmount-27196.test.tsx
packages/plugin-detail/src/__tests__/DetailSection.homeAmount-27196.test.tsx`,预期
3 个文件 21 个用例全绿。
- 需要你做的:无,席位落地。
## What changes
- **`CurrencyField`'s read-only face**
(`ui/packages/fields/src/widgets/CurrencyField.tsx`,
`@object-ui/fields`). The read-only branch used to return the formatted
amount and nothing else, so `HomeAmountPreview` was mounted on the
editable face only. It now mounts the same `HomeAmountPreview` under the
amount when the field is a `record`-mode amount declaring `homeAmount`
(ADR-0144 D5) and the widget is not `disabled`. The amount span is
unchanged; for such a field it sits in a `div.space-y-1` beside the
preview line, the editable face's own wrapper. Every other read-only
currency (no `homeAmount`, or not `record` mode) returns the same single
span as before.
- **How the read-only face tells an editable form from a read-only view
(measured, as the order asked):**
- The edit form reaches this branch for a computed amount through
`readonly: true` (`ObjectForm`'s `isExpressionComputedField` stamp and
`sectionFields.ts`'s, unchanged), with `disabled` false except while a
submit is in flight. The form renderer (`renderFieldComponent` in
`ui/packages/components/src/renderers/form/form.tsx`) hands the currency
widget the live form record as `dependentValues`
(`RECORD_CURRENCY_WIDGET_TYPES`), which is what the preview reads the
currency and document date from, so a change in the form re-renders the
line.
- A read-only form (`mode: 'view'` or `readOnly`) stamps `disabled:
true` on every field (`generateField` in `ObjectForm.tsx` and
`fromObjectSchema` in `sectionFields.ts`), so `!disabled` keeps the
preview off it. Its home field already shows "Converted at RATE on
DATE".
- The record detail page never mounts `CurrencyField`: `DetailSection`
and the highlights strip draw `currency` through `getCellRenderer`,
which is `CurrencyCellRenderer`, unchanged. So the detail page keeps
exactly one line, the home field's hint.
- **Changeset** `.changeset/32941-readonly-amount-home-preview.md`:
`@object-ui/fields` patch, both declaration lines.
## Tests
- `ui/packages/fields/src/__tests__/homeAmountPreview-27196.test.tsx`,
new describe for objectstack#32941:
- a `readonly` record-mode amount (EUR 450, 2026-11-12, home CNY) draws
no input and the line "≈ CN¥500.00 at 0.9 on Nov 12, 2026" with
`data-state="converted"`; re-rendered with JPY and 2026-01-15 it reads
"≈ CN¥2.97 at 151.5 on Jan 15, 2026"; with the date cleared it reads the
awaiting-date line with `data-state="awaitingDate"`.
- CONTROL: a `readonly` and `disabled` face, and a `readonly`
record-mode amount with no `homeAmount`, draw the amount alone and read
no rate.
-
`ui/packages/plugin-form/src/__tests__/sectionFormHomeAmount-27196.test.tsx`,
new describe, through a rendered `ObjectForm` whose `amount` carries an
`expression` (the showcase invoice's shape):
- edit mode: the amount row has no input and its preview reads "≈
$500.00 at 0.9 on Nov 12, 2026", `data-state="converted"`. Typing
01/15/2026 into the form's own date box and leaving it moves the line to
"≈ $489.13 at 0.92 on Jan 15, 2026"; picking JPY in the form's own
currency select moves it to "≈ $2.97 at 151.5 on Jan 15, 2026".
- CONTROL: the same object in view mode draws the amount (`€450.00`)
with no preview, and the home field keeps "Converted at 0.9 on Nov 12,
2026".
-
`ui/packages/plugin-detail/src/__tests__/DetailSection.homeAmount-27196.test.tsx`,
new describe: CONTROL, the record page with the expression-computed
amount shows one "Converted at" line (on the home row) and no preview.
- Ablations through `scripts/ablation-replace.mjs`, each restored to the
HEAD blob with `git diff HEAD` empty. `@object-ui/fields` resolves to
`packages/fields/src` through `ui/vitest.config.mts`'s alias, so no
build sat between mutation and run.
- The new branch's condition replaced with `false as boolean` (anchor 1
to 0, blob `9f82c708` to `3aea6a75`): 2 failed, 16 passed (18). Red: the
widget's read-face preview case and the edit-form case. Every CONTROL
green.
- The `!props.disabled &&` gate dropped (blob `9f82c708` to `5d03c47f`):
2 failed, 16 passed (18). Red: the widget's disabled CONTROL and the
view-mode form CONTROL.
## Acceptance notes
- **The preview leaves the read-only face while a save is in flight.**
The form renderer sets `disabled` on every field during `isSubmitting`,
and the widget cannot tell that window from a read-only form, so the
line under a read-only amount disappears for that moment and returns if
the save fails. The editable face keeps its line during submit. No new
prop was added to tell the two apart: a host-produced form-context key
would be a widget-contract change for a transient.
- **Pre-existing, unchanged:** the editable face already mounts the
preview under a `disabled` input, so on a view-mode form a record-mode
amount that is not computed still shows the line. This PR does not touch
the editable face (the order keeps it unchanged); named here, not filed.
- **Live console check not run.** The reproduction on the showcase
invoice INV-1004 was not driven in a browser; the rendered `ObjectForm`
test above drives the same field shape through the real form renderer,
date box and currency select.
- **Declaration lines measured on the diff:** no prop, export, schema
key or translation key is added or removed; the preview's
`fields.currencyHome.*` strings already exist. `Clause-②: no`,
`Metadata-protocol: none`, as the claim opened.
## Verification
Run on head `fc89ce51` (base `origin/main` `d4fbb4db`). `origin/main`
moved to `9f736f2e` before this PR opened; its 42 files touch nothing
under `ui/` (spec, lint, mcp, runtime, services, docs), so the branch
was not merged and CI's merge ref carries the combination.
<details><summary>Build, tests and lint</summary>
- Build under the verify lock: `pnpm --workspace-concurrency=2 --filter
'@objectstack/spec...' --filter '@objectstack/formula...' --filter
'@objectstack/client...' --filter '@objectstack/lint...' --filter
'@objectstack/sdui-parser...' build`: VERDICT command-exit 0.
- `pnpm --dir ui exec vitest run --maxWorkers=2 packages/fields/` plus
the four related files (`CurrencyConfigField.recordMode-27188`,
`DetailSection.homeAmount-27196`, `sectionFormHomeAmount-27196`,
`objectFormExpressionComputed-31759`) under the lock: VERDICT
command-exit 0, Test Files 309 passed, 1 skipped (310), Tests 4645
passed, 7 skipped (4652).
- eslint on the four changed source and test files: exit 0 (0 errors).
`pnpm --dir ui run check:new-line-citations`: 0 new citations, exit 0.
- `@object-ui/fields` `type-check` (`tsc --noEmit && tsc -p
tsconfig.test.json`) after `pnpm --filter '@object-ui/fields^...'
build`, under the lock: VERDICT command-exit 0.
</details>
<details><summary>Derived gates (36)</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 36 families on this diff. On head
`fc89ce51` all 36 exited 0, among them `pnpm --dir ui exec vitest run
scripts/`, `pnpm check:test-source-alias` and `pnpm
check:type-check-debt`. `--ran` reconciliation with exit codes recorded:
36 derived, 36 run, 0 NOT-MEASURED (a derived zero), 0 UNRUN. Changed
lines: 154 (+152 / -2, 5 files), under the 3,000 threshold.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5mWLGqDtxv15E7gTTF
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5mWLGqDtxv15E7gTTF)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 4c9104e commit 82838e8
5 files changed
Lines changed: 152 additions & 2 deletions
File tree
- .changeset
- ui/packages
- fields/src
- __tests__
- widgets
- plugin-detail/src/__tests__
- plugin-form/src/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
85 | 101 | | |
86 | 102 | | |
87 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
0 commit comments