Repository navigation
Commit 7fa9873
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
- .changeset
- ui/packages
- app-shell/src/views
- metadata-admin/inspectors
- studio-design
- i18n/src/namespaces/studio
| 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 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
| |||
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| 48 | + | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
| |||
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
79 | 90 | | |
80 | 91 | | |
81 | 92 | | |
| |||
86 | 97 | | |
87 | 98 | | |
88 | 99 | | |
| 100 | + | |
89 | 101 | | |
90 | 102 | | |
91 | 103 | | |
| |||
111 | 123 | | |
112 | 124 | | |
113 | 125 | | |
114 | | - | |
| 126 | + | |
| 127 | + | |
115 | 128 | | |
116 | 129 | | |
117 | 130 | | |
118 | | - | |
| 131 | + | |
119 | 132 | | |
120 | 133 | | |
121 | 134 | | |
122 | 135 | | |
123 | 136 | | |
124 | 137 | | |
125 | | - | |
| 138 | + | |
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
| |||
203 | 216 | | |
204 | 217 | | |
205 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
206 | 224 | | |
207 | 225 | | |
208 | 226 | | |
| |||
0 commit comments