Skip to content

Commit f71d488

Browse files
feat(units): show a quantity with its unit label (#35490) (#37449)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg8ZBQe4UHadd2fGHGeWRW9V)_ repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS Fixes #35490 Fixes #37471 Clause-②: yes (widening) Metadata-protocol: added ## What A quantity (`unitConfig` on a `number` field) now renders with its unit on every display face: the grid cell, the form (read-only and edited), and the detail row (DetailSection, the quick-look panel, RelatedList). A unit-code `text` field (`unitMode: 'code'`) shows its unit's name (Open item 8 (A)). - **Choosing a unit (Open item 8, ruled A: 「有下拉」, #37471).** In a form, a unit code field is a searchable picker (`UnitCodeField`), never a typed box. That covers a `text` field declaring `unitMode: 'code'` and the `unitField` a `record` quantity on the same form points at; the form stamps that pointer (`withUnitCodePointer`) and hands the field its record. The picker lists the record's organization's non-retired `sys_unit` rows, then every standard code, each by its translated name (spec fallback) and limited to the declared `unitDimension`. It stores the code. Read-only, the field shows the unit's name, not the bare code. - **Authorable key (`Metadata-protocol: added`).** `unitConfig` is now declared on `@object-ui/types`' `FormField` / `FormFieldSchema`, by reference to the spec's `FieldSchema.unitConfig`, beside `currencyConfig`, so `objectui validate` accepts it on a hand-authored form field. `@object-ui/types` ships `minor` (the `scale` / `currencyConfig` precedent). The tolerant face now checks the key's value against `UnitConfigSchema` where it passed as an unknown key before. - **Which unit.** Fixed mode uses `unitConfig.unit`. Record mode reads the row's `unitField`. Grid, ListView and RelatedList add the unit column and `organization_id` to their `$select` when the unit column is not shown. - **Name.** An org unit (`sys_unit`, U3) shows its `label`. A standard code shows the platform's name for it in the reader's locale (L2, 2A): the spec English base `STANDARD_UNIT_NAMES`, and each platform bundle serves `messages.standardUnit<CODE>`. The UI reads `app.messages.standardUnit<CODE>` and falls back to the English base. - **Decimals.** These come from the unit row (org unit `decimal_places`, or the `sys_standard_unit_setting` row for a standard code, OI10 (A)). The row is the one whose `organization_id` matches the record's organization (note 7180167601). L4 holds: the display width is `min(unit places, field scale)`. - **Rounding (OI6, ruled A).** The display rounds half away from zero (Intl `halfExpand`) at a fixed width. The stored value, footer totals (summed exact, then formatted), exports, the API and MCP stay exact. No marker is shown. - **Bare code.** A retired ("deleted") org unit, an unknown code, or a reader who may not read `sys_unit` (an external member, comment 7030066814) gets the bare code, never an error. The rows are read once per data-source adapter for the session (the `homeAmountPreview` precedent). Each table is read on its own, so a refusal of one leaves the other usable. ## Server-side home of the names (measured) The platform-objects translation bundles, flat `messages` map, with single-segment keys `standardUnit<CODE>`. The keys are not dotted `units.standard.<CODE>` because `FileI18nAdapter.resolveKey` splits on `.` and walks the parts as nesting (the plugin-audit precedent). The console's served document lays bundles under `app`, so the UI key is `app.messages.standardUnit<CODE>`. English is copied from the spec base, never re-typed. Ten locales are translated, and a pin test holds every locale to exactly the 41 codes. ## Acceptance notes - **platform-catalog row:** deferred to #37431 (`skills/**` fence). - **Standalone `ObjectGrid` with no `SchemaRendererContext`:** there is no data source, so no unit rows are read. Codes show bare at the field's own width. This known limit is pinned in `gridQuantityUnit-35490.test.tsx`. - **English names are singular,** e.g. `1,235 kilogram`. - **The catalog is cached per adapter for the session.** A unit edited mid-session shows after a reload. A failed read stays unread for the session; this is deliberate, because an external member's refusal is permanent and re-reading per mount would cost a request per grid cell. Follow-ups N4/N5 are on #37472. - **Grid and detail cells of a pointed unit field** show the stored code. The pointer is stamped on the form face, where the quantity and its unit field sit together. - **Known overlap with #37436 (#36806).** Both PRs edit the `const extraFields = [...]` line in `ui/packages/plugin-grid/src/objectGridRowLoad.ts`: this PR appends `...quantityUnitFields`, and #37436 inserts `...lockOperandFields`. Whichever lands second merges main and keeps both entries. ## Verification - Card tests: core 21, fields 26, components form, plugin-grid 2, plugin-list, plugin-detail 3. green; the fields, core, components-form and schema-catalog suites (13,000+ tests) pass on the picker head. spec `standard-units` 18/18; platform-objects translations 613/613. - Ablations, each restored to blob == HEAD: - resolver → 24/52 red; - org-row pick → 8/48 red; - served-name read → 1/26 red (the zh served-name case); - picker's retired-unit filter → 4/56 red; - form pointer stamp → 1/2 red; - TextField's picker branch → 3/30 red. - Typecheck: spec, platform-objects and fields are clean. `check:api-surface` was regenerated (2 added exports). - Gates: `check-i18n-bundles`, `check-i18n-stale-fill` and `check-i18n-walk-parity` pass. `check-published-readme-exports` passes. - `overlap-check`: clean against main, #37437, #37436 and #37427. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CXM7nqtiQ3M9JqGAqL <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent df0894a commit f71d488

46 files changed

Lines changed: 2576 additions & 44 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/platform-objects': patch
4+
'@object-ui/core': patch
5+
'@object-ui/fields': patch
6+
'@object-ui/types': minor
7+
'@object-ui/components': patch
8+
'@object-ui/plugin-grid': patch
9+
'@object-ui/plugin-list': patch
10+
'@object-ui/plugin-detail': patch
11+
---
12+
13+
feat(fields): a quantity displays with its unit's label and display decimal places in grid, form and detail (ADR-0158 R1 display)
14+
15+
Clause-②: yes (widening)
16+
Metadata-protocol: added
17+
18+
A `number` field that declares `unitConfig` now draws its unit beside the number on every face: grid and list cells, the record page (sections, highlights, the quick-look panel, related lists), and the form, both read-only and beside the edited box. A `fixed` quantity shows its one unit; a `record` quantity shows the unit its row's code field holds, and the list, grid and related-list reads fetch that field (and the row's organization) even when no column shows it. A `text` field declaring `unitConfig: { unitMode: 'code' }` shows the code's label.
19+
20+
- A standard code (`KGM`, `H87`, …) shows the platform's name for it in the reader's locale; an organization code shows its `sys_unit` label. `@objectstack/spec` now exports the English base name of every standard code, `STANDARD_UNIT_NAMES` and `standardUnitName(code)`, beside `STANDARD_UNITS`. `@objectstack/platform-objects` serves each locale's names through the i18n service, as `messages.standardUnit<CODE>` in every platform bundle, and a reader without a translation falls back to the English base.
21+
- Decimal places: a standard code takes its organization's `sys_standard_unit_setting` row, an organization code its `sys_unit.decimal_places`. The row is the record's own organization's, never merely the first one returned. The field's `scale` is the ceiling (ADR-0158 L4). The number is drawn at that fixed width, rounded half away from zero (ADR-0158 Open item 6, ruled A): `1.5` beside a unit of 0 places reads `2`. Only the display rounds; nothing is rounded at write, and footers, exports and the API keep the exact value.
22+
- A retired organization unit, and a unit whose row the reader may not read (an external member holds no `sys_unit` read), show the bare code, never an error.
23+
- One resolver (`resolveQuantityUnit` in `@object-ui/core`) and one formatter (`formatQuantity` in `@object-ui/fields`) serve every face.
24+
- `@object-ui/types`: `unitConfig` is now an authorable key on `FormField` and `FormFieldSchema` (by reference to the spec's `FieldSchema.unitConfig`, beside `currencyConfig`), so `objectui validate` accepts it on a hand-authored form field. The tolerant face now checks its value against the spec's `UnitConfigSchema`, where before it passed as an unknown key. On the form face the `number` widget reads it, and on a `text` field `unitMode: 'code'` makes the text widget the unit picker.
25+
- A unit code field is chosen, never typed (ADR-0158 Open item 8): a `text` field declaring `unitMode: 'code'`, and the `unitField` a `record` quantity on the same form points at, draw a searchable picker (`UnitCodeField`) of the organization's non-retired units and the standard codes, each by name and restricted to the declared `unitDimension`. It stores the code; read-only, it shows the unit's name. `@object-ui/core` exports the option list (`unitPickerOptions`) and the pointer helpers (`quantityUnitCodePointers`, `withUnitCodePointer`, `declaresUnitCode`).

‎content/docs/frontend/fields.mdx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@ ObjectUI comes with built-in support for the standard [ObjectStack Protocol](htt
8484
| `user` | Person picker — searches the `sys_user` object (a lookup specialized to users) |
8585
| `owner` | Record owner — a `user` field, typically read-only and stamped with the current user |
8686

87+
## Quantities with a unit
88+
89+
A `number` field that declares `unitConfig` is a quantity, and every face draws it with its unit: grid and
90+
list cells, the record page, the quick-look panel, related lists, and the form (read-only, and beside the
91+
edited box). A record-mode quantity, for example, declares
92+
`unitConfig: { unitMode: 'record', unitField: 'unit_code' }` on its `number` field.
93+
94+
- **Which unit.** `unitMode: 'fixed'` shows its one `unit`. `unitMode: 'record'` shows the code the row's
95+
`unitField` holds; the list, grid and related-list reads fetch that field, and the row's
96+
`organization_id`, even when no column shows them. A `text` field declaring `unitMode: 'code'` shows the
97+
code's label.
98+
- **Choosing a unit.** In a form, a `text` field declaring `unitMode: 'code'`, and the `unitField` a
99+
`record` quantity on the same form points at, are a searchable unit picker, never a typed box: the
100+
organization's non-retired units, then the standard codes, each by name and limited to the declared
101+
`unitDimension`. The picker stores the code. Read-only, the field shows the unit's name.
102+
- **Which label.** A standard code (`KGM`, `H87`, …) shows the platform's name for it in the reader's
103+
language, served by the platform's i18n service (`messages.standardUnit<CODE>`), falling back to the
104+
English name in `@objectstack/spec` (`STANDARD_UNIT_NAMES`). An organization's own code shows its
105+
`sys_unit` label.
106+
- **How many decimal places.** A standard code takes the organization's `sys_standard_unit_setting` row,
107+
and an organization code its `sys_unit.decimal_places`, always the row of the record's own
108+
organization. The field's `scale` is the ceiling. The number is drawn at that fixed width, rounded half
109+
away from zero (`1.5` beside a unit of 0 places reads `2`). With no unit setting, the field's own width
110+
applies. Only the display rounds: the stored value, totals, exports and the API keep the exact value.
111+
- **The bare code.** A retired organization unit, or one whose row the reader may not read, shows its code
112+
with no label.
113+
114+
The unit rows are read through the data source of the surrounding `SchemaRendererProvider`, once per
115+
session.
116+
87117
## How the Console draws field metadata
88118

89119
What a field's metadata makes the Console draw (number inputs, polymorphic record pointers,

‎packages/platform-objects/src/apps/translations/ar.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { arObjects } from './ar.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* العربية (ar) — Setup App Translations
89
*/
910
export const ar: TranslationData = {
1011
objects: arObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('ar'),
1114
apps: {
1215
account: {
1316
label: 'الحساب',

‎packages/platform-objects/src/apps/translations/de.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { deObjects } from './de.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* Deutsch (de) — Setup App Translations
89
*/
910
export const de: TranslationData = {
1011
objects: deObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('de'),
1114
apps: {
1215
account: {
1316
label: 'Konto',

‎packages/platform-objects/src/apps/translations/en.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { enObjects } from './en.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* English (en) — Setup App Translations
@@ -23,6 +24,8 @@ import { enObjects } from './en.objects.generated.js';
2324
*/
2425
export const en: TranslationData = {
2526
objects: enObjects,
27+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
28+
messages: standardUnitMessages('en'),
2629
apps: {
2730
account: {
2831
label: 'Account',

‎packages/platform-objects/src/apps/translations/es-ES.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { esESObjects } from './es-ES.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* Español (es-ES) — Setup App Translations
89
*/
910
export const esES: TranslationData = {
1011
objects: esESObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('es-ES'),
1114
apps: {
1215
account: {
1316
label: 'Cuenta',

‎packages/platform-objects/src/apps/translations/fr.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { frObjects } from './fr.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* Français (fr) — Setup App Translations
89
*/
910
export const fr: TranslationData = {
1011
objects: frObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('fr'),
1114
apps: {
1215
account: {
1316
label: 'Compte',

‎packages/platform-objects/src/apps/translations/ja-JP.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { jaJPObjects } from './ja-JP.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* 日本語 (ja-JP) — Setup App Translations
89
*/
910
export const jaJP: TranslationData = {
1011
objects: jaJPObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('ja-JP'),
1114
apps: {
1215
account: {
1316
label: 'アカウント',

‎packages/platform-objects/src/apps/translations/ko.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { koObjects } from './ko.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* 한국어 (ko) — Setup App Translations
89
*/
910
export const ko: TranslationData = {
1011
objects: koObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('ko'),
1114
apps: {
1215
account: {
1316
label: '계정',

‎packages/platform-objects/src/apps/translations/pt-BR.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import type { TranslationData } from '@objectstack/spec/system';
44
import { ptBRObjects } from './pt-BR.objects.generated.js';
5+
import { standardUnitMessages } from './standard-unit-names.js';
56

67
/**
78
* Português do Brasil (pt-BR) — Setup App Translations
89
*/
910
export const ptBR: TranslationData = {
1011
objects: ptBRObjects,
12+
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
13+
messages: standardUnitMessages('pt-BR'),
1114
apps: {
1215
account: {
1316
label: 'Conta',

0 commit comments

Comments
 (0)