Skip to content

Commit f06f064

Browse files
fix(plugin-grid): a multi-field row conflict lists each field, and a summary column's footer total is formatted as its cells (#33728)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XPEYywMnLBNXfP2Yxf1uAi2)_ domain:ui#2 · os-project-manager · session_01FEkQ5mDVzZmSX2UmJXU7sH Fixes #33557 Fixes #33542 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:① 表格整行保存遇到 409 冲突、且这一行改了多个字段时,冲突对话框按字段逐行列出(列标题、你的修改、当前值),不再把两个整对象打成原始 JSON;只改一个字段的冲突外观不变。② 列表底部合计行里,汇总字段(`Field.summary`)的合计按它在单元格里的画法格式化:声明了币种(`currencyConfig`)就按货币,否则按声明的 `scale` 位小数;都没声明的保持原样。HotCRM 发票列表的「Paid 230,000」因此读作「230,000.00」,与该列单元格一致。 - 为什么改:① 多字段冲突时对话框只给整行草稿对象,用户看到的是 `{"estimate_hours":61,...}`;#33547 已给对话框加了逐字段列表,表格这条路径还没填。② 合计行的格式化按列类型分支,`summary` 类型落到兜底分支,从不读 `scale`;实测 showcase 服务端返回的汇总字段带 `scale: 2`,缺口在 ui。 - 风险与回滚:只动 `@object-ui/plugin-grid` 内部和 `@object-ui/fields` 新增一个导出 `summaryDeclaresCurrency`(单元格本就用它判断汇总字段是否为货币,现在合计行复用同一个判断,不另写格式化器)。货币与否按汇总字段自己的 `currencyConfig`,不看被汇总的源字段类型,这是 spec 的规定,席位已认可。回滚即 revert 本 PR。 - 先看:`ui/packages/plugin-grid/src/useColumnSummary.ts` 的 `summaryValueType` 及 `formatSummaryLabel` 里改为调用它的那一行;`ui/packages/plugin-grid/src/ObjectGrid.tsx` 的 `buildRowConflict` 新增的 `fields`。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/plugin-grid/src/__tests__/footerSummaryFieldScale-33542.test.tsx packages/plugin-grid/src/__tests__/inlineEditConflictFields-33557.test.tsx`,预期 7 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes **#33557, a multi-field grid row conflict lists each field.** `buildRowConflict` in `ObjectGrid.tsx` now fills the conflict's `fields` list (#33547's `ConcurrentUpdateFieldConflict`: field, label, your edit, current value) when a row save changed more than one field, labelled by the column header (`columnHeaderOf`, the label the one-field conflict already uses). The dialog then draws one row per field instead of the two whole-map previews. A one-field conflict is built exactly as before. **#33542, a summary column's footer total is formatted as its cell.** The footer formatter (`formatSummaryLabel` in `useColumnSummary.ts`) chooses its arm by the column type, and a `summary` column fell to the plain default, which never reads `scale`. A new `summaryValueType` routes a summary into the arm the list cell draws the same field with (`FormulaCellRenderer`): `currency` when the summary declares its currency (`summaryDeclaresCurrency`, the cell's own predicate, now exported from `@object-ui/fields`), else `number` when `resolveFieldScale` answers a width, else the plain default as today. No second formatter: the existing currency arm (`formatCurrency`) and number arm (`resolveFieldScale`) do the formatting. **Measured first, as the triage asked.** On a live showcase (`origin/main` d95ddeb, `objectstack dev`), `GET /api/v1/meta/object/showcase_expense_report` serves the summary fields with their scale, e.g. `total_amount`: `{"type":"summary","scale":2,"summaryOperations":{"object":"showcase_expense_line","field":"amount","function":"sum"}}`, no `currencyConfig`. The source `showcase_expense_line.amount` is served as `type: currency` on its own object. So the scale reaches the console and the gap was the footer. ## Tests - `ui/packages/plugin-grid/src/__tests__/inlineEditConflictFields-33557.test.tsx`, new. The real `ObjectGrid`, `data-table` and `ConcurrentUpdateDialog`; writes go through the real `@object-ui/data-objectstack` adapter and `@objectstack/client`, with only `fetch` stubbed by a server answering a stale `If-Match` with the 409 `CONCURRENT_UPDATE` envelope. Cells are edited by click, typing and Enter, then the row's Save is clicked. - Two changed fields + a 409: the dialog lists two rows, `estimate_hours` under "Estimate" (61 / 77) and `owner_note` under "Owner note" (shipped / blocked), and its text holds no `{` or `}`. - CONTROL: one changed field shows no list, names "Estimate" and both values. - `ui/packages/plugin-grid/src/__tests__/footerSummaryFieldScale-33542.test.tsx`, new. The real `ObjectGrid` footer, its field catalogue read from the data source's object schema, under a real `I18nProvider`. - en: a summary with `scale: 2` totals to `Sum: 230,000.00`; zh-CN: `合计:230,000.00`. - en and zh-CN: a summary declaring a `fixed` CNY currency totals exactly as a plain currency column with the same config does (money, not a bare number). - CONTROL: a summary with no scale and no currency keeps the plain total (`Sum: 7`). Ablations at head `eed5643b` (`scripts/ablation-replace.mjs`; the tests import plugin-grid and `@object-ui/fields` from `src/` through the ui vitest alias, so no dist is in the path): <details><summary>#33557: buildRowConflict without the fields list → the multi-field case red, the control green; restored</summary> ```text anchor " fields: keys.map((k) => ({" → " _ablated: keys.map((k) => ({" ablation-replace: ok mutation landed: anchor 1 -> 0, blob 7c4d76f -> 3be11d0556d5 × two changed fields + a 409: two rows, each under its column header with both values, no raw JSON Tests 1 failed | 1 passed (2) ablation-replace: ok restored: blob == HEAD (7c4d76f) and `git diff HEAD` is empty ``` </details> <details><summary>#33542: the summary routing switched off → the four scale and currency cases red, the control green; restored</summary> ```text anchor "column?.type === 'summary' ? summaryValueType(column) : column?.type" → "column?.type === 'summary' && String('ABL').length < 0 ? summaryValueType(column) : column?.type" ablation-replace: ok mutation landed: anchor 1 -> 0, blob 7803efa -> 9ba5b6deda4a × en: a summary with scale 2 totals to two decimals × zh-CN: a summary with scale 2 totals to two decimals, under the zh prefix × en: a summary declaring a fixed currency totals as a plain currency column does × zh-CN: a summary declaring a fixed currency totals as a plain currency column does Tests 4 failed | 1 passed (5) ablation-replace: ok restored: blob == HEAD (7803efa) and `git diff HEAD` is empty ``` </details> ## Acceptance notes - **Money follows the summary's own `currencyConfig`, not its source field's type** (seat accepted this reading). The card asks for the currency format "when its source field is currency". The spec's `currencyConfig` describe says "Absent: dynamic mode, and no currency on a summary", and the list cell (`FormulaCellRenderer`) draws a summary as money only when `summaryDeclaresCurrency` holds. The footer follows the same rule, so footer and cell agree. HotCRM's All Invoices `paid_amount` (`Field.summary`, `scale: 2`, no `currencyConfig`, summing currency `crm_payment.amount`) therefore totals as `230,000.00`, matching its cells; a HotCRM author who wants it drawn as money declares `currencyConfig: { currencyMode: 'fixed', ... }` on the summary. The HotCRM result is read from a fixture of the same shape in the pin above, not from a live HotCRM run. - A `formula` column's footer total also falls to the plain default arm (the cell draws it by `returnType`). Not measured on a real producer here; noted only. ## Verification Local, at head `eed5643b` (rebased on `origin/main` 5604aeb), each exit code captured before any pipe: - `pnpm --dir ui exec vitest run packages/plugin-grid/ --maxWorkers=2` under the verify lock: Test Files 283 passed (283), Tests 2443 passed (2443), the two new files included. - `pnpm --filter @object-ui/fields run type-check` and `pnpm --filter @object-ui/plugin-grid run type-check` (each `tsc --noEmit && tsc -p tsconfig.test.json`, so the new tests are type-checked): exit 0, after building the `@object-ui/plugin-grid^...` closure. - `pnpm check:new-line-citations` (ui, run by hand per `ui/AGENTS.md` #11): 0 new citations. - Derived gate families (`node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`): 39 derived, 39 run, all exit 0; `--ran` reconciles: "39 derived famil(ies) accounted for — 39 run, 0 NOT-MEASURED". <details><summary>the 39 derived families, each COMMAND :: exit N</summary> ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-status-conformance :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` </details> The repo-wide scans, the `test:repo` project and every family CI runs beyond the derived list are CI's (Test UI, Type Check UI and the lint farm). --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5mDVzZmSX2UmJXU7sH)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent baf9f3b commit f06f064

6 files changed

Lines changed: 402 additions & 4 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
'@object-ui/fields': patch
4+
---
5+
6+
fix(plugin-grid): a multi-field row conflict lists each field, and a summary column's footer total is formatted as its cells
7+
8+
Clause-②: yes (widening) — `@object-ui/fields` gains the export `summaryDeclaresCurrency`; nothing is removed or narrowed, and the `@object-ui/plugin-grid` changes are internal.
9+
Metadata-protocol: none
10+
11+
**Row save conflicts in the grid.** A row save that changed several fields and met a newer version (409 `CONCURRENT_UPDATE`) opened the conflict dialog with your edit and the current value printed as two raw JSON objects. The dialog now lists each changed field on its own row, under its column header, with your edit and the current value. A one-field conflict looks as before.
12+
13+
**The list footer total of a roll-up (`summary`) field.** The total ignored the field's `scale`, so a summary with `scale: 2` read "Paid 230,000" beside a currency column's "215,000.00". The footer now formats a summary's total the way the list cell draws the same field: as money when the summary declares its currency (`currencyConfig`), else as a number at its declared `scale`. A summary that declares neither keeps its plain total. Money follows the summary's own `currencyConfig`, not the type of the field it sums, as the spec states and as the cell already draws it.

‎ui/packages/fields/src/index.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ function isPlainObjectValue(value: unknown): value is Record<string, unknown> {
575575
import { resolveFieldCurrency, summaryDeclaresCurrency } from './currency.js';
576576
export { withFollowedParentObject, FOLLOWED_PARENT_OBJECT_KEY } from './currency.js';
577577
import { HomeAmountHint } from './widgets/CurrencyField.js';
578-
export { resolveFieldCurrency };
578+
// `summaryDeclaresCurrency` is the cell's own test for drawing a roll-up as
579+
// money; the grid footer formats the same field's total by it.
580+
export { resolveFieldCurrency, summaryDeclaresCurrency };
579581

580582
/**
581583
* `formatCurrency` lives beside `formatNumberFieldValue` in

‎ui/packages/plugin-grid/src/ObjectGrid.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,8 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
22892289
/**
22902290
* The dialog's payload for one row's 409, in the shape `InlineEditSaveBar`
22912291
* builds for a record's draft: one edited field shows its own before and
2292-
* after, several show the record-level summary.
2292+
* after; several list each field (`fields`) with its column header and both
2293+
* values, so the dialog never prints the draft map as raw JSON.
22932294
*/
22942295
const buildRowConflict = (
22952296
changes: Record<string, any>,
@@ -2315,6 +2316,12 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
23152316
currentValue: current ? Object.fromEntries(keys.map((k) => [k, current[k]])) : undefined,
23162317
currentVersion: err.currentVersion,
23172318
currentRecord: current,
2319+
fields: keys.map((k) => ({
2320+
field: k,
2321+
label: columnHeaderOf(k),
2322+
pendingValue: changes[k],
2323+
currentValue: current ? current[k] : undefined,
2324+
})),
23182325
};
23192326
};
23202327

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
* objectstack#33542 — the footer total of a roll-up (`summary`) column is
11+
* formatted as the list cell draws the same field.
12+
*
13+
* HotCRM's All Invoices footer read "Paid 230,000" for a `Field.summary` with
14+
* `scale: 2`, beside "Open 215,000.00" for a currency field: the footer's
15+
* formatter keyed on the column type, and a `summary` fell to the plain
16+
* default, which never reads `scale`. The served object metadata carries the
17+
* summary's `scale` (measured on the showcase's `showcase_expense_report`).
18+
*
19+
* The cell draws a summary through `FormulaCellRenderer`: as money when the
20+
* summary declares its currency (`currencyConfig`, `summaryDeclaresCurrency`),
21+
* else as a number at its `resolveFieldScale` width. The footer now takes the
22+
* same two arms, the ones a plain `currency` / `number` column takes.
23+
*
24+
* Pinned through the real `ObjectGrid` footer, its field catalogue read from
25+
* the data source's object schema, under a real `I18nProvider` in en and zh-CN:
26+
*
27+
* - a summary with `scale: 2` totals to two decimals;
28+
* - a summary declaring a `fixed` currency totals exactly as a plain currency
29+
* column with the same config does;
30+
* - CONTROL: a summary with no `scale` and no currency keeps today's face.
31+
*/
32+
import { describe, it, expect, vi, beforeAll, beforeEach, afterEach } from 'vitest';
33+
import { render, screen, cleanup, waitFor } from '@testing-library/react';
34+
import '@testing-library/jest-dom';
35+
import React from 'react';
36+
37+
import { ObjectGrid } from '../ObjectGrid';
38+
import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts';
39+
import { installExplainDouble } from './explainDouble';
40+
import { registerAllFields } from '@object-ui/fields';
41+
import { ActionProvider, I18nProvider } from '@object-ui/react';
42+
43+
beforeAll(() => {
44+
registerAllFields();
45+
if (!Element.prototype.scrollIntoView) {
46+
Element.prototype.scrollIntoView = vi.fn() as unknown as Element['scrollIntoView'];
47+
}
48+
});
49+
beforeEach(() => {
50+
__clearRecordCrudVerdictCache();
51+
installExplainDouble();
52+
});
53+
afterEach(() => {
54+
cleanup();
55+
vi.unstubAllGlobals();
56+
});
57+
58+
const OBJECT = 'invoice_33542';
59+
60+
const CNY = { currencyMode: 'fixed', defaultCurrency: 'CNY' } as const;
61+
62+
/** The served field catalogue: three roll-ups and a plain currency field. */
63+
const FIELDS = {
64+
id: { type: 'text', label: 'Id' },
65+
invoice_number: { type: 'text', label: 'Invoice Number' },
66+
paid_amount: {
67+
type: 'summary', label: 'Paid', scale: 2,
68+
summaryOperations: { object: 'payment', field: 'amount', function: 'sum' },
69+
},
70+
paid_cny: {
71+
type: 'summary', label: 'Paid (CNY)', scale: 2, currencyConfig: CNY,
72+
summaryOperations: { object: 'payment', field: 'amount', function: 'sum' },
73+
},
74+
billed_cny: { type: 'currency', label: 'Billed (CNY)', currencyConfig: CNY },
75+
payment_count: {
76+
type: 'summary', label: 'Payments',
77+
summaryOperations: { object: 'payment', function: 'count' },
78+
},
79+
};
80+
81+
/** Totals: 230,000 for every amount column, 7 payments. */
82+
const ROWS = [
83+
{ id: 'i1', invoice_number: 'INV-1', paid_amount: 100000, paid_cny: 100000, billed_cny: 100000, payment_count: 3 },
84+
{ id: 'i2', invoice_number: 'INV-2', paid_amount: 130000, paid_cny: 130000, billed_cny: 130000, payment_count: 4 },
85+
];
86+
87+
function renderGrid(language: 'en' | 'zh-CN') {
88+
const dataSource = {
89+
find: vi.fn(async () => ({ data: ROWS.map((r) => ({ ...r })), total: ROWS.length, hasMore: false, pageSize: 50 })),
90+
getObjectSchema: vi.fn(async (name: string) => ({ name, fields: FIELDS })),
91+
} as any;
92+
const schema: any = {
93+
type: 'object-grid',
94+
objectName: OBJECT,
95+
columns: [
96+
{ field: 'invoice_number', label: 'Invoice Number' },
97+
{ field: 'paid_amount', label: 'Paid', summary: 'sum' },
98+
{ field: 'paid_cny', label: 'Paid (CNY)', summary: 'sum' },
99+
{ field: 'billed_cny', label: 'Billed (CNY)', summary: 'sum' },
100+
{ field: 'payment_count', label: 'Payments', summary: 'sum' },
101+
],
102+
pagination: { pageSize: 50 },
103+
};
104+
return render(
105+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }} persistLanguage={false}>
106+
<ActionProvider>
107+
<ObjectGrid schema={schema} dataSource={dataSource} />
108+
</ActionProvider>
109+
</I18nProvider>,
110+
);
111+
}
112+
113+
/** The footer text of a column once the grid has its field catalogue. */
114+
async function footerOf(field: string): Promise<string> {
115+
const cell = await screen.findByTestId(`summary-${field}`);
116+
return cell.textContent ?? '';
117+
}
118+
119+
describe('a summary column footer total is formatted as its cell (objectstack#33542)', () => {
120+
it('en: a summary with scale 2 totals to two decimals', async () => {
121+
renderGrid('en');
122+
await waitFor(async () => expect(await footerOf('paid_amount')).toContain('Sum: 230,000.00'));
123+
});
124+
125+
it('zh-CN: a summary with scale 2 totals to two decimals, under the zh prefix', async () => {
126+
renderGrid('zh-CN');
127+
await waitFor(async () => expect(await footerOf('paid_amount')).toContain('合计:230,000.00'));
128+
});
129+
130+
it.each(['en', 'zh-CN'] as const)('%s: a summary declaring a fixed currency totals as a plain currency column does', async (language) => {
131+
renderGrid(language);
132+
await waitFor(async () => expect(await footerOf('billed_cny')).toMatch(/230,000\.00/));
133+
const currencyTotal = (await footerOf('billed_cny')).replace(/^.*?:/, '');
134+
// The plain currency column draws money (a currency sign beside the amount).
135+
expect(currencyTotal).not.toBe('230,000.00');
136+
expect((await footerOf('paid_cny')).replace(/^.*?:/, '')).toBe(currencyTotal);
137+
});
138+
139+
it('CONTROL: a summary with no scale and no currency keeps the plain total', async () => {
140+
renderGrid('en');
141+
// The catalogue has landed once the plain currency column draws money.
142+
await waitFor(async () => expect(await footerOf('billed_cny')).toMatch(/230,000\.00/));
143+
expect(await footerOf('payment_count')).toContain('Sum: 7');
144+
expect(await footerOf('payment_count')).not.toContain('7.0');
145+
});
146+
});

0 commit comments

Comments
 (0)