Repository navigation
Commit 6be71ab
fix(ui): a stored field carrying an expression is read-only on every write surface (#31803)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbEhykwmktUP4pkKyVLHEVT7)_
Fixes #31759
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- **改了什么:** 声明了 `expression` 的存储字段(例如示例应用发票行的 `amount` = 数量 ×
单价,以及发票的「含税总额」)现在和公式字段一样,在所有可写入口都只读:自动布局的新建表单不再显示它;编辑表单和手写分区表单显示格式化后的值,不再是输入框;列表行内编辑、记录页行内编辑(详情、高亮条、路径阶段)不再提供编辑器;导入向导只把它作为匹配键,AI
表格导入不再提供它。判断集中在 `@object-ui/core` 新导出的 `isExpressionComputedField` 一处。
- **为什么改:** spec
规定这类字段「由引擎在每次写入时计算并存储,客户端传来的值永远不会生效」。之前表单照样给出输入框,用户输入的值保存时被静默替换(卡片实测:`PATCH
amount 999` 返回 200,读回 `323.94`)。
- **风险与回滚:** 只收窄可编辑范围,没有放宽任何东西。用户失去的只是一个从来不会生效的输入框。新增一个公开导出,所以声明为
`Clause-②: yes (widening)`,需要声明复审。服务端、spec 都没有改动。回滚即 revert 本 PR。
- **先看:**
`ui/packages/core/src/utils/expression-computed-field.ts`(规则本身),然后看
`ui/packages/plugin-form/src/ObjectForm.tsx` 和 `sectionFields.ts` 里打
`readonly: true` 的两处。
- **两分钟验证:** `cd ui && pnpm exec vitest run
packages/plugin-form/src/__tests__/objectFormExpressionComputed-31759.test.tsx`,预期
6 例全绿;或者 `pnpm dev --fresh` 后打开任意发票行点「Edit」,Amount 显示为 `$450.00`
文本,没有输入框。
- **需要你做的:** 无,席位落地(落地前欠一次 Clause-② 声明复审)。
## What changes
`@objectstack/spec`'s `FieldSchema.expression`: on a non-`formula` field
the engine computes the value from the row the write stores and stores
it, "so a client-sent value never stands". The ui decided "computed"
from type lists alone (`formula`, `summary`, `auto_number`, …), and none
of them read `expression`. Such a field was an editable input, grid
cell, record row and import column, and the save replaced what the user
typed without a word.
The rule, stated once: **a field carrying a non-empty `expression` is
computed exactly as a `formula` is.**
- **`@object-ui/core`: `isExpressionComputedField(def)` (new export).**
It reads `expression` the way the spec's own `isComputed`
(`packages/spec/src/data/inline-grid-columns.ts`) and
`deriveMasterDetail` read it: a non-empty bare string, or the `source`
of the `{ dialect, source }` envelope. It takes an untyped bag because
every caller holds served JSON.
- **`@object-ui/plugin-form`.**
- `filterAutoGeneratedFields` and `filterCreateModeFields`
(`autoLayout.ts`): the auto-layout create form drops the field, as it
drops a `formula`. This covers the flat and grouped arms of
`ObjectForm`, `ModalForm` and `DrawerForm`, which all call it.
- The two FormField producers, `ObjectForm.tsx` `generateField` and
`sectionFields.ts` `fromObjectSchema`, stamp `readonly: true`. The form
then draws the type's read face (for a currency, the formatted amount)
instead of an input, on the auto-layout edit form and in authored
sections on create or edit. It is `readonly`, not `disabled`: `disabled`
draws a greyed input, while `readonly` draws the plain value and is
omitted from the edit submit (`readonlyFieldNames` in `form.tsx`).
- `deriveMasterDetail.ts`: its two inline reads of `expression` switch
to the predicate. Behaviour is unchanged, since the line grid already
treated such a column as computed.
- **`@object-ui/plugin-grid`:** `isFieldInlineEditable` answers `false`,
so the column's cells are read-only.
- **`@object-ui/plugin-detail`:** a new module-private helper,
`isComputedDetailField(viewType, objectDefField)`, beside
`isComputedFieldType`. It returns the type union OR the predicate. The
details body (`DetailSection`), the highlight strip (`HeaderHighlight`)
and the path stage (`recordPathStageChange`) all call it, so the three
cannot drift.
- **`@object-ui/app-shell` (private):** `importTargetFields` keeps the
field as a match key only, the disposition a `readonly` field gets (it
has a real column; a `formula` has none and stays absent). The AI
spreadsheet import bar (`ExcelImportBar.tsx`) does not offer it; the
seat added this file to the surface in its amendment.
## Tests
Pins extend the existing harness files; one new file for the
`ObjectForm` render.
- `core/src/utils/__tests__/expression-computed-field.test.ts` (new):
bare string, envelope, formula; CONTROL: absent, empty, sourceless
envelope, null, non-string, no field; exported from the package entry.
-
`plugin-form/src/__tests__/objectFormExpressionComputed-31759.test.tsx`
(new, real `ObjectForm` render): auto-layout create drops a bare-string
and an envelope field; auto-layout edit draws no input and shows the
stored value; authored sections on create and edit draw no input.
CONTROL: a plain `currency` field is an editable input on every form; a
`formula` is drawn read-only as before.
- `plugin-form/src/__tests__/autoLayout.test.ts`: `applyAutoLayout` and
`filterCreateModeFields` drop it on create and keep it on edit; CONTROL:
a plain currency stays.
- `plugin-grid/src/inline-edit-options.test.ts`: not inline-editable for
a bare string, an envelope, or no type; CONTROL: a plain and an
empty-expression currency stay editable, a formula stays locked.
- `plugin-detail/src/__tests__/inlineEditTypeNarrowing.test.tsx`: the
highlight strip offers no editor; the details body offers no pencil and
no input in edit mode, and still shows the value; an envelope locks too;
CONTROL: the same currency without an expression is editable on both;
the helper is the union.
-
`plugin-detail/src/renderers/__tests__/record-path.stageChange-28199.test.tsx`:
a status field carrying an expression is never pressable.
- `app-shell/src/views/importTargetFields.test.ts`: match key only;
CONTROL: a plain currency stays a write column, a formula stays absent.
-
`app-shell/src/console/ai/__tests__/ExcelImportBar.importGrant-12082.test.tsx`:
the wizard is handed `['title', 'price']`, without the expression field
and without the formula.
**Ablation** (`node scripts/ablation-replace.mjs`; the subject resolves
through the vitest source alias `@object-ui/core` → `packages/core/src`,
so no `dist` is involved): `isExpressionComputedField` made to return
`false`, mutation proven on disk (anchor 1 → 0, blob `f6b07e05` →
`738b1b68`). The eight files gave **16 failed, 130 passed**. Every
failure is a new pin; every CONTROL row and every pre-existing test
stayed green. The restore was proven: blob equal to HEAD, `git diff
HEAD` empty.
## Acceptance notes
- **Should the engine refuse a client-written value for a
stored-expression field instead of replacing it?** Not built. The spec
declares the replace (`packages/spec/src/data/field.zod.ts`,
`expression`), so a refusal would narrow a published contract. `carrier:
maintainer` (a spec ruling on `FieldSchema.expression`).
- **What the user loses:** an input, inline editor or import column
whose typed value the save always replaced. Nothing that ever persisted
is lost; the engine computed the value before and still does.
- **Edit submit:** the edit form already writes only the fields that
differ from the record it read, so an untouched value was never sent.
What changes is that the user can no longer type one.
- **Live grid cell:** NOT MEASURED live, reason: the live run did not
open a list grid in inline-edit mode. The gate is pinned at
`isFieldInlineEditable`, the one predicate
`objectGridPersistedColumns.ts` reads.
- **The invoice record page** (`invoice-document.page.ts`) is an
authored page with no inline-editable rows, so its record-page check was
not meaningful (a plain field there had no editor either). The
record-page check was made on the line's default page.
## Verification
Head `405ec109`, which merges `origin/main` at `e253f3ab` (the merge
included #31757, so `invoice.amount` was checked live too). 22 files,
+507 / −27.
<details><summary>Suites (locked, two workers, run from the ui
root)</summary>
- `packages/plugin-form/ packages/core/`: 461 files passed, 6857 tests
passed, 28 skipped.
- `packages/plugin-grid/ packages/plugin-detail/`: 652 files passed, 1
skipped; 5759 tests passed, 18 skipped.
- app-shell: `views/importTargetFields.test.ts` + `console/ai/` (51
files, 293 tests) and `views/ObjectView.importPredicates.test.tsx` +
`views/__tests__/` (92 files, 774 tests), all passed.
- The eight pin files on the final head: 146 tests passed.
- Examples censuses (found with `git grep -l` of every touched source
path over `ui/examples/**/test/**` and `ui/e2e/**`):
`catalog-gallery-render.test.tsx` and
`form-field-channel-census-12130.test.tsx`, 613 tests passed.
`ui/e2e/record-flow-phone-targets.spec.ts` reads `DetailSection` and
`HeaderHighlight` and is left to `Build & E2E UI`.
- `pnpm --dir ui exec vitest run scripts/`: 170 files passed, 2 skipped;
5027 tests passed.
- `turbo run type-check` for core, plugin-form, plugin-grid,
plugin-detail and app-shell: 73/73 tasks. `eslint` over the touched ui
files: 0 errors.
</details>
<details><summary>Gates (dispatch-gates at the merged tree)</summary>
36 derived. All 33 run unlocked exited 0, including
`check-sdui-manifest.mjs` (no widget or registry name changed) and
`check-changeset-no-major`. `pnpm --dir ui exec vitest run scripts/`
exited 0 (above). The body-reading gates `check-closing-keyword-parity`
and `check-adr-0087-registration --base origin/main` ran on this body
through `GITHUB_EVENT_PATH` and exited 0. `--ran` reconciliation is in
the os-dev report on the card.
</details>
<details><summary>Live run</summary>
`pnpm dev --fresh` showcase on a random port, the Console from source
under Vite, signed in as the seeded admin, 1280×900 at deviceScaleFactor
2.
- **Invoice line `INV-1004 · Consulting hours`**
(`showcase_invoice_line.amount`, quantity 3 × 150): the Edit dialog
draws `Amount` as the text `$450.00`, with no `input[name="amount"]`;
Qty and Unit Price stay inputs. On the record page, double-clicking
Amount opens nothing and it has no pencil; double-clicking Qty opens its
editor (control).
- **Invoice `INV-1001`** (`showcase_invoice.amount`, "Total incl. Tax",
from #31757): the Edit dialog draws it as the text `$1,749.56`, with no
input; Tax Rate stays an input.
- Screenshots: project files, folder `issue-31759/live/shots`
(`line-edit-form.png`, `line-record-page.png`,
`line-record-dblclick-Amount.png`, `invoice-edit-form.png`,
`invoice-record-page.png`).
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jRozMk42iSKSwHdNts
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jRozMk42iSKSwHdNts)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 56cac5e commit 6be71ab
22 files changed
Lines changed: 507 additions & 27 deletions
File tree
- .changeset
- ui/packages
- app-shell/src
- console/ai
- __tests__
- views
- core/src
- utils
- __tests__
- plugin-detail/src
- __tests__
- renderers
- __tests__
- plugin-form/src
- __tests__
- plugin-grid/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 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
| 76 | + | |
70 | 77 | | |
71 | 78 | | |
72 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
| 60 | + | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
496 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
497 | 498 | | |
498 | 499 | | |
499 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| |||
0 commit comments