Skip to content

Commit 65fddc8

Browse files
fix(formula): a percent or currency formula is a KPI chip on the record header and formats its browser footer as its return type; lint names all six return types (#35793)
repo:objectstack#7 · os-tesla · session_01L9qibvVRcFWKrfWeG5jzPb <!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoK8YCcS3hkJHvVLxZNeiKG8)_ Fixes #35734 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:记录页顶部的要点条里,声明为百分比或金额结果的公式字段,现在和普通百分比、金额字段一样按数字样式显示;搭建者在解释文字里看到全部六种公式结果类型。对公式字段做合计在搭建时本就被拒绝,这里不把它当成可用写法。 - 为什么做:属于公式字段的显示一致性,替用公式表达比率或金额的搭建者解决要点条与同类字段样式不一致,并让解释文字不漏掉百分比类型。 - 出错会怎样:最坏是这两类公式的要点条字形回到旧样子,存储的数据不受影响,可直接撤回。 - 要你做什么:无。 ## What changes A `formula` field declares a `returnType` from `number`, `text`, `boolean`, `date`, `currency`, `percent`. The spec reads two of them AS a field type: `currency` is "an amount of money … as a currency field declares it" and `percent` is "read and displayed as a `percent` field reads its stored value". The list cell already draws them through the currency and percent cells (`FormulaCellRenderer`); two other faces read only the field's own `type`, and the lint prescription listed five return types. - **Grid footer formatting** (`ui/packages/plugin-grid/src/useColumnSummary.ts`). `formatSummaryLabel` resolves a `formula` column through a new `formulaValueType` before picking its arm, as it already resolves a `summary` column through `summaryValueType`, so a browser-computed footer over a `percent` formula reads `Sum: 75%` rather than `Sum: 0.75`, and over a `currency` formula reads as money; any other formula keeps the plain arm. **This is not a supported authoring shape.** A `sum`, `avg`, `min` or `max` column summary over a `formula` field is refused at authoring by `list-view-summary-field-type-refused` (`columnSummaryRefusal` in `packages/lint/src/validate-list-view-field-refs.ts`, through `aggregateAcceptsDeclaration`): `VALUE_READING_AGGREGATES` in `packages/spec/src/data/aggregate-field-type-compatibility.ts` refuses the virtual `formula` type whatever its `returnType`, because a formula is computed on read and stored in no column, and the whole-set footer query answers `400 INVALID_FIELD`. So this leg formats only an ungrouped, one-page footer the browser computes over a declaration `os validate` refuses. The platform's prescription for totalling a formula stands: make it a stored field of its own, of the formula's `returnType` and carrying the same `expression`, which the engine computes and stores on every write, and summarise that field. The percent arm asks `resolveFieldScale` for the width as a `percent` (the cell hands the percent cell `type: 'percent'` for the same reason) and `percentCellScale(column)` for the storage, so the storage-caller ledger (`ui/scripts/__tests__/percent-storage-callers-11475.test.ts`) stays as it is. - **Record header chip** (`ui/packages/plugin-detail/src/HeaderHighlight.tsx`). `isKpi` reads `formulaReadsAsFieldType(resolvedType, objectDefField?.returnType) ?? resolvedType`, so a `percent` or `currency` formula wears the KPI chip's figure typography, as a field of that type does. The value itself was already drawn correctly (`FormulaCellRenderer`); only the chip class differed. A `number` formula is unchanged. - **Lint prescription** (`packages/lint/src/rule-explanations.ts`). `os explain dimension-virtual-field-refused` now names all six return types. The module imports nothing (its header says why: a published entry the CLI loads on every finding), so the list is written out and `rule-explanations.test.ts` holds it to `FieldSchema.shape.returnType`'s options, the way that file already holds the scan-root list to its constant. Read first, by risk: 1. `ui/packages/plugin-detail/src/HeaderHighlight.tsx`: `formulaReadsAsFieldType` and the `isKpi` block. 2. `ui/packages/plugin-grid/src/useColumnSummary.ts`: `formulaValueType` and the `colType` line in `formatSummaryLabel` (the browser-computed footer formatting only, see above). 3. `packages/lint/src/rule-explanations.test.ts`: the new enum pin. Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-grid/src/useColumnSummary.test.tsx packages/plugin-detail/src/__tests__/HeaderHighlight.formulaReturnType-35734.test.tsx` from the repository root; expect 17 passed, including `Sum: 75%` for the percent formula and `Sum: 0.75` for the number formula control. ## Tests - `ui/packages/plugin-grid/src/useColumnSummary.test.tsx`, new top-level `describe` "useColumnSummary reads a formula by its declared returnType", which drives the hook directly with a formula field's metadata (the authoring door refuses that summary declaration, so these pin the browser formatter only): a percent formula sums to `Sum: 75%` and equals a `percent` field's label; it keeps a declared `scale` (`Sum: 75.0%`) and `max` (equal to a `percent` field with the same `max`); a currency formula with a fixed USD `currencyConfig` sums to `Sum: $1,234.00` under a CNY tenant; CONTROL: a `number` formula sums to `Sum: 0.75`, the same label as a formula declaring no `returnType`. - `ui/packages/plugin-detail/src/__tests__/HeaderHighlight.formulaReturnType-35734.test.tsx` (the strip's pins are one file per subject today, no shared harness file): a percent formula's value span carries `tabular-nums` and the same classes as a `percent` field's; a currency formula's carries it too; CONTROL: a `number` formula's does not. - `packages/lint/src/rule-explanations.test.ts`: the prescription's return-type list equals the spec enum. <details> <summary>Ablations (each fix committed first, mutated through scripts/ablation-replace.mjs, restored to the HEAD blob)</summary> - A1, footer resolution (`colType` line back to `column?.type`): 3 failed, the two percent cases and the currency case; the number control stays green. Restored, `git diff HEAD` empty. A first attempt was refused by the tool before any run, because its replacement text already occurred in the file; the re-run used a unique marker. - A2, percent width face (`resolveFieldScale` handed the formula column as is): 17 passed, no test moved. Expected and stated: the platform's absent `percent` width and `formatPercent`'s parameter default are both 0 today, so the face changes nothing observable; the equality pin against a `percent` field is what goes red if the platform's absent percent width ever moves. - A3, chip resolution (`valueType` back to `resolvedType`): 2 failed, the percent and currency chip cases; the number control stays green. - A4, lint list back to five types: 1 failed, the enum pin. </details> <details> <summary>Test runs</summary> - `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2`: Test Files 222 passed, Tests 9337 passed. - `pnpm --filter @objectstack/lint typecheck`: exit 0, `check:test-typecheck: OK`. - `pnpm exec turbo run type-check --filter=@object-ui/plugin-grid --filter=@object-ui/plugin-detail`: 55 tasks successful, both `type-check` tasks executed (cache miss). - `pnpm --dir ui exec vitest run` over every footer-summary and highlights test of the two packages (28 files) plus `scripts/__tests__/percent-storage-callers-11475.test.ts`: Test Files 29 passed, Tests 300 passed. The two whole packages (682 files) are declared to CI's `Test UI`, which runs them; a local whole-package run was stopped after 20 minutes holding the shared lock. </details> ## Acceptance notes - The chip and the footer formatter resolve `percent` and `currency` and nothing else, on the spec's own wording that those two are read as a field type; `number`, `text`, `boolean` and `date` formulas are unchanged (the number control is pinned in both). - A column summary over a `formula` field stays refused at authoring, whatever its `returnType`; nothing here widens that door, and the stored-field prescription above is the supported way to total a formula. - The record page's summary chip in `DetailView.tsx` picks its currency and percent arms from the field's own `type` too; outside this card's file surface, it is the follow-up card #35798. - The date-returning-formula finding (the footer's date-family test and the chip's wide basis) was withdrawn by the seat: the aggregate door refuses `min` and `max` over a formula, so no supported declaration reaches that footer arm. - No shared exported helper resolves a formula's value type today (`FormulaCellRenderer`, `columnValueType` in plugin-form and `alignsAsNumber` in plugin-grid each spell it); both new helpers are module-local. ## Verification Gates derived by `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` from the branch's own change set and run locally; CI runs the full farm. Readings are in the report comment on the card. --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibvVRcFWKrfWeG5jzPb)_ --- Body refreshed 2026-11-20T08:41Z for the L1 prose delta (amendment 7034399489), head 117c845. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7878cf0 commit 65fddc8

7 files changed

Lines changed: 214 additions & 11 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/lint': patch
3+
'@object-ui/plugin-grid': patch
4+
'@object-ui/plugin-detail': patch
5+
---
6+
7+
fix: a `percent` or `currency` formula is a KPI chip on the record header; the lint prescription names all six return types
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A `formula` field whose `returnType` is `percent` drew percentages in its list cells, and the record header strip drew it without the figure typography a `percent` field's chip has. The strip now reads a formula's declared `returnType` before it picks its face, for the two return types the spec reads as a field type, `percent` and `currency`. Both are KPI chips on the header strip. A formula of any other return type chips as before.
13+
14+
The grid's footer formatting reads the same two return types, so a browser-computed footer over a `percent` formula reads `Sum: 75%` rather than `Sum: 0.75`, and over a `currency` formula reads as money. That is not a supported authoring shape: a `sum`, `avg`, `min` or `max` column summary over a `formula` field is refused at authoring by `list-view-summary-field-type-refused`, whatever its `returnType`, because a formula is computed on read and stored in no column, and the whole-set footer query answers `400 INVALID_FIELD`. The formatting reaches only an ungrouped, one-page footer the browser computes over a declaration `os validate` refuses. To total a formula's value, make it a stored field of its own, of the formula's `returnType` and carrying the same `expression`, which the engine computes and stores on every write, and summarise that field.
15+
16+
`os explain dimension-virtual-field-refused` told the author to make a stored copy "of the formula's `returnType` (`number`, `text`, `boolean`, `date` or `currency`)", which named no type for a `percent` formula. It now lists all six, and a test holds the list to the spec's own `returnType` enum.

‎packages/lint/src/rule-explanations.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import {
1616
FUNCTIONAL_COMPLETENESS_RULES,
1717
MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH,
1818
} from '@objectstack/spec/kernel';
19+
import { FieldSchema } from '@objectstack/spec/data';
1920

2021
import * as indexBarrel from './index.js';
2122
import { RULE_EXPLANATIONS, explainRule } from './rule-explanations.js';
2223
import { CARRIER_ROOTS, CONSUMER_ROOTS, FIELD_NO_CONSUMERS } from './validate-field-consumers.js';
2324
import { NAMESPACE_NO_CUSTOMIZATION_PAIR } from './validate-customization-namespace.js';
25+
import { DIMENSION_VIRTUAL_FIELD_REFUSED } from './validate-dataset-measure-aggregates.js';
2426

2527
const HERE = dirname(fileURLToPath(import.meta.url));
2628

@@ -112,6 +114,18 @@ describe('rule explanations (#22161)', () => {
112114
expect(text).toContain(`to ${max} characters or fewer`);
113115
});
114116

117+
// The module imports nothing, so the formula return types the stored copy
118+
// may take are written out in the text; held here to the spec's own enum,
119+
// so a return type the spec adds cannot be missing from the prescription.
120+
it('the dimension-virtual-field-refused prescription names every formula return type', () => {
121+
const text = explainRule(DIMENSION_VIRTUAL_FIELD_REFUSED)!.paragraphs.join('\n');
122+
const listed = /of the formula's `returnType` \(([^)]*)\)/.exec(text)?.[1];
123+
expect(listed).toBeDefined();
124+
const named = [...listed!.matchAll(/`([a-z_]+)`/g)].map((m) => m[1]).sort();
125+
const members = (FieldSchema.shape.returnType.unwrap().options as readonly string[]).slice().sort();
126+
expect(named).toEqual(members);
127+
});
128+
115129
it('explainRule is an exact-id lookup: no prefix, case or prototype match', () => {
116130
expect(explainRule(FIELD_NO_CONSUMERS)?.rule).toBe(FIELD_NO_CONSUMERS);
117131
expect(explainRule('field-no-consumer')).toBeUndefined();

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,8 +2734,9 @@ const DIMENSION_VIRTUAL_FIELD_REFUSED_EXPLANATION: RuleExplanation = {
27342734
'Before those refusals the group key reached the driver as a column that does not exist, or an ' +
27352735
'engine that aggregates in memory put every row into one null group while the answer looked served.',
27362736
'Denormalise the value: make it a stored field of its own on the object, of the formula\'s ' +
2737-
'`returnType` (`number`, `text`, `boolean`, `date` or `currency`) and carrying the same `expression`, ' +
2738-
'which the engine computes and stores on every write, and point the dimension at that stored field. ' +
2737+
'`returnType` (`number`, `text`, `boolean`, `date`, `currency` or `percent`) and carrying the same ' +
2738+
'`expression`, which the engine computes and stores on every write, and point the dimension at that ' +
2739+
'stored field. ' +
27392740
'This rule makes the same ' +
27402741
'refusal where the author is standing. A dotted path is judged on the leaf\'s own declaration.',
27412742
ANALYTICS_MEMBER_WALK,

‎ui/packages/plugin-detail/src/HeaderHighlight.tsx‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ import { hasCellValue } from './emptiness';
3535
import { useDefaultRecordPage } from './defaultRecordPage';
3636
import { dropFieldPredicateHidden, lazyPredicateRecord } from './fieldPredicateVisibility';
3737

38+
/**
39+
* The field type a `formula` reads as, when its declared `returnType` is one
40+
* the spec reads AS a field type: `currency` ("an amount of money … as a
41+
* currency field declares it") and `percent` ("read and displayed as a
42+
* `percent` field reads its stored value"). `undefined` for any other field
43+
* or return type.
44+
*/
45+
function formulaReadsAsFieldType(type: string | undefined, returnType: unknown): 'currency' | 'percent' | undefined {
46+
if (type !== 'formula') return undefined;
47+
return returnType === 'currency' || returnType === 'percent' ? returnType : undefined;
48+
}
49+
3850
export interface HeaderHighlightProps {
3951
fields: HighlightField[];
4052
data?: any;
@@ -256,12 +268,17 @@ export const HeaderHighlight: React.FC<HeaderHighlightProps> = ({
256268
// coerceToSafeValue() so even object/array data is safe (no error #310).
257269
const CellRenderer = getCellRenderer(drawnType);
258270

271+
// A `formula` declaring a return type the spec reads AS a field
272+
// type (`currency`, `percent`) is a figure of that type, drawn by
273+
// that type's cell, so it is a KPI chip as that field is. Every
274+
// other formula keeps its own type here.
275+
const valueType = formulaReadsAsFieldType(resolvedType, objectDefField?.returnType) ?? resolvedType;
259276
const isKpi =
260-
resolvedType === 'number' ||
261-
resolvedType === 'integer' ||
262-
resolvedType === 'currency' ||
263-
resolvedType === 'percent' ||
264-
resolvedType === 'decimal';
277+
valueType === 'number' ||
278+
valueType === 'integer' ||
279+
valueType === 'currency' ||
280+
valueType === 'percent' ||
281+
valueType === 'decimal';
265282
// Two independent reasons a chip needs the wide basis, kept
266283
// separate because only one of them is a shared table:
267284
// 1. long-text DISPLAY types, whose value simply does not fit a
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* A `formula` whose declared `returnType` the spec reads AS a field type
11+
* (`percent`, `currency`) is a KPI chip on the highlights strip, as a field of
12+
* that type is: its value carries the strip's figure typography. A formula of
13+
* any other return type keeps the face it had (CONTROL: `number`).
14+
*/
15+
import { describe, it, expect, afterEach } from 'vitest';
16+
import { render, screen, cleanup } from '@testing-library/react';
17+
import * as React from 'react';
18+
import { HeaderHighlight } from '../HeaderHighlight';
19+
20+
afterEach(cleanup);
21+
22+
const objectSchema = {
23+
fields: {
24+
win_rate: { type: 'percent', label: 'Win Rate' },
25+
margin_pct: { type: 'formula', label: 'Margin', returnType: 'percent', expression: 'record.profit / record.revenue' },
26+
net_amount: { type: 'formula', label: 'Net', returnType: 'currency', expression: 'record.revenue - record.cost' },
27+
units_left: { type: 'formula', label: 'Units Left', returnType: 'number', expression: 'record.stock - record.sold' },
28+
},
29+
};
30+
31+
function renderStrip() {
32+
render(
33+
<HeaderHighlight
34+
fields={
35+
[
36+
{ name: 'win_rate', label: 'Win Rate' },
37+
{ name: 'margin_pct', label: 'Margin' },
38+
{ name: 'net_amount', label: 'Net' },
39+
{ name: 'units_left', label: 'Units Left' },
40+
] as any
41+
}
42+
data={{ win_rate: 0.4, margin_pct: 0.25, net_amount: 1200, units_left: 7 }}
43+
objectSchema={objectSchema}
44+
/>,
45+
);
46+
}
47+
48+
/** The value span of the chip captioned `label`. */
49+
const valueOf = (label: string) => {
50+
const span = (screen.getByText(label).closest('div.group') as HTMLElement).querySelector('span.truncate');
51+
expect(span, `a value span under "${label}"`).not.toBeNull();
52+
return span as HTMLElement;
53+
};
54+
55+
describe('the highlights strip reads a formula by its declared returnType (objectstack#35734)', () => {
56+
it('a percent field is a KPI chip (the reference)', () => {
57+
renderStrip();
58+
expect(valueOf('Win Rate').className).toMatch(/\btabular-nums\b/);
59+
});
60+
61+
it('a percent-returning formula is a KPI chip, as a percent field is', () => {
62+
renderStrip();
63+
expect(valueOf('Margin').className).toMatch(/\btabular-nums\b/);
64+
expect(valueOf('Margin').className).toBe(valueOf('Win Rate').className);
65+
expect(valueOf('Margin').textContent).toContain('25%');
66+
});
67+
68+
it('a currency-returning formula is a KPI chip too', () => {
69+
renderStrip();
70+
expect(valueOf('Net').className).toMatch(/\btabular-nums\b/);
71+
});
72+
73+
it('CONTROL: a number-returning formula keeps the face it had', () => {
74+
renderStrip();
75+
expect(valueOf('Units Left').className).not.toMatch(/\btabular-nums\b/);
76+
});
77+
});

‎ui/packages/plugin-grid/src/useColumnSummary.test.tsx‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,46 @@ describe('useColumnSummary formatting stays with the numeric family', () => {
148148
expect(result.current.summaries.get('amount')?.label).toMatch(/\$|US\$/);
149149
});
150150
});
151+
152+
/**
153+
* A `formula` column's footer reads its declared `returnType` when the spec
154+
* reads that return type AS a field type (`percent`, `currency`), so the total
155+
* reads in the unit of the cells above it. Every other formula keeps the plain
156+
* arm (CONTROL: `number`).
157+
*/
158+
describe('useColumnSummary reads a formula by its declared returnType (objectstack#35734)', () => {
159+
const RATES = [{ rate: 0.25 }, { rate: 0.5 }];
160+
const sumOf = (meta: Record<string, any>) =>
161+
renderHook(() => useColumnSummary([{ field: 'rate', summary: 'sum' }] as any[], RATES, meta), {
162+
wrapper: wrapper('USD'),
163+
}).result.current.summaries.get('rate')?.label;
164+
165+
it('a percent-returning formula totals as a percentage, as a percent field does', () => {
166+
const formula = sumOf({ rate: { type: 'formula', returnType: 'percent' } });
167+
expect(formula).toBe('Sum: 75%');
168+
expect(formula).toBe(sumOf({ rate: { type: 'percent' } }));
169+
});
170+
171+
it('a percent-returning formula keeps its declared width and storage', () => {
172+
expect(sumOf({ rate: { type: 'formula', returnType: 'percent', scale: 1 } })).toBe('Sum: 75.0%');
173+
// `max` above 1 declares percentage points: 0.75 is under one percent.
174+
expect(sumOf({ rate: { type: 'formula', returnType: 'percent', max: 100 } })).toBe(
175+
sumOf({ rate: { type: 'percent', max: 100 } }),
176+
);
177+
});
178+
179+
it('a currency-returning formula totals as money in its declared currency', () => {
180+
const { result } = renderHook(
181+
() => useColumnSummary([{ field: 'net', summary: 'sum' }] as any[], [{ net: 1000 }, { net: 234 }], {
182+
net: { type: 'formula', returnType: 'currency', currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'USD' } },
183+
}),
184+
{ wrapper: wrapper('CNY') },
185+
);
186+
expect(result.current.summaries.get('net')?.label).toBe('Sum: $1,234.00');
187+
});
188+
189+
it('CONTROL: a number-returning formula totals as it did, a plain number', () => {
190+
expect(sumOf({ rate: { type: 'formula', returnType: 'number' } })).toBe('Sum: 0.75');
191+
expect(sumOf({ rate: { type: 'formula', returnType: 'number' } })).toBe(sumOf({ rate: { type: 'formula' } }));
192+
});
193+
});

‎ui/packages/plugin-grid/src/useColumnSummary.ts‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,31 @@ function summaryValueType(column: { currencyConfig?: unknown; scale?: number | n
376376
return resolveFieldScale(column) === undefined ? 'summary' : 'number';
377377
}
378378

379+
/**
380+
* The return types the spec reads AS a field type: `currency` is "an amount of
381+
* money … as a currency field declares it", and `percent` is "read and
382+
* displayed as a `percent` field reads its stored value". The list cell draws
383+
* them through the currency and percent cells (`FormulaCellRenderer`).
384+
*/
385+
const FIELD_TYPED_FORMULA_RETURNS: ReadonlySet<string> = new Set(['currency', 'percent']);
386+
387+
/**
388+
* The arm a `formula` column's total is formatted by: its declared
389+
* `returnType` when the spec reads that return type as a field type, so a
390+
* percent-returning formula's total reads as a percentage under cells that
391+
* read as percentages, and a currency-returning one's as money. Any other
392+
* formula keeps the plain arm it always took.
393+
*/
394+
function formulaValueType(column: { returnType?: unknown }): string {
395+
const declared = column.returnType;
396+
return typeof declared === 'string' && FIELD_TYPED_FORMULA_RETURNS.has(declared) ? declared : 'formula';
397+
}
398+
379399
function formatSummaryLabel(
380400
type: string,
381401
value: number | null,
382402
t: SummaryTranslate,
383-
column: { type?: string; currency?: string; defaultCurrency?: string; currencyConfig?: { defaultCurrency?: string }; precision?: number | null; scale?: number | null; max?: number } | undefined,
403+
column: { type?: string; returnType?: string; currency?: string; defaultCurrency?: string; currencyConfig?: { defaultCurrency?: string }; precision?: number | null; scale?: number | null; max?: number } | undefined,
384404
tenantDefault: string | undefined,
385405
// The BCP-47 tag from `useDisplayLocale()` — tenant locale, then UI
386406
// language, then a concrete `'en'`, never `undefined`.
@@ -419,7 +439,9 @@ function formatSummaryLabel(
419439
return join(value.toLocaleString(displayLocale));
420440
}
421441

422-
const colType = column?.type === 'summary' ? summaryValueType(column) : column?.type;
442+
const colType = column?.type === 'summary'
443+
? summaryValueType(column)
444+
: column?.type === 'formula' ? formulaValueType(column) : column?.type;
423445
let formatted: string;
424446
if (colType === 'currency') {
425447
// objectui#10221 — a currency's decimal places are the currency's, not a
@@ -500,7 +522,17 @@ function formatSummaryLabel(
500522
// over the field's `max`), the answer the cell above reads. The shared
501523
// scaling used to guess from the magnitude, so a fraction-stored column
502524
// summing to `1` (100%) read `Sum: 1%` under cells reading the same rows.
503-
const decimals = resolveFieldScale(column);
525+
//
526+
// A percent-returning `formula` reaches this arm too, and is read as the
527+
// `percent` field it reads like, as the list cell hands it on
528+
// (`FormulaCellRenderer`): `resolveFieldScale` keys its absent-`scale` row
529+
// on the type, and a formula's own type has none, so an undeclared width
530+
// takes the platform's percent width rather than `formatPercent`'s own
531+
// parameter default. Every column that reaches this arm is a percent, so
532+
// the type below changes for the formula alone. Its storage is read off
533+
// the column as is: `percentCellScale` reads the declared `max`, and the
534+
// formula declares it as a percent field does.
535+
const decimals = resolveFieldScale({ ...column, type: 'percent' });
504536
formatted = formatPercent(value, percentCellScale(column), decimals, displayLocale);
505537
} else if (colType === 'number') {
506538
// objectstack#19628, ruled A′ and carried to this footer by objectui#9843:
@@ -531,7 +563,7 @@ function formatSummaryLabel(
531563
}
532564

533565
/** The `objectSchema.fields` slice the footer formats with. */
534-
type SummaryFieldMetadata = Record<string, { type?: string; format?: string | null; widget?: string | null; currency?: string; defaultCurrency?: string; currencyConfig?: CurrencyConfig; precision?: number | null; scale?: number | null; max?: number }>;
566+
type SummaryFieldMetadata = Record<string, { type?: string; returnType?: string; format?: string | null; widget?: string | null; currency?: string; defaultCurrency?: string; currencyConfig?: CurrencyConfig; precision?: number | null; scale?: number | null; max?: number }>;
535567

536568
/**
537569
* Which rows the footer's figures describe (objectui#12081 item 3).
@@ -724,6 +756,9 @@ export function useScopedColumnSummary(
724756
// objectui#11475 — a percent field's declared `max`, its STORAGE
725757
// statement (`percentScaleOf`: a fraction unless `max` is above 1).
726758
max: meta?.max,
759+
// A `formula`'s declared value type: a `percent` or `currency` one is
760+
// totalled in that type's arm (`formulaValueType`).
761+
returnType: meta?.returnType,
727762
};
728763

729764
// The widest decimal count among the numeric values this aggregation

0 commit comments

Comments
 (0)