Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/35490-quantity-unit-display.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@objectstack/spec': minor
'@objectstack/platform-objects': patch
'@object-ui/core': patch
'@object-ui/fields': patch
'@object-ui/types': minor
'@object-ui/components': patch
'@object-ui/plugin-grid': patch
'@object-ui/plugin-list': patch
'@object-ui/plugin-detail': patch
---

feat(fields): a quantity displays with its unit's label and display decimal places in grid, form and detail (ADR-0158 R1 display)

Clause-②: yes (widening)
Metadata-protocol: added

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.

- 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.
- 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.
- 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.
- One resolver (`resolveQuantityUnit` in `@object-ui/core`) and one formatter (`formatQuantity` in `@object-ui/fields`) serve every face.
- `@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.
- 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`).
30 changes: 30 additions & 0 deletions content/docs/frontend/fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ ObjectUI comes with built-in support for the standard [ObjectStack Protocol](htt
| `user` | Person picker — searches the `sys_user` object (a lookup specialized to users) |
| `owner` | Record owner — a `user` field, typically read-only and stamped with the current user |

## Quantities with a unit

A `number` field that declares `unitConfig` is a quantity, and every face draws it with its unit: grid and
list cells, the record page, the quick-look panel, related lists, and the form (read-only, and beside the
edited box). A record-mode quantity, for example, declares
`unitConfig: { unitMode: 'record', unitField: 'unit_code' }` on its `number` field.

- **Which unit.** `unitMode: 'fixed'` shows its one `unit`. `unitMode: 'record'` shows the code the row's
`unitField` holds; the list, grid and related-list reads fetch that field, and the row's
`organization_id`, even when no column shows them. A `text` field declaring `unitMode: 'code'` shows the
code's label.
- **Choosing a unit.** In a form, a `text` field declaring `unitMode: 'code'`, and the `unitField` a
`record` quantity on the same form points at, are a searchable unit picker, never a typed box: the
organization's non-retired units, then the standard codes, each by name and limited to the declared
`unitDimension`. The picker stores the code. Read-only, the field shows the unit's name.
- **Which label.** A standard code (`KGM`, `H87`, …) shows the platform's name for it in the reader's
language, served by the platform's i18n service (`messages.standardUnit<CODE>`), falling back to the
English name in `@objectstack/spec` (`STANDARD_UNIT_NAMES`). An organization's own code shows its
`sys_unit` label.
- **How many decimal places.** A standard code takes the organization's `sys_standard_unit_setting` row,
and an organization code its `sys_unit.decimal_places`, always the row of the record's own
organization. The field's `scale` is the ceiling. The number is drawn at that fixed width, rounded half
away from zero (`1.5` beside a unit of 0 places reads `2`). With no unit setting, the field's own width
applies. Only the display rounds: the stored value, totals, exports and the API keep the exact value.
- **The bare code.** A retired organization unit, or one whose row the reader may not read, shows its code
with no label.

The unit rows are read through the data source of the surrounding `SchemaRendererProvider`, once per
session.

## How the Console draws field metadata

What a field's metadata makes the Console draw (number inputs, polymorphic record pointers,
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* العربية (ar) — Setup App Translations
*/
export const ar: TranslationData = {
objects: arObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('ar'),
apps: {
account: {
label: 'الحساب',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* Deutsch (de) — Setup App Translations
*/
export const de: TranslationData = {
objects: deObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('de'),
apps: {
account: {
label: 'Konto',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

/**
* English (en) — Setup App Translations
Expand All @@ -23,6 +24,8 @@ import { enObjects } from './en.objects.generated.js';
*/
export const en: TranslationData = {
objects: enObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('en'),
apps: {
account: {
label: 'Account',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/es-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* Español (es-ES) — Setup App Translations
*/
export const esES: TranslationData = {
objects: esESObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('es-ES'),
apps: {
account: {
label: 'Cuenta',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* Français (fr) — Setup App Translations
*/
export const fr: TranslationData = {
objects: frObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('fr'),
apps: {
account: {
label: 'Compte',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/ja-JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* 日本語 (ja-JP) — Setup App Translations
*/
export const jaJP: TranslationData = {
objects: jaJPObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('ja-JP'),
apps: {
account: {
label: 'アカウント',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* 한국어 (ko) — Setup App Translations
*/
export const ko: TranslationData = {
objects: koObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('ko'),
apps: {
account: {
label: '계정',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

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

/**
* Português do Brasil (pt-BR) — Setup App Translations
*/
export const ptBR: TranslationData = {
objects: ptBRObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('pt-BR'),
apps: {
account: {
label: 'Conta',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-objects/src/apps/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import type { TranslationData } from '@objectstack/spec/system';
import { ruObjects } from './ru.objects.generated.js';
import { standardUnitMessages } from './standard-unit-names.js';

/**
* Русский (ru) — Setup App Translations
*/
export const ru: TranslationData = {
objects: ruObjects,
// ADR-0158 L2 (2A): each standard unit code's name (`standard-unit-names.ts`).
messages: standardUnitMessages('ru'),
apps: {
account: {
label: 'Учётная запись',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { describe, it, expect } from 'vitest';
import { STANDARD_UNITS, STANDARD_UNIT_NAMES } from '@objectstack/spec/data';
import { STANDARD_UNIT_NAME_TRANSLATIONS, standardUnitMessageKey, standardUnitMessages } from './standard-unit-names';
import { en, zhCN, jaJP, esES, zhHant, ar, fr, ptBR, ru, de, ko } from './index';

/**
* ADR-0158 L2 (2A): the platform serves a name for every standard unit code in
* every bundle locale (objectstack#35490), as `messages.standardUnit<CODE>`.
*/
const BUNDLES = { en, 'zh-CN': zhCN, 'ja-JP': jaJP, 'es-ES': esES, 'zh-Hant': zhHant, ar, fr, 'pt-BR': ptBR, ru, de, ko };
const codes = Object.keys(STANDARD_UNITS);

describe('standard unit names in the platform bundles (ADR-0158 L2, objectstack#35490)', () => {
it('translates exactly the codes of STANDARD_UNITS in every non-English locale', () => {
for (const [locale, names] of Object.entries(STANDARD_UNIT_NAME_TRANSLATIONS)) {
expect(Object.keys(names), locale).toEqual(codes);
for (const [code, name] of Object.entries(names)) expect(name.trim(), `${locale} ${code}`).not.toBe('');
}
expect(Object.keys(STANDARD_UNIT_NAME_TRANSLATIONS).sort()).toEqual(Object.keys(BUNDLES).filter((l) => l !== 'en').sort());
});

it('serves every code in every bundle, under a single-segment message key', () => {
for (const [locale, bundle] of Object.entries(BUNDLES)) {
const messages = bundle.messages ?? {};
for (const code of codes) {
const key = standardUnitMessageKey(code);
expect(key).not.toContain('.');
expect(messages[key], `${locale} ${code}`).toBeTruthy();
}
}
});

it('copies the English bundle from the spec base, never re-typed', () => {
for (const code of codes) expect(en.messages?.[standardUnitMessageKey(code)]).toBe(STANDARD_UNIT_NAMES[code]);
expect(standardUnitMessages('zh-CN')[standardUnitMessageKey('KGM')]).toBe('千克');
});
});
Loading
Loading