Skip to content

Commit 7fa9873

Browse files
feat(studio): add a field to a read-only base object as an extension in its pair (#28860)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbYRec3jiez4jm2QQrTy3GFq)_ Fixes #28575 ## 维护者速读 - **改了什么**:在 Studio 的数据栏里,已安装(只读)软件包的对象现在可以"添加字段"。表单工具栏和表格的"+"都提供这个入口。点创建时会自动建立定制包 `<包名>.custom`(只建一次,不弹确认),新字段作为对象扩展(`object_extension`)的草稿写进定制包,原对象本身不会被发送。字段名在创建前就显示带 `__c` 后缀的形式。选中软件包自带的字段时,只有标签、描述、帮助文字、占位文字和选项标签可以修改,修改写成该字段的 `fieldPatches`,其余属性只读,并有一句话说明可改范围。 - **为什么改**:ADR-0146 D10 规定客户在别人的对象上加的字段必须以 `__c` 结尾、写成扩展;软件包自带字段只能改显示类属性(`BASE_FIELD_DISPLAY_WHITELIST`)。之前只读包的对象完全不能加字段,只能整体接管。 - **风险与回滚**:只影响只读基础包的对象;可写软件包的添加字段和字段检查器不变(有对照测试)。草稿字段在发布前不会出现在记录表格的列里,这是表格只投影服务端已有列的既有行为。回滚就是 revert 本 PR。 - **先看**:`ui/packages/app-shell/src/views/studio-design/StudioCustomizeControls.tsx` 末尾的"Object extensions"一节(`foldObjectExtension`、`routeFoldedFieldsEdit`、`extensionBodyForSave`),以及 `StudioDesignSurface.tsx` 里 DataPillar 的扩展草稿加载、保存和 `addField` 分支。 - **两分钟验证**:在 Studio 打开一个只读基础包(如 HotCRM)的对象,切到表单,点"添加字段",输入"Region",创建前看到 `region__c`;创建后定制包出现、字段立即显示在表单里。再选中"Account Name",只有标签等几项可改,"必填"是灰的。 - **需要你做的**:无。 ## What changes - **Add field on a base object** (`@object-ui/app-shell`). When the Data pillar shows an object of a read-only base that has a customization (`StudioBaseCustomization`), and the object is the base's own (not one the pair added), Add field is offered in two places: in the Form toolbar's leading slot, and in the grid "+" through `AddFieldPopover`'s new `extensionField` mode. Create calls the N-17 ensure path once per base, without a prompt; the promise is cached and cleared on a refusal. The new field goes into an `object_extension` draft of the object, saved to the pair through the `/api/v1/meta` doors (`mode: 'draft'`, `packageId: <pair>`, `surface: 'studio'`). The base object's own body is never sent. - **The `__c` suffix.** In `extensionField` mode the popover shows the derived api name with `EXTENSION_FIELD_SUFFIX` before Create, and a typed name is suffixed the same way. The taken-name refusal reads the object as shown, so a published `region__c` is caught. - **The extension draft.** DataPillar reads the pair's draft of the extension (`readDraftForSave`), else its published body, else `{ extend: <object> }`, with its own save guard and auto-save. `foldObjectExtension` shows the served object with the extension's `fieldPatches` applied and its `fields` laid over by name, the draft winning, so a published extension field shows once. A published field the draft removed is left out. The grid's field count, the form, the preview and the inspector all read this folded object. Surface-level publish already acts on the pair's drafts. - **Edits routed.** `routeFoldedFieldsEdit` turns an edit of the folded fields back into the extension: any field that is not the base's is declared whole in `fields`, and on a base field only a change to a key of `BASE_FIELD_DISPLAY_WHITELIST` (from `@objectstack/spec/data`, no client copy) is written, into `fieldPatches[<field>]`, with option labels keyed by stored value. A cleared value is held as `''` in the buffer so the input can be emptied and retyped, and `extensionBodyForSave` drops it on save, so the package's text comes back. - **The inspector on a base field.** `ObjectFieldInspector` reads `BaseFieldDisplayPatchContext`. When it is on, only the whitelisted controls (label, description, help text, placeholder, option labels) are editable, under one sentence naming them, built from the whitelist. Every other control draws read-only. The context lives in `StudioCustomizeControls.tsx` so Studio does not import the lazily registered inspector. - **Refusals and walls.** An ensure or save refusal is shown in the server's words (`plainRefusal`). Under a walled posture, Add field draws disabled in the object header with the console's walled sentence (`engine.studio.customize.walled`) as its title and description. - **Strings** (`@object-ui/i18n`). `designer.field.basePatchOnly`, `.optionLabels` and `.separator` in the studio namespace, en and zh. ## Tests - New `DataPillar.baseObjectExtension-28575.test.tsx` runs the real DataPillar and the real `ObjectFieldInspector` over a client double, on a read-only base `com.example.hotcrm` with its pair: - "Region" from the Form toolbar ensures the pair once and saves `object_extension` / `crm_account` to the pair with `{ extend, fields: { region__c: … } }`; no `object` save is sent. The form shows the field at once and its inspector edits the extension. - A second add ("Tier") does not ensure again and saves both fields. - The grid "+" suffixes the same way. - A published `region__c` plus a second add shows each field exactly once, and the taken-name refusal still catches `region__c` (the seat's added case). - A label edit on a base field saves only `fieldPatches.name.label`; an option label edit saves `fieldPatches.industry.options.technology.label`. - `required` and `unique` on a base field are disabled; the whitelisted controls are enabled; the sentence names them. - An ensure refusal and a save refusal are each shown verbatim. - The walled case: no grid "+", the disabled button with the walled sentence, no form button, a base field's label disabled, nothing ensured or saved. - Control: on a writable package, a plain `region` is saved into the `object` body, nothing goes to `object_extension`, `required` stays enabled and no sentence shows. - New `StudioCustomizeControls.objectExtension-28575.test.ts` pins the pure pieces: the suffix, the body read from a stored document, the fold (patches, overlay, dedupe, removal), the base-owned names, the routing (whitelisted vs dropped, new fields, option labels) and the cleared-value round trip. ## Acceptance notes - **Wanted 1, grid half: a deviation.** The grid "+" is offered and writes the extension, but a draft field does not appear as a Records grid column before publish. The grid projects only the columns the server holds (`gridColumns` filtered by the published field names, cloud#1652), so the new field shows at once in the form, the field count and the inspector, and joins the grid once published. The seat accepted this measurement. - **The Form toolbar's Add field** sits in the designer's leading slot (`modeControl` / `FormToolbar leading`), because `ObjectFormDesigner.tsx` is outside this card's surface and hides its own add button when read-only. - **The walled disabled action** is drawn in the object header on the grid and form tabs, because the grid "+" column comes from `GridFieldAuthoringProvider`, outside the surface. - **The base-field mode reaches the inspector by React context**, because `MetadataInspectorProps` lives in `inspector-registry.ts`, outside the surface. - Renaming or duplicating an extension field in the inspector is not auto-suffixed; a name without `__c` is refused by the server, and that refusal is shown verbatim. ## Verification Head `fe34b830` on `00918c88`. Every run below was under `scripts/pm/os-verify-lock.sh` on a shared box. - ui: the two new files, 19 tests, green. Then every test under `app-shell/src/views/studio-design/` and `metadata-admin/inspectors/`, the zh census `zh-base-term.i18n-13131`, `studio-locale.i18n` and all of `packages/i18n/` (615 files, 6493 tests, `--maxWorkers=1`). One failed: `StudioDesignSurface.gridColumns.test.tsx`'s identity-churn liveness case, because the first cut keyed the grid columns on their names for every object. The columns now keep their identity semantics and are keyed on names only while a base object's extension is open. The `StudioDesignSurface.grid*`, `DataPillar*`, `StudioCustomizeControls*` and `oneSurface-28572` files were re-run on the fixed head: 36 files, 206 tests, green. - Ablations through `scripts/ablation-replace.mjs`, each restored to HEAD: - The popover's suffix made the identity: 3 of the 10 DataPillar cases red (Region, the grid "+", the published `region__c` case). - `routeFoldedFieldsEdit` sending base fields whole into `fields`: 7 red across both files. - `pnpm --filter @object-ui/app-shell run type-check`: green. `pnpm --dir ui exec vitest run scripts/`: 169 files, green. `check:type-check-debt`: OK. - `node scripts/pm/dispatch-gates.mjs --commands`: 34 commands, all exit 0, including `check-sdui-manifest`, `check-changeset-no-major`, `check-empty-changeset`, `check-adr-0087-registration`, `check-closing-keyword-parity` and `check:nul-bytes`. - `check-new-cross-file-line-citations --base origin/main`: 0 new citations. `eslint` on the changed ui files: 0 errors. - `origin/main` at `3b920f6d` touches none of these files and merges cleanly. Clause-②: no Metadata-protocol: none 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jVPKQuoz3QHyQ76RnU --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 581d294 commit 7fa9873

9 files changed

Lines changed: 1233 additions & 79 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(studio): add a field to a read-only base object, written as an extension in its customization pair
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
- **Before.** In Studio's Data pillar, a base object of an installed (read-only) package offered no Add field: the grid "+" and the Form toolbar's add were hidden with the rest of the read-only package, and the field inspector locked every property. The only way to add a field was to take the object over.
12+
- **Now.** On a base object of a read-only base with a customization pair, Add field is offered in the Form toolbar and the grid "+". Create ensures the pair `<base>.custom` (once, without a prompt) and writes an `object_extension` draft of the object into the pair through the `/api/v1/meta` doors. The base object's own body is never sent. The popover shows the api name with its `__c` suffix before Create, a typed name is suffixed too, and the taken-name refusal covers the fields of the object as shown, a published extension's fields included. The new field shows in the form at once and its inspector edits the extension; it joins the Records grid's columns once published, like any draft field.
13+
- **Base fields.** Selecting one of the package's own fields opens the inspector with only `BASE_FIELD_DISPLAY_WHITELIST` editable (label, description, help text, placeholder, option labels), read from the spec constant, under one sentence naming them. An edit is written as the field's `fieldPatches` entry in the extension, and clearing a property drops it from the patch so the package's text shows again. Every other property draws read-only.
14+
- **Refusals and walls.** A refusal from the ensure door or the save is shown in the server's own words. Under a walled posture the Add field action draws disabled with the console's walled sentence.
15+
- A writable package's add-field and inspector are unchanged.

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx‎

Lines changed: 72 additions & 34 deletions
Large diffs are not rendered by default.

‎ui/packages/app-shell/src/views/studio-design/AddFieldPopover.tsx‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
* its authoring context with no element to hand over): the host passes
2626
* `open` / `onOpenChange`, `children` is the element it is placed against,
2727
* and `returnFocusTo` names where focus goes back when it closes.
28+
*
29+
* objectstack#28575 (ADR-0146 D10) — on a read-only base's object the field
30+
* is the customer's extension field (`extensionField`): its api name takes
31+
* the spec's suffix (`region` → `region__c`), shown before Create, a typed
32+
* name the same, and Create always hands the suffixed name.
2833
*/
2934

