Skip to content

Commit 6be71ab

Browse files
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
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/core': patch
3+
'@object-ui/plugin-form': patch
4+
'@object-ui/plugin-grid': patch
5+
'@object-ui/plugin-detail': patch
6+
---
7+
8+
fix(ui): a stored field carrying an `expression` is read-only on every write surface, as a formula is
9+
10+
Clause-②: yes (widening)
11+
Metadata-protocol: none
12+
13+
- **Before.** A non-`formula` field with an `expression` (for example a `currency` amount computed from quantity times unit price) is computed by the engine on every write, so a client-sent value never stands. The record form still drew it as an editable input, a list grid offered an editable cell, the record page offered inline edit, and the import wizard offered it as a column to write. The save then replaced what the user typed, with no message.
14+
- **Now.** Such a field is computed exactly as a `formula` is. The auto-layout create form leaves it out. The auto-layout edit form, and an authored form section on create or edit, draw its type's read face (the formatted value, no input), and the edit save does not send it. A list grid cell, the record page's details body, its highlight strip and its path stage offer no editor. The import wizard offers it only as a match key, as it does a `readonly` field, and the spreadsheet import bar does not offer it. The value itself is unchanged: the engine computed it before and still does.
15+
- **The widening.** `@object-ui/core` exports `isExpressionComputedField(def)`. It answers whether an object field carries a non-empty `expression`, either a bare CEL string or the `source` of the `{ dialect, source }` envelope, which is the spec's own reading. Every gate above asks it alongside its type list. Nothing is removed or renamed.

‎ui/packages/app-shell/src/console/ai/ExcelImportBar.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import { createAuthenticatedFetch } from '@object-ui/auth';
3333
import { toast } from 'sonner';
3434
import { useObjectTranslation } from '@object-ui/i18n';
35-
import { resolveAffordance } from '@object-ui/core';
35+
import { resolveAffordance, isExpressionComputedField } from '@object-ui/core';
3636
import { usePermissions } from '@object-ui/permissions';
3737
import { ImportWizard } from '@object-ui/plugin-grid';
3838

@@ -60,13 +60,20 @@ interface ExcelImportBarProps {
6060
const SKIP_OBJECT_PREFIXES = ['sys_', 'ai_', 'cloud_'];
6161
const NON_WRITABLE_TYPES = ['formula', 'summary', 'autonumber'];
6262

63-
/** Normalize a getObjectSchema result's fields → the ImportWizard field shape. */
63+
/**
64+
* Normalize a getObjectSchema result's fields → the ImportWizard field shape.
65+
*
66+
* Only fields an import can write are kept: not a computed type, and not a
67+
* stored field carrying an `expression`, which the engine computes on every
68+
* write so an imported value never stands (objectstack#31759).
69+
*/
6470
function normalizeFields(schema: any): WizardField[] {
6571
const raw = schema?.fields ?? schema?.data?.fields ?? schema?.item?.fields ?? {};
6672
const entries: Array<[string, any]> = Array.isArray(raw)
6773
? raw.map((f: any) => [f?.name, f])
6874
: Object.entries(raw);
6975
return entries
76+
.filter(([, def]) => !isExpressionComputedField(def))
7077
.map(([name, def]) => ({
7178
name: (def?.name ?? name) as string,
7279
label: (def?.label ?? def?.name ?? name) as string,

‎ui/packages/app-shell/src/console/ai/__tests__/ExcelImportBar.importGrant-12082.test.tsx‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
4343
}));
4444
vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({
4545
...(await importOriginal<Record<string, unknown>>()),
46-
ImportWizard: (props: { objectName: string }) => {
47-
h.wizard.push({ objectName: props.objectName });
46+
ImportWizard: (props: { objectName: string; fields?: Array<{ name: string }> }) => {
47+
h.wizard.push({ objectName: props.objectName, fields: props.fields });
4848
return <div data-testid="import-wizard" />;
4949
},
5050
}));
@@ -140,3 +140,24 @@ describe("the spreadsheet import bar: the map's other layers and fail-open (obje
140140
expect(await pressImport(dataSource)).toBe('crm_deal');
141141
});
142142
});
143+
144+
describe('the spreadsheet import bar: a field carrying an expression (objectstack#31759)', () => {
145+
it('is not offered to the wizard: the engine computes it on every write, so an imported value never stands', async () => {
146+
const dataSource = {
147+
getObjectSchema: vi.fn(async (_name: string) => ({
148+
fields: {
149+
title: { type: 'text', label: 'Title' },
150+
price: { type: 'currency', label: 'Price' },
151+
amount: { type: 'currency', label: 'Amount', expression: 'record.quantity * record.unit_price' },
152+
total: { type: 'formula', label: 'Total' },
153+
},
154+
})),
155+
};
156+
render(<ExcelImportBar file={FILE} dataSource={dataSource} onDone={vi.fn()} />);
157+
await settle();
158+
expect(await pressImport(dataSource)).toBe('crm_account');
159+
const offered = (h.wizard[h.wizard.length - 1].fields as Array<{ name: string }>).map((f) => f.name);
160+
// CONTROL: the plain currency field of the same shape is still offered; a formula still is not.
161+
expect(offered).toEqual(['title', 'price']);
162+
});
163+
});

