Skip to content

Commit bf95e78

Browse files
fix(platform-objects): title a unit of measure by its label, not its code (#39712)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D6q8dUDEiRaQSo6oAsacVv3)_ Fixes #39658 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:管理员在设置里新建计量单位「斤」(编码 JIN1)后,成功提示、记录标题、列表标题和选择框都显示「斤」,不再显示编码 JIN1。 - 为什么做:属于计量单位这组工作,替设置管理员解决「新建单位后看到的是机器编码」的问题。 - 出错会怎样:只影响自定义计量单位记录的标题显示,数量字段仍按编码存储和引用,改回原样即可直接撤回。 - 要你做什么:无。 ## What changes `sys_unit` declared `code` as its title (`nameField` and `displayNameField`). Both now name `label`, the required "name shown beside a quantity in this unit". This follows `sys_email_template` and `sys_personal_view`, and matches ADR-0079's "a record's human name". A quantity still stores and names its unit by code (ADR-0158 U4); only the unit row's own title changes. `sys_standard_unit_setting` and `sys_exchange_rate` are untouched, and so is item 12b (the ratio's 12-decimal display). Nothing reads `sys_unit`'s title as a code. No reference field points at `sys_unit`, and the console's unit display (`ui/packages/core/src/utils/unit-display.ts`) reads the `label` column by name, not through the title pointer. No test pinned `code` as the title. No generated artifact carries these two declarations. **Read first** (by risk): 1. `packages/platform-objects/src/system/sys-unit.object.ts` lines 125-126: the two-pointer change. 2. `packages/platform-objects/src/system/sys-unit.object.test.ts`: the new pin, which also asserts that `label` stays required, so the title can never be empty. **Two-minute check:** `pnpm --filter @objectstack/platform-objects exec vitest run --maxWorkers=2 src/system/sys-unit.object.test.ts` should report 31 passed. In a running console, create unit 斤 (code JIN1): the toast should read 「计量单位"斤"已创建」. ## Tests - Pin test: `sys_unit` is titled by `label` (`nameField`, `displayNameField`), and `label` is required. - Ablation: I reverted `nameField` to `'code'` on disk, and the pin turned red (`Expected: "label"`, `Received: "code"`, 1 failed / 30 passed). Then I restored it. <details><summary>Package suite and typecheck, at f577f2f</summary> - `pnpm --filter @objectstack/platform-objects test`: Test Files 137 passed (137), Tests 2458 passed (2458), command-exit 0 under os-verify-lock. The package was built first: its own suite self-imports `@objectstack/platform-objects/system` from `dist`, and the first run without that build failed on exactly that import. - `pnpm --filter @objectstack/platform-objects typecheck`: exit 0 (`check:test-typecheck: OK`). - `pnpm --filter '@objectstack/platform-objects^...' build`: dependency closure built. </details> ## Acceptance notes - The object's `description` still says "named by a code in the organization namespace". That describes the code namespace, not the title. It is outside this card's file surface and I left it unchanged. ## Verification <details><summary>Derived gate subset (dispatch-gates --commands, at f577f2f)</summary> - 65 derived, 57 run with exit 0, 8 NOT MEASURED, 0 UNRUN (`dispatch-gates --ran`: `65 derived famil(ies) accounted for`). - NOT MEASURED, exit 3 PREREQUISITE NOT MET: `check:dual-build-cjs-loads` and `check:lean-entry-closure` (they need a workspace-wide `dist`), `check:i18n` (the CLI is not built), `check-plugin-teardown-shape --self-test` (shallow clone). CI runs these. - NOT MEASURED, exit 124 (killed by timeout on a shared box, no verdict printed): `check-comment-mask-corpus`, `check:query-options-erasure`, `check:slot-lookup`, `check:type-check-debt`. CI runs these. - `check:nul-bytes`: exit 0. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4d1cnRvyiAqrarmDhZV <!-- signed: repo:objectstack@os-elon-musk · os-elon-musk · session_016WV4d1cnRvyiAqrarmDhZV --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 758cd97 commit bf95e78

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/platform-objects': patch
3+
---
4+
5+
fix(platform-objects): a unit of measure is titled by its label, not its code
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`sys_unit` now declares `label` as its title field (`nameField` and `displayNameField`), where it declared `code`. An admin who creates a unit 斤 with code `JIN1` now sees 斤 in the "created" message, the record header, list titles and pickers, instead of `JIN1`. A quantity still stores and names its unit by code; only the unit row's own title changes. `sys_standard_unit_setting` and `sys_exchange_rate` keep their code titles.

‎packages/platform-objects/src/system/sys-unit.object.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ describe('sys_unit — declaration (ADR-0158 U3)', () => {
6363
expect(SysUnit.pluralLabel).toBe('Units of Measure');
6464
});
6565

66+
it('is titled by its label, the human name, never by its code (ADR-0079)', () => {
67+
// The toast on create and every face that shows a record title read the
68+
// declared title field: a unit 斤 coded JIN1 must read 斤 there.
69+
expect(SysUnit.nameField).toBe('label');
70+
expect(SysUnit.displayNameField).toBe('label');
71+
expect(fields.label.required).toBe(true);
72+
});
73+
6674
describe('uniqueness', () => {
6775
const uniqueIndexes = (SysUnit.indexes ?? []).filter((i: any) => i.unique);
6876

‎packages/platform-objects/src/system/sys-unit.object.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export const SysUnit = ObjectSchema.create({
122122
description:
123123
"The organization's own units of measure, beside the standard units every organization has — " +
124124
'one row per unit, named by a code in the organization namespace.',
125-
displayNameField: 'code',
126-
nameField: 'code', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
125+
displayNameField: 'label',
126+
nameField: 'label', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
127127
highlightFields: ['code', 'label', 'dimension', 'ratio', 'retired'],
128128

129129
fields: {

0 commit comments

Comments
 (0)