3035
import * as React from 'react';
@@ -40,6 +45,7 @@ import type { FieldTypeId } from '../metadata-admin/previews/field-types.js';
4045
import { FieldTypePicker } from '../metadata-admin/inspectors/FieldTypePicker.js';
4146
import { t, tFormat, useMetadataLocale, type SupportedLocale } from '../metadata-admin/i18n.js';
4247
import { toFieldNameLoose } from '../metadata-admin/previews/object-fields-io.js';
48+
import { extensionFieldName } from './StudioCustomizeControls.js';
4349

4450
/**
4551
* The refusal for an api name another field of the object already holds, or
@@ -76,6 +82,11 @@ export interface AddFieldPopoverProps {
7682
returnFocusTo?: () => HTMLElement | null;
7783
/** Which edge of `children` the popover lines up with. */
7884
align?: 'start' | 'end';
85+
/**
86+
* objectstack#28575 — the field is a customer extension field of a base
87+
* object: its api name is suffixed (`__c`), and Create hands that name.
88+
*/
89+
extensionField?: boolean;
7990
}
8091

8192
export function AddFieldPopover({
@@ -86,6 +97,7 @@ export function AddFieldPopover({
8697
onOpenChange,
8798
returnFocusTo,
8899
align = 'end',
100+
extensionField = false,
89101
}: AddFieldPopoverProps): React.ReactElement {
90102
const locale = useMetadataLocale();
91103
const [openState, setOpenState] = React.useState(false);
@@ -111,18 +123,19 @@ export function AddFieldPopover({
111123
};
112124

113125
const trimmed = label.trim();
114-
const derived = toFieldNameLoose(trimmed).replace(/_+$/, '');
126+
const suffixed = (name: string) => (extensionField ? extensionFieldName(name) : name);
127+
const derived = suffixed(toFieldNameLoose(trimmed).replace(/_+$/, ''));
115128
const derivedTaken = !!derived && takenNames.includes(derived);
116129
// The label alone cannot name the field: the author types the api name.
117130
const asksName = !!trimmed && (!derived || derivedTaken);
118-
const typed = apiName.replace(/_+$/, '');
131+
const typed = suffixed(apiName.replace(/_+$/, ''));
119132
const typedRefusal = fieldNameTakenRefusal(typed, takenNames, locale);
120133
const typedTaken = !!typedRefusal;
121134
const canCreate = !!trimmed && (!asksName || (!!typed && !typedTaken));
122135
const submit = (e: React.FormEvent) => {
123136
e.preventDefault();
124137
if (!canCreate) return;
125-
onCreate(trimmed, type, asksName ? typed : undefined);
138+
onCreate(trimmed, type, asksName ? typed : extensionField ? derived : undefined);
126139
setOpen(false);
127140
};
128141
const nameHint = !asksName
@@ -203,6 +216,11 @@ export function AddFieldPopover({
203216
{nameHint}
204217
</p>
205218
)}
219+
{!nameHint && extensionField && typed && (
220+
<p className="text-xs text-muted-foreground" data-testid="add-field-api-name-preview">
221+
{t('designer.field.apiName', locale)}: <span className="font-mono text-foreground">{typed}</span>
222+
</p>
223+
)}
206224
</div>
207225
)}
208226
<FieldTypePicker label={t('designer.field.type', locale)} value={type} onCommit={setType} locale={locale} />

0 commit comments

Comments
 (0)