‎ui/packages/app-shell/src/views/importTargetFields.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,24 @@ describe('importTargetFields', () => {
114114
);
115115
});
116116
});
117+
118+
describe('importTargetFields: a field carrying an expression (objectstack#31759)', () => {
119+
const computedFields = {
120+
amount: { type: 'currency', label: 'Amount', expression: 'record.quantity * record.unit_price' },
121+
margin: { type: 'number', label: 'Margin', expression: { dialect: 'cel', source: 'record.a - record.b' } },
122+
price: { type: 'currency', label: 'Price' },
123+
total: { type: 'formula', label: 'Total', expression: 'record.a * 2' },
124+
};
125+
126+
it('is a match key only, never a write column, as a readonly field is', () => {
127+
const byName = Object.fromEntries(importTargetFields('line', computedFields).map((f) => [f.name, f]));
128+
expect(byName.amount).toMatchObject({ matchOnly: true, required: false });
129+
expect(byName.margin).toMatchObject({ matchOnly: true, required: false });
130+
});
131+
132+
it('CONTROL: the same currency field without one stays a write column, a formula stays absent', () => {
133+
const byName = Object.fromEntries(importTargetFields('line', computedFields).map((f) => [f.name, f]));
134+
expect(byName.price.matchOnly).toBeUndefined();
135+
expect(byName.total).toBeUndefined();
136+
});
137+
});

‎ui/packages/app-shell/src/views/importTargetFields.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* matching leaks the column's values by existence.
2424
*/
2525

26-
import { resolveFieldAffordance } from '@object-ui/core';
26+
import { resolveFieldAffordance, isExpressionComputedField } from '@object-ui/core';
2727

