Repository navigation
Commit 0241df4
fix(plugin-form): a line-items column over a formula takes the type its returnType declares (#34319)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Nf3gqWSittou77go2LaJkT)_
Fixes #34286
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:明细(record:line_items / 主从表)里只写字段名的列,如果那个字段是公式(或汇总),列类型改按公式声明的
`returnType` 推导;货币公式现在打印 `$157,780.00` / `157,780` 这样的金额,而不是裸数字
`157780`。
- 为什么改:报价单、发票打印的明细里,货币公式列显示成未格式化的数字,而同一个值在记录详情页和普通货币列里是格式化的,客户看到的单据不一致。
- 风险与回滚:只改一个纯函数(列类型推导);没有 `returnType` 的公式、手写了 `type`
的列、普通货币字段都和以前一样。回滚就是撤销这一个 PR。
- 先看:`ui/packages/plugin-form/src/deriveMasterDetail.ts` 的
`columnValueType`(新)和它在 `hydrateColumns` 里的那一处调用。
- 两分钟验证:在 `ui/` 下跑 `pnpm exec vitest run
packages/plugin-form/src/LineItemsPanel.childFieldHydration-12854.test.tsx`,预期
9 个用例全绿,其中 `#34286` 一组 4 个。
- 需要你做的:无,席位落地。
## What changes
`hydrateColumns` (and the internal `deriveColumn`, for symmetry) in
`ui/packages/plugin-form/src/deriveMasterDetail.ts` now map a child
field through a new private `columnValueType(d)` before
`fieldTypeToColumnType`:
- a `summary` that declares its currency (`summaryDeclaresCurrency`,
already exported by `@object-ui/fields`, the formula cell's own test) →
`currency`;
- otherwise a `formula` / `summary` field's declared `returnType`, as
declared;
- with neither, the field's own `type`, so the column hydrates exactly
as before (`text`);
- every other field type is unchanged.
This is the formula cell's reading (`FormulaCellRenderer` in
`ui/packages/fields/src/index.tsx`), applied to the declaration alone: a
column is typed before any value exists, so the cell's last arm (a JS
number drawn as a number) has no counterpart, and nothing is inferred
from the expression. No second return-type table: the declared value
type is a field type, and the existing `fieldTypeToColumnType` maps it.
Mappings: `currency` → `currency`; `number` → `number` (the formula's
`scale` still carried by the computed branch); `date` → `date`;
`boolean` → `select` with the two session-language option labels a
boolean field gets (`optionsFor` now reads the value type); `text` →
`text`. The spec `returnType` enum has no `percent`, so none is added.
Unchanged: a column with an authored `type` is returned as written; the
column stays computed and read-only (`isExpressionComputedField`); a
hydrated `currency` column with an authored `scale` is still reported by
`reportCurrencyColumnScale`; the column's currency is resolved where
every currency column's is (`GridField` `columnCurrencies`, filled from
the child field's own `currencyConfig` by `parentCurrencyFieldsOf`,
which reads any field type).
## Tests
- `LineItemsPanel.childFieldHydration-12854.test.tsx`, new top-level
`describe` in the existing harness: a name-only column over a
`returnType: 'currency'` formula prints `$157,780.00` (USD tenant);
`returnType: 'number'` prints `157,780`; CONTROL no `returnType` prints
`157780` as before; CONTROL an authored `type: 'number'` wins.
- `deriveMasterDetail.test.ts`, new top-level `describe`: currency /
number (+ scale) / date / boolean (select + labels) / text mappings; a
summary declaring a currency → `currency`; CONTROL a formula with no
`returnType` and a summary with no currency stay `text`; CONTROL
authored type wins and a plain currency field stays `currency`.
## Acceptance notes
- `deriveColumns` never reaches a `formula` / `summary` field: the
spec's `deriveInlineGridColumns` skips both as non-editable
(`INLINE_GRID_NON_EDITABLE_TYPES`), so only the hydration path
(`record:line_items` and the master-detail block's explicit `columns`,
both through `hydrateColumns`) is live. `deriveColumn` takes the same
rule so the two cannot drift.
- A `number` column's read-only text is `toLocaleString` with no minimum
fraction digits (`GridField` `cellDisplayText`), so a declared `scale`
rounds the stored computed value but does not pad the display.
Pre-existing for every number column; not changed here.
- A hydrated `summary` column is not `computed` (a summary has no
`expression`), so in an editable panel it renders an input, as it did as
`text` before. Pre-existing.
- The card's print door (`POST /api/v1/print/records`) renders the
console page, whose `record:line_items` is `LineItemsPanel` →
`hydrateColumns`; the panel pin reproduces the card's `157780` on main
(ablation below). The print door itself was not driven end to end: NOT
MEASURED.
## Verification
All at head `c922a5f0` (branch merged with `origin/main` f9120b8; main
moved no file this diff reads).
- Symptom on main, measured: ablation A below is main's rule for a
formula (its `type` mapped as is); the panel cell read `157780` where
the pin expects `$157,780.00`, the card's text.
- `pnpm exec vitest run
packages/plugin-form/src/deriveMasterDetail.test.ts
packages/plugin-form/src/LineItemsPanel.childFieldHydration-12854.test.tsx`
(from `ui/`): `Test Files 2 passed (2)`, `Tests 61 passed (61)`.
- Whole package, `pnpm exec vitest run packages/plugin-form/` under the
verify lock: `VERDICT command-exit 0`, `Test Files 232 passed (232)`,
`Tests 2582 passed | 1 skipped (2583)` (run on `0fbbd921`, before the
main merge; the merge touched no
`ui/packages/{plugin-form,fields,core,i18n}` file).
- `pnpm --filter @object-ui/plugin-form type-check`: `VERDICT
command-exit 0`.
- `eslint` on the three touched source/test files: 0 errors (21
pre-existing `no-explicit-any` warnings).
- Derived gates: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` → 38 families, each run, all `exit 0`;
`--ran` reconciliation: `38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN`.
<details><summary>Ablations (node scripts/ablation-replace.mjs, mutation
proven on disk, restored to the HEAD blob)</summary>
- A: `return typeof d?.returnType === 'string' ? d.returnType : type;` →
`return type;` (blob 06c9c5a → 6024bd16): 4 red, the currency and
number pins in both files (`Expected $157,780.00, Received 157780`;
`Expected /^157,780$/, Received 157780`). Restored: blob == HEAD, `git
diff HEAD` empty.
- B: delete `if (type === 'summary' && summaryDeclaresCurrency(d))
return 'currency';` (blob 06c9c5a → c9a3bbaa): 1 red, the summary pin.
Restored: blob == HEAD, `git diff HEAD` empty.
The tests import `./deriveMasterDetail` by relative path (source), so no
dist leg applies.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
Dev session `session_01ADHkmPj7KdYMP7i9jmhi3m`, card thread for seat
`domain:ui#2`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmPj7KdYMP7i9jmhi3m)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8559ee1 commit 0241df4
4 files changed
Lines changed: 187 additions & 5 deletions
File tree
- .changeset
- ui/packages/plugin-form/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 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 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 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 | + | |
92 | 128 | | |
93 | 129 | | |
94 | 130 | | |
| |||
127 | 163 | | |
128 | 164 | | |
129 | 165 | | |
130 | | - | |
| 166 | + | |
| 167 | + | |
131 | 168 | | |
132 | 169 | | |
133 | 170 | | |
| |||
211 | 248 | | |
212 | 249 | | |
213 | 250 | | |
214 | | - | |
| 251 | + | |
215 | 252 | | |
216 | 253 | | |
217 | 254 | | |
| |||
343 | 380 | | |
344 | 381 | | |
345 | 382 | | |
346 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
347 | 386 | | |
348 | 387 | | |
349 | 388 | | |
| |||
0 commit comments