Skip to content

Commit 77edd2a

Browse files
fix(plugin-grid): phone card amount slot takes a formula or summary that draws as money (#38100)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoJgGMcVYe3tSvxAWdknWFST)_ Fixes #37890 repo:objectstack#3 · os-tesla · session_01L9qibvqGhhENZcAuiMxqA7 Clause-②: no Metadata-protocol: none ## 维护者速读 - 手机上看订单行、报价行这类明细列表时,卡片右下角的金额现在显示这一行的总额,不再错显示单价;电脑上的表格不变。 - 属于手机端列表卡片的体验线,替 HotCRM 等有明细行的应用解决金额读错的问题。 - 只改卡片挑哪一列当金额,数据和接口都不变;若挑错,最多是卡片上金额位置显示另一列,可以直接撤回。 - 无 ## What changes - `ui/packages/plugin-grid/src/ObjectGrid.tsx`, `buildMobileCardRenderer`: the amount slot now takes the first shown body column whose value draws as money. That is a `currency` column, or a `formula` / `summary` column for which `resolveFormulaValueType(fieldDef, number)` (the exported `@object-ui/fields` rule the formula cell draws by) answers `currency`: a formula declaring `returnType: 'currency'`, or a summary declaring its currency (`currencyConfig`). The slot is still chosen once for the list, so every card keeps one shape. - Unchanged: a masked column is not promoted; a view that presents the field as another type (column `type`) keeps it a plain value; a number-returning formula is not an amount; view order still picks among several money columns; desktop table untouched. - No new export (seat ruling: option A). `patch` changeset for `@object-ui/plugin-grid`. ## Why On a phone, an order line (2 × 6,000.00, 10% off) showed its unit price 6,000.00 in the amount slot; the line total 10,800.00 is a formula returning currency, which the slot never considered. Reordering columns did not help: the total moved into the subtitle. ## Tests `ui/packages/plugin-grid/src/__tests__/phoneCardAmount-34615.test.tsx`, a new top-level `describe` in the existing harness (390 px): - currency formula shown before the unit price → amount `CN¥10,800.00`, subtitle `2 · CN¥6,000.00`; - currency formula as the only money column → amount `CN¥10,800.00`; - summary declaring its currency → amount `CN¥777.00`; - unit price shown first stays the amount (view order unchanged); - CONTROL: number-returning formula → no amount line; - CONTROL: the currency formula presented as `type: 'text'` → no amount line. <details><summary>Readings (head f800825 = b4dd4f2 + merge of origin/main 815e882..f72f335)</summary> - New describe at b4dd4f2: `Tests 11 passed (11)` for the harness file. - Ablation on the committed fix (ObjectGrid.tsx restored from base 815e882, tree only, then restored from HEAD; `drawsAsMoney` count 0 → 2 on disk): `Tests 3 failed | 8 passed (11)`. The three red are exactly the predicted RED directions; both CONTROLs and all five #34615 cases stay green. - After merging origin/main (which brought #37929, also in plugin-grid) and rebuilding the closure (`turbo run build --filter='@object-ui/plugin-grid^...'`, 57/57): `pnpm --filter @object-ui/plugin-grid type-check` exit 0; `pnpm --dir ui exec vitest run packages/plugin-grid/`: `Test Files 319 passed (319)`, `Tests 2805 passed (2805)`. - eslint on the two changed files: 0 errors (155 warnings, none on the changed hunk). - `dispatch-gates --ran` at b4dd4f2: 39 derived, 39 run, all exit 0, 0 NOT MEASURED, 0 unrun. </details> ## Acceptance notes - Premise measured on origin/main 815e882 before writing (390 px probe, readings on the card's pre-claim report): unit price first → slot `CN¥6,000.00`; total first → slot still `CN¥6,000.00`, total in subtitle; formula-only or summary-only → no slot, though the cell already drew currency. - `#37929` and `#37924` also touch `ObjectGrid.tsx`, in hunks far from this one; whichever lands later merges main. ## Verification Read first (by risk): 1. `ObjectGrid.tsx`: `drawsAsMoney` and the `amountCol` line under it. 2. The new `describe` in `phoneCardAmount-34615.test.tsx`, especially the two CONTROL cases. Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-grid/src/__tests__/phoneCardAmount-34615.test.tsx` shows 11 passing; replace `drawsAsMoney(c)` with `c.type === 'currency'` and the same command shows 3 failing. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the two changed files: 0 errors) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibvqGhhENZcAuiMxqA7)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent bbe4258 commit 77edd2a

3 files changed

Lines changed: 130 additions & 5 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
Phone list cards now put a line's total in the amount slot. The slot used to take only a column whose field type is literally `currency`, so on an order-line list the card showed the unit price (6,000.00) where the line total (10,800.00) belonged, and with no plain currency column there was no amount at all. A column now counts as money when its cell draws a number as currency: a `currency` field, a formula declaring `returnType: 'currency'`, or a summary declaring its currency (`currencyConfig`). The first such column the view shows is the amount, as before. A view that presents the field as another type, a masked column and a number-returning formula are still not promoted. Nothing changes on desktop.

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { SchemaRenderer, isPermissionError, useDataScope, useNavigationOverlay,
3232
// what stops a seventh site picking a convention of its own.
3333
import { resolveGridCellRendering } from './cellRendererResolution';
3434
import { isMaskedGridColumn } from './maskedColumn';
35-
import { formatCurrency, formatDate, getBadgeColorClasses, getBadgeHexAppearance, FieldEditWidget, hasFieldEditWidget, hasInCellPanelEditWidget, DISCRETE_EDIT_TYPES, coerceToSafeValue, MaskedCellRenderer, withKnownObjects, RICH_TEXT_FIELD_TYPES } from '@object-ui/fields';
35+
import { formatCurrency, formatDate, getBadgeColorClasses, getBadgeHexAppearance, FieldEditWidget, hasFieldEditWidget, hasInCellPanelEditWidget, DISCRETE_EDIT_TYPES, coerceToSafeValue, MaskedCellRenderer, withKnownObjects, RICH_TEXT_FIELD_TYPES, resolveFormulaValueType } from '@object-ui/fields';
3636
import { useLocalization, useDisplayLocale } from '@object-ui/i18n';
3737
// Two resolvers, two vocabularies — the repo spells the distinction into the
3838
// NAMES (objectui#4167). `resolveInlineI18nLabel` is the spec's own
@@ -4429,14 +4429,29 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44294429
const statusKey = detectStatusField(objectSchema);
44304430
const statusCol = statusKey !== null ? bodyColumns.find((c) => c.accessorKey === statusKey) : undefined;
44314431
// objectstack#34615 — the card's AMOUNT is the first shown body column whose
4432-
// field type is `currency` (the column draft's resolved type, so a view
4433-
// that presents the field as another type keeps it a plain value). It
4434-
// never shares the subtitle's width: it gets a line of its own under the
4432+
// value draws as money (the column draft's resolved type, so a view that
4433+
// presents the field as another type keeps it a plain value). It never
4434+
// shares the subtitle's width: it gets a line of its own under the
44354435
// subtitle, drawn whole at the right edge, and the status chip moves to
44364436
// that line's left so the two never compete for one row. A masked amount
44374437
// is not promoted; it stays a subtitle candidate, which skips it.
4438+
//
4439+
// objectstack#37890 — money is a `currency` column, and also a `formula`
4440+
// or `summary` column whose cell draws a number as currency: a formula
4441+
// declaring `returnType: 'currency'` (an order line's total) or a summary
4442+
// declaring its currency. That is asked of `resolveFormulaValueType`, the
4443+
// rule the formula cell draws by, so the slot and the cell cannot disagree.
4444+
// The slot is chosen once for the whole list (every card keeps one shape),
4445+
// so the rule is asked how the column draws a NUMBER, not how one row's
4446+
// value happens to draw: only a numeric value is an amount.
4447+
const drawsAsMoney = (c: ObjectGridColumnDraft): boolean => {
4448+
if (c.type === 'currency') return true;
4449+
if (c.type !== 'formula' && c.type !== 'summary') return false;
4450+
const def = objectFields?.[c.accessorKey];
4451+
return def?.type === c.type && resolveFormulaValueType(def, 0) === 'currency';
4452+
};
44384453
const amountCol = bodyColumns.find(
4439-
(c) => c !== statusCol && c.type === 'currency' && !isMaskedCardColumn(c.accessorKey),
4454+
(c) => c !== statusCol && drawsAsMoney(c) && !isMaskedCardColumn(c.accessorKey),
44404455
);
44414456
const subtitleColumns = bodyColumns
44424457
.filter((c) => c !== statusCol && c !== amountCol && !titleReads.has(c.accessorKey))

‎ui/packages/plugin-grid/src/__tests__/phoneCardAmount-34615.test.tsx‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,105 @@ describe('the phone list card draws its amount whole, on a line of its own (obje
155155
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('Wayne Enterprises · Sign by 11-27');
156156
});
157157
});
158+
159+
/**
160+
* objectstack#37890 — the amount slot takes any column whose value draws as
161+
* money, not only a literal `currency` column: a formula declaring
162+
* `returnType: 'currency'` and a summary declaring its currency are amounts
163+
* too, so an order line's card shows the line total rather than the unit
164+
* price. Measured on the base tree with this fixture: with `unit_price` shown
165+
* first the slot read the unit price; with `total_price` first it still read
166+
* the unit price and the total fell into the subtitle; with no plain currency
167+
* column there was no slot at all.
168+
*
169+
* ── Directions on the base tree (measured before the fix) ────────────────
170+
* formula total shown before the unit price → slot holds the total RED
171+
* formula total as the only money column → slot holds the total RED
172+
* currency summary as the only money column → slot holds it RED
173+
* control: a view that presents the formula as text → not promoted GREEN
174+
* control: a number-returning formula → not promoted GREEN
175+
*/
176+
describe('the phone card amount slot takes a formula or summary that draws as money (objectstack#37890)', () => {
177+
const LINE_OBJECT = 'order_line_37890';
178+
const LINE_FIELDS = {
179+
id: { type: 'text' },
180+
name: { type: 'text', label: 'Product' },
181+
quantity: { type: 'number', label: 'Quantity' },
182+
unit_price: { type: 'currency', label: 'Unit Price' },
183+
total_price: {
184+
type: 'formula',
185+
label: 'Total',
186+
returnType: 'currency',
187+
expression: 'record.quantity * record.unit_price * (1 - record.discount)',
188+
},
189+
line_weight: { type: 'formula', label: 'Weight', returnType: 'number', expression: 'record.quantity * 3' },
190+
lines_total: {
191+
type: 'summary',
192+
label: 'Lines Total',
193+
summaryOperations: { object: 'order_item', field: 'amount', function: 'sum' },
194+
currencyConfig: { currencyMode: 'dynamic' },
195+
},
196+
};
197+
const LINE_ROWS = [
198+
{ id: 'l1', name: 'Admin Training Workshop', quantity: 2, unit_price: 6000, total_price: 10800, line_weight: 6, lines_total: 777 },
199+
];
200+
201+
async function lineCard(columns: unknown[]) {
202+
setWidth(390);
203+
const dataSource = {
204+
find: vi.fn(async () => ({ data: LINE_ROWS, total: LINE_ROWS.length, hasMore: false, pageSize: 50 })),
205+
getObjectSchema: async (name: string) => ({ name, nameField: 'name', fields: structuredClone(LINE_FIELDS) }),
206+
} as never;
207+
render(
208+
<LocalizationProvider value={{ currency: 'CNY', locale: 'en' }}>
209+
<ActionProvider>
210+
<SchemaRendererProvider dataSource={dataSource}>
211+
<ObjectGrid
212+
schema={{ type: 'object-grid', objectName: LINE_OBJECT, columns, pagination: { pageSize: 50 } } as never}
213+
dataSource={dataSource}
214+
/>
215+
</SchemaRendererProvider>
216+
</ActionProvider>
217+
</LocalizationProvider>,
218+
);
219+
// The quantity column draws through the number cell once the field defs
220+
// arrive; the money cells below read the same defs.
221+
await waitFor(() => expect(screen.getByTestId('grid-card-subtitle').textContent).toMatch(/^2\b/));
222+
expect(document.querySelector('table'), 'the card layout, not the table').toBeNull();
223+
return cardOf('Admin Training Workshop');
224+
}
225+
const fields = (...names: string[]) => names.map((field) => ({ field }));
226+
227+
it('takes a currency formula shown before the unit price: the card reads the line total', async () => {
228+
const card = await lineCard(fields('name', 'quantity', 'total_price', 'unit_price'));
229+
expect(within(card).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
230+
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('2 · CN¥6,000.00');
231+
});
232+
233+
it('takes a currency formula that is the only money column', async () => {
234+
const card = await lineCard(fields('name', 'quantity', 'total_price'));
235+
expect(within(card).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
236+
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('2');
237+
});
238+
239+
it('takes a summary that declares its currency', async () => {
240+
const card = await lineCard(fields('name', 'quantity', 'lines_total'));
241+
expect(within(card).getByTestId('grid-card-amount').textContent).toBe('CN¥777.00');
242+
});
243+
244+
it('keeps the first money column in view order: a unit price shown first stays the amount', async () => {
245+
const card = await lineCard(fields('name', 'quantity', 'unit_price', 'total_price'));
246+
expect(within(card).getByTestId('grid-card-amount').textContent).toBe('CN¥6,000.00');
247+
});
248+
249+
it('CONTROL: a number-returning formula is not an amount', async () => {
250+
const card = await lineCard(fields('name', 'quantity', 'line_weight'));
251+
expect(within(card).queryByTestId('grid-card-amount-line')).toBeNull();
252+
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('2 · 6');
253+
});
254+
255+
it('CONTROL: a view that presents the currency formula as text keeps it a plain value', async () => {
256+
const card = await lineCard([{ field: 'name' }, { field: 'quantity' }, { field: 'total_price', type: 'text' }]);
257+
expect(within(card).queryByTestId('grid-card-amount-line')).toBeNull();
258+
});
259+
});

0 commit comments

Comments
 (0)