2828
export interface ImportTargetField {
2929
name: string;
@@ -52,7 +52,12 @@ export function importTargetFields(
5252
const out: ImportTargetField[] = [];
5353
for (const [name, def] of Object.entries(fields || {})) {
5454
const computed = COMPUTED_TYPES.has(def?.type);
55+
// A stored field carrying an `expression` is computed by the engine on
56+
// every write, so an imported value never stands (objectstack#31759). It
57+
// has a real column, so it stays a match key, as a `readonly` field does;
58+
// a `formula` has none and is not offered at all.
5559
const writable = !computed
60+
&& !isExpressionComputedField(def)
5661
&& def?.type !== 'autonumber'
5762
&& !def?.readonly
5863
&& resolveFieldAffordance('listImport', perms, objectName, name);

‎ui/packages/core/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export * from './utils/external-write-refusal.js';
7575
// for why a second copy was not an option. `@object-ui/fields` re-exports every
7676
// name, so its published surface is unchanged.
7777
export * from './utils/retired-field-types.js';
78+
// The computed-by-expression predicate (objectstack#31759): a field carrying an
79+
// `expression` is computed, whatever its type, so no write surface offers it a
80+
// value. Read by the form, grid, detail and import gates.
81+
export * from './utils/expression-computed-field.js';
7882
export * from './utils/unmaterialized-fields.js';
7983
// [#5729] The consumer half of objectstack#10235's ruling: the SERVED
8084
// per-column sortability projection, and the one spelling of its contract
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* `isExpressionComputedField` (objectstack#31759): a field carrying a non-empty
11+
* `expression` is computed, whatever its type — read the way the spec's own
12+
* `isComputed` (`packages/spec/src/data/inline-grid-columns.ts`) reads it.
13+
*/
14+
import { describe, it, expect } from 'vitest';
15+
import { isExpressionComputedField } from '../expression-computed-field';
16+
import { isExpressionComputedField as fromEntry } from '../../index';
17+
18+
describe('isExpressionComputedField', () => {
19+
it('a stored field carrying a bare CEL string is computed', () => {
20+
expect(isExpressionComputedField({ type: 'currency', expression: 'record.quantity * record.unit_price' })).toBe(true);
21+
});
22+
23+
it('a stored field carrying the CEL envelope is computed', () => {
24+
expect(
25+
isExpressionComputedField({ type: 'number', expression: { dialect: 'cel', source: 'record.a + 1' } }),
26+
).toBe(true);
27+
});
28+
29+
it('a formula carries one too: the predicate does not ask the type', () => {
30+
expect(isExpressionComputedField({ type: 'formula', expression: 'record.a * 2' })).toBe(true);
31+
});
32+
33+
it('CONTROL: a field with no expression, an empty one or a sourceless envelope is not computed', () => {
34+
expect(isExpressionComputedField({ type: 'currency' })).toBe(false);
35+
expect(isExpressionComputedField({ type: 'currency', expression: '' })).toBe(false);
36+
expect(isExpressionComputedField({ type: 'currency', expression: { dialect: 'cel' } })).toBe(false);
37+
expect(isExpressionComputedField({ type: 'currency', expression: { dialect: 'cel', source: '' } })).toBe(false);
38+
expect(isExpressionComputedField({ type: 'currency', expression: null })).toBe(false);
39+
expect(isExpressionComputedField({ type: 'currency', expression: 42 })).toBe(false);
40+
});
41+
42+
it('CONTROL: no field at all is not computed', () => {
43+
expect(isExpressionComputedField(undefined)).toBe(false);
44+
expect(isExpressionComputedField(null)).toBe(false);
45+
expect(isExpressionComputedField('record.a')).toBe(false);
46+
});
47+
48+
it('is exported from the package entry', () => {
49+
expect(fromEntry).toBe(isExpressionComputedField);
50+
});
51+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* ObjectUI — the computed-by-expression predicate
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* Is this object field's value computed from its `expression`, so that no
11+
* write surface may offer it a value? (objectstack#31759)
12+
*
13+
* `@objectstack/spec`'s `FieldSchema.expression` makes a field computed on
14+
* every type. On a `formula` field it is computed on read. On any other
15+
* (stored) field the engine computes it from the row the write stores and
16+
* stores the result, "so a client-sent value never stands". The spec names
17+
* the class in the same terms: a `lookupAutofill` target must be "not
18+
* computed (`formula`, `summary`, `autonumber`, or an `expression`)".
19+
*
20+
* The edit gates in this repo used to decide "computed" from a list of TYPES
21+
* (`formula`, `summary`, `auto_number`, …), each list its own, and none read
22+
* `expression`. So a stored `currency` field carrying one was an editable
23+
* input on the record form, an editable grid cell, an inline-editable record
24+
* row and an import write column, and the save replaced what the user typed
25+
* without a word. Every such gate asks this predicate as well as its type
26+
* list: a surface treats a field carrying an `expression` exactly as it
27+
* treats a `formula`.
28+
*
29+
* The reading is the spec's own `isComputed`
30+
* (`packages/spec/src/data/inline-grid-columns.ts`): a non-empty `expression`,
31+
* either the bare CEL string or the `source` of the `{ dialect, source }`
32+
* envelope the build emits. An empty string or an envelope with no source
33+
* declares nothing, so it is not computed.
34+
*
35+
* Takes an untyped bag on purpose: every caller holds a raw object-schema
36+
* field, served JSON, never a parsed `FieldSchema`.
37+
*/
38+
export function isExpressionComputedField(def: unknown): boolean {
39+
if (def === null || typeof def !== 'object') return false;
40+
const expression = (def as { expression?: unknown }).expression;
41+
const source =
42+
typeof expression === 'string'
43+
? expression
44+
: expression !== null && typeof expression === 'object'
45+
? (expression as { source?: unknown }).source
46+
: undefined;
47+
return typeof source === 'string' && source.length > 0;
48+
}

‎ui/packages/plugin-detail/src/DetailSection.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { DetailsColumnCapContext, framelessSectionColumns, useDefaultRecordPage
6060
import { hasCellValue } from './emptiness';
6161
import {
6262
enrichDetailField,
63-
isComputedFieldType,
63+
isComputedDetailField,
6464
isInlineExcludedDetailFieldType,
6565
isMaskedDetailFieldType,
6666
} from './fieldEnrichment';
@@ -492,8 +492,9 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
492492
// the UNION of the two, so an authored display `type` (which still drives
493493
// renderer/editor selection through `enrichedField.type`) can narrow
494494
// editability but never widen it (objectui#3355). Shared with
495-
// HeaderHighlight via `isComputedFieldType` so the two can't drift.
496-
const isComputedField = isComputedFieldType(field.type, objectDefField?.type);
495+
// HeaderHighlight via `isComputedDetailField` so the two can't drift.
496+
// A stored field carrying an `expression` is computed too (objectstack#31759).
497+
const isComputedField = isComputedDetailField(field.type, objectDefField);
497498
// Honor the OBJECT metadata's read-only flag too — the enrichment above
498499
// intentionally doesn't copy `readonly` into enrichedField, so read it
499500
// straight off objectDefField (covers formula / non-updateable fields the

‎ui/packages/plugin-detail/src/HeaderHighlight.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Pencil } from 'lucide-react';
2626
import { InlineFieldInput } from './InlineFieldInput';
2727
import {
2828
enrichDetailField,
29-
isComputedFieldType,
29+
isComputedDetailField,
3030
isInlineExcludedDetailFieldType,
3131
} from './fieldEnrichment';
3232
import { NON_EDITABLE_SYSTEM_FIELDS } from './systemFields';
@@ -193,7 +193,7 @@ export const HeaderHighlight: React.FC<HeaderHighlightProps> = ({
193193
: pickLocalized(objectDefField?.label, language) || undefined;
194194
const caption = fieldLabel(objectName || '', field.name, entryLabel || field.name);
195195

196-
// Field-level editability gate — shares `isComputedFieldType` with
196+
// Field-level editability gate — shares `isComputedDetailField` with
197197
// DetailSection so the strip and the body agree on which highlights
198198
// are editable. Computed types (formula/summary/rollup/auto_number),
199199
// `readonly` (view OR object metadata), and immutable system/audit
@@ -203,7 +203,8 @@ export const HeaderHighlight: React.FC<HeaderHighlightProps> = ({
203203
// not `resolvedType` — an authored display `type` can narrow
204204
// editability but never widen it (objectui#3355). `resolvedType`
205205
// keeps its display precedence for renderer selection just below.
206-
const isComputed = isComputedFieldType(field.type, objectDefField?.type);
206+
// A stored field carrying an `expression` is computed too (objectstack#31759).
207+
const isComputed = isComputedDetailField(field.type, objectDefField);
207208
const isReadonly =
208209
field.readonly === true || objectDefField?.readonly === true;
209210
const isSystem = NON_EDITABLE_SYSTEM_FIELDS.has(field.name);

0 commit comments

Comments
 (0)