Skip to content

Commit 9957484

Browse files
feat(plugin-grid): phone cards follow the object's highlightFields for their amount and subtitle (#38214)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoAvhxsnErQnmY8cTbgC3beU)_ Fixes #37891 repo:objectstack#3 · os-tesla · session_01L9qibwy7XB37e8e1P6jRJ3 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在手机上看列表和相关列表时,卡片按对象声明的「最重要字段」显示:右下角是其中第一个金额(订单明细显示这一行的合计,不再是单价),副标题依次显示后面最多三个字段,数字类带名称,例如「数量 2 · 单价 ¥6,000.00 · 折扣 10.00%」;电脑上的宽表格不变。 - 为什么做:HotCRM 订单明细的手机卡片只写「1 · 2」、右下角是单价,要改只能动宽表格的列顺序;你 11 月 28 日选了「按对象的最重要字段」,不加新配置。 - 出错会怎样:声明了「最重要字段」的对象,手机卡片都会跟着变(事先粗量约 222 处里 180 处,大多在 HotCRM),哪个对象读着不对,调它的「最重要字段」顺序即可;整个改动可以直接撤回。 - 要你做什么:无。 ## What changes Governing ruling: the maintainer chose option A on #37891 (ruling record 7235312203, 2026-11-28T06:25Z, anchor 7235198146): phone cards follow the object's `highlightFields` (ADR-0085 §1), no new key, no line-number title prefix. Built as the claim (7235321485) and its surface amendment (seat, 2026-11-28T06:31Z) say. - `ui/packages/plugin-grid/src/ObjectGrid.tsx` (`buildMobileCardRenderer`): when the object declares `highlightFields`, the card body is that list, in order (title excluded): the amount is the first entry that draws as money (#37890's `drawsAsMoney`), the subtitle the next three, skipping the status field and the title formula's reads, empty values dropped (0 is a value), and a number, currency or percent part (a formula or summary by its value type) is drawn under its field label (`grid-card-subtitle-label`). A highlighted field the view shows is drawn through its column draft; one it does not show through the synthesized draft. Masked fields stay masked: never the amount, never a part. An object without `highlightFields` keeps the column-order card (two unlabelled parts). - `ui/packages/plugin-grid/src/objectGridGenerateColumns.tsx`: the synthesized path's per-field draft is now its own callback, `synthesizeFieldColumn` (same body: renderer, translated label, FLS), which `generateColumns` calls and the card reuses. No behaviour change for columns. - Fetches, beside the declared name field and through the same gates (declared, FLS-readable, not draft-only/withheld/redacted), on every viewport so a width change never refetches: - `ui/packages/plugin-grid/src/objectGridRowLoad.ts` `getSelectFields` (the grid's own fetch); - `ui/packages/plugin-list/src/ListView.tsx` harvest (the list page's fetch); - `ui/packages/plugin-detail/src/RelatedList.tsx` `selectFields` (the related list's fetch; derived-columns lists still send no projection). - Changeset: `@object-ui/plugin-grid`, `@object-ui/plugin-list`, `@object-ui/plugin-detail` patch, naming the phone-card change. ## Tests - `plugin-grid` `phoneCardAmount-34615.test.tsx`, new top-level describe (HotCRM order-line fixture at 390 px): amount = highlighted total (CN¥10,800.00) though the table shows the unit price first; subtitle `Quantity 2 · Sales Price CN¥6,000.00 · Discount % 10.00%`; a text part drawn bare; an empty part dropped; a highlighted field no column shows is drawn and is in the grid's `$select`; CONTROL no `highlightFields` keeps `1 · 2` and the unit price, no labels; CONTROL a `password` field first in `highlightFields` is neither amount nor part and its value is never printed. - `plugin-list` `ListView.harness.test.tsx`, new top-level describe: a highlighted field no column shows is in `$select` and not drawn; CONTROL no `highlightFields` sends the old projection. - `plugin-detail` `RelatedList.selectFls-10186.test.tsx`, new top-level describe: a declared, readable highlighted field is requested, an undeclared one never; an FLS-denied one is not requested; CONTROL no `highlightFields` keeps the projection. ## Acceptance notes - The fetches ask for `highlightFields` on desktop too (a few extra columns per row), as they already ask for the name field, so crossing the 768 px breakpoint never refetches. - The status chip is unchanged: drawn when a column shows the status field; the status field is never a subtitle part. - The related list's non-enlarged mobile gallery (`object-gallery`) path is untouched (#37008 owns its labels). - No "×" joiner and no title prefix, by the ruling. The HotCRM `highlightFields` re-order (order line, quote line, and a review of its other objects) follows in its own card after this lands, per the anchor's 裁后执行. - Measured before the ruling (anchor 7235198146, static simulation): 180 of 222 shipped phone-card surfaces change, 134 of 138 on HotCRM; platform objects only gain a third part. ## Verification Two-minute check: `cd ui && pnpm exec vitest run packages/plugin-grid/src/__tests__/phoneCardAmount-34615.test.tsx -t highlightFields`, expect the objectstack#37891 describe green (7 cases). First files to read (by risk): `ui/packages/plugin-grid/src/ObjectGrid.tsx` (the card body and the label rule); `ui/packages/plugin-grid/src/objectGridGenerateColumns.tsx` (the extracted draft, must be byte-equivalent for columns); `ui/packages/plugin-detail/src/RelatedList.tsx` (the projection arm and its gates). Verification record: every reading below is on `objectstack-ai/objectstack`, base `origin/main` 4f7aa88, through `os-verify-lock.sh`, after rebuilding the closure (`turbo run build --filter='@object-ui/plugin-grid^...' --filter='@object-ui/plugin-list^...' --filter='@object-ui/plugin-detail^...'`, 58/58). <details><summary>Tests</summary> - The three changed test files at 32340f2+: `Test Files 3 passed (3)`, `Tests 168 passed (168)`; the plugin-grid file alone at the fixture fix: `Tests 18 passed (18)`. - Full suites `pnpm --dir ui exec vitest run packages/plugin-grid/ packages/plugin-list/ packages/plugin-detail/` at 5f2eee0 (head 512ad74 changes only test docblock comments): `Test Files 933 passed | 1 skipped (934)`, `Tests 8897 passed | 18 skipped (8915)`, VERDICT command-exit 0. - `type-check` in plugin-grid, plugin-list, plugin-detail: exit 0 each. </details> <details><summary>Shown red without the fix (ablation, restored to HEAD)</summary> - The five source files restored from base 4f7aa88 (tree only; `objectstack#37891` marker count 0 on disk in each), the three test files run: `Tests 9 failed | 159 passed (168)`. Red: all six grid cases with `highlightFields` (the masked control too, on its amount half: the base tree shows the unit price), both RelatedList projection cases, the ListView projection case. Green: the three no-`highlightFields` controls. - Restored with `git checkout HEAD -- PATHS`: marker counts back (2/1/1/1/1), `git diff HEAD` empty, each blob equal to its HEAD blob. </details> <details><summary>Gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` at 512ad74: 39 families derived, all 39 run locally, all exit 0 (two first hit a 240 s per-gate timeout, exit 124, and were re-run to exit 0: `pnpm check:query-options-erasure`, `pnpm --dir ui exec vitest run scripts/` = 172 files passed). `--ran`: `39 derived famil(ies) accounted for — 39 run, 0 NOT-MEASURED`. `overlap-check` before each push: VERDICT clean, exit 0 (#38169 and #37924 share files and merge cleanly). PR check-runs at 512ad74 (`pr-state`): 42 success, 13 expected skip, 0 failed, 0 pending; mergeable_state clean. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qibwy7XB37e8e1P6jRJ3 --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibwy7XB37e8e1P6jRJ3)_ <!-- signed: repo:objectstack#3 · os-tesla · session_01L9qibwy7XB37e8e1P6jRJ3 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ccdfe62 commit 9957484

9 files changed

Lines changed: 436 additions & 48 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
'@object-ui/plugin-list': patch
4+
'@object-ui/plugin-detail': patch
5+
---
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Phone list cards now follow the object's `highlightFields`. When an object declares them, a card's amount is the first of those fields that draws as money, and its subtitle is the next three, in that order, with empty values dropped and each number, currency or percent part under its field label (`Quantity 2 · Sales Price ¥6,000.00 · Discount % 10.00%`). The view's column order no longer decides the card, so an order line that declares `highlightFields: ['total_price', 'quantity', 'unit_price', 'discount']` shows its line total bottom right while its wide table keeps its columns. A highlighted field no column shows is drawn too: the grid's own fetch, the list page's fetch and the related list's fetch now ask for the object's `highlightFields` beside its name field, through the same field-level security gate.
11+
12+
This changes the phone card of every object that declares `highlightFields` and shows its fields in a different order, or shows more than two of them: review an object's `highlightFields` order if its phone list now reads differently. An object without `highlightFields` keeps the column-order card. Nothing changes on desktop tables, apart from the fetch asking for the highlighted fields.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,21 @@ export const RelatedList: React.FC<RelatedListProps> = ({
20082008
projection.add(declaredName);
20092009
}
20102010
}
2011+
// [objectstack#37891] The child object's `highlightFields` (ADR-0085).
2012+
// On a phone the enlarged tab's grid draws each row as a card whose
2013+
// amount and subtitle are those fields, in that order, whether or not a
2014+
// column shows them. Fetched, never drawn as columns; on every
2015+
// viewport, as the gallery cover above, so crossing the breakpoint never
2016+
// refetches. Through the name field's gates: declared, readable, and not
2017+
// one the block redacts.
2018+
const highlights = (objectSchema as { highlightFields?: unknown } | undefined)?.highlightFields;
2019+
if (Array.isArray(highlights)) {
2020+
for (const field of highlights) {
2021+
if (typeof field !== 'string' || field === '' || redactedFields.has(field)) continue;
2022+
if (parentRelationshipFieldDef(fields, field) === undefined || !readable(field)) continue;
2023+
projection.add(field);
2024+
}
2025+
}
20112026
}
20122027
return Array.from(projection);
20132028
}, [columns, redactedFields, referenceField, objectName, api, perms, expandFields, objectSchema, rowActions]);

‎ui/packages/plugin-detail/src/__tests__/RelatedList.selectFls-10186.test.tsx‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,46 @@ describe('RelatedList row fetch — the derived-columns boundary (objectui#10186
341341
for (const params of rowFetches(ds)) expect('$select' in params).toBe(false);
342342
});
343343
});
344+
345+
/**
346+
* objectstack#37891 — the child object's `highlightFields` (ADR-0085) ride
347+
* along. On a phone the enlarged tab's grid draws each row as a card whose
348+
* amount and subtitle are those fields, in that order, whether or not a
349+
* column shows them, so the rows this list reads must carry them. Through the
350+
* name field's gates: declared, readable, not redacted.
351+
*
352+
* Directions on the base tree, measured by reverting the fix:
353+
* a declared, readable highlighted field no column shows is requested RED
354+
* a highlighted field FLS denies is not requested RED (the readable one is missing too)
355+
* control: no highlightFields keeps the projection byte-identical GREEN
356+
*/
357+
describe('RelatedList row fetch — the child object\'s highlightFields ride along (objectstack#37891)', () => {
358+
const withHighlights = { name: OBJECT, highlightFields: ['salary', 'title', 'undeclared_field'], fields: baseFields };
359+
const lastSelect = (ds: ReturnType<typeof makeDataSource>): string[] =>
360+
rowFetches(ds).at(-1)?.$select ?? [];
361+
const schemaLanded = (): boolean =>
362+
tableDrawn() && typeof (h.schema?.columns ?? []).find((c: any) => c.accessorKey === 'name')?.cell === 'function';
363+
364+
it('requests a declared, readable highlighted field no column shows, and never an undeclared one', async () => {
365+
const ds = makeDataSource(withHighlights);
366+
renderList(ds, [], { columns: ['name'] });
367+
await waitFor(() => expect(lastSelect(ds)).toContain('salary'));
368+
expect(lastSelect(ds)).toEqual(['id', 'name', 'salary', 'title']);
369+
expect(drawnKeys()).not.toContain('salary');
370+
});
371+
372+
it('does not request a highlighted field FLS denies', async () => {
373+
const ds = makeDataSource(withHighlights);
374+
renderList(ds, denying('salary'), { columns: ['name'] });
375+
await waitFor(() => expect(schemaLanded()).toBe(true));
376+
for (const params of rowFetches(ds)) expect(params.$select).not.toContain('salary');
377+
expect(lastSelect(ds)).toEqual(['id', 'name', 'title']);
378+
});
379+
380+
it('control: a child with no highlightFields sends the projection it sent before', async () => {
381+
const ds = makeDataSource();
382+
renderList(ds, [], { columns: ['name'] });
383+
await waitFor(() => expect(schemaLanded()).toBe(true));
384+
expect(lastSelect(ds)).toEqual(['id', 'name']);
385+
});
386+
});

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

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
21102110
useObjectGridDiagnostics(schema);
21112111

21122112
// `generateColumns`, the column generator, in hook order (`./objectGridGenerateColumns`).
2113-
const { generateColumns } = useObjectGridGenerateColumns({
2113+
const { generateColumns, synthesizeFieldColumn } = useObjectGridGenerateColumns({
21142114
schema, dataSource, data, dataConfig, hasInlineData, objectName, objectSchema, objectFields,
21152115
objectTypesPending, schemaFields, schemaColumns, perms, navigation, executeAction, predicateScope,
21162116
resolveFieldLabel, translateOptions, uiLanguage, recordLinkAdornment, rowOpensRecord,
@@ -4408,8 +4408,37 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44084408
// A WITHHELD column (objectui#10657: the object's field types are still
44094409
// unknown, and the column has no type of its own) is handled the same way:
44104410
// its `cell` draws the mask.
4411+
// objectstack#37891 — the card's BODY. When the object declares
4412+
// `highlightFields` (ADR-0085's "which fields matter most", in priority
4413+
// order) the card reads its amount and subtitle from that list, in that
4414+
// order, whether or not the view shows each field as a column: the wide
4415+
// table keeps its own columns and the phone card follows the object. A
4416+
// shown column is drawn through its own draft; a field no column shows is
4417+
// drawn through the draft the synthesized grid would give it
4418+
// (`synthesizeFieldColumn`: the field's renderer, its translated label, and
4419+
// field-level security, so a field the viewer may not read is left out).
4420+
// The fetches that feed this grid ask for those fields beside the name
4421+
// field. An object that declares none keeps the shown columns' order.
4422+
const highlightNames = Array.isArray((objectSchema as any)?.highlightFields)
4423+
? [...new Set(((objectSchema as any).highlightFields as unknown[])
4424+
.filter((n): n is string => typeof n === 'string' && !!objectFields?.[n]))]
4425+
: [];
4426+
const followsHighlights = highlightNames.length > 0;
4427+
const cardColMap = new Map(colMap);
4428+
const highlightColumns = highlightNames
4429+
.filter((n) => n !== titleKey)
4430+
.map((n) => {
4431+
const shown = colMap.get(n);
4432+
if (shown) return shown;
4433+
const drafted = synthesizeFieldColumn(n);
4434+
if (drafted) cardColMap.set(n, drafted);
4435+
return drafted;
4436+
})
4437+
.filter((c): c is ObjectGridColumnDraft => c !== null && c !== undefined);
4438+
const cardBodyColumns = followsHighlights ? highlightColumns : bodyColumns;
4439+
44114440
const isMaskedCardColumn = (key: string) =>
4412-
isMaskedGridColumn(colMap.get(key)?.type, objectFields?.[key]?.type, objectTypesPending);
4441+
isMaskedGridColumn(cardColMap.get(key)?.type, objectFields?.[key]?.type, objectTypesPending);
44134442

44144443
// objectstack#28484 — a phone's card row is the board's list row: the
44154444
// title, ONE subtitle line and ONE status chip at the right, with no
@@ -4444,12 +4473,31 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44444473
const def = objectFields?.[c.accessorKey];
44454474
return def?.type === c.type && resolveFormulaValueType(def, 0) === 'currency';
44464475
};
4447-
const amountCol = bodyColumns.find(
4448-
(c) => c !== statusCol && drawsAsMoney(c) && !isMaskedCardColumn(c.accessorKey),
4476+
// objectstack#37891 — read from the card body above: with `highlightFields`
4477+
// the amount is the first of them that draws as money (an order line
4478+
// declaring `['total_price', 'quantity', 'unit_price', 'discount']` shows
4479+
// its total, not the unit price its table happens to show first), and the
4480+
// subtitle takes the next three, in that order, each number, currency and
4481+
// percent part under its field label, so `2 · 10` reads as quantities.
4482+
const amountCol = cardBodyColumns.find(
4483+
(c) => c.accessorKey !== statusKey && drawsAsMoney(c) && !isMaskedCardColumn(c.accessorKey),
44494484
);
4450-
const subtitleColumns = bodyColumns
4451-
.filter((c) => c !== statusCol && c !== amountCol && !titleReads.has(c.accessorKey))
4452-
.slice(0, 2);
4485+
const subtitleColumns = cardBodyColumns
4486+
.filter((c) => c.accessorKey !== statusKey && c !== amountCol && !titleReads.has(c.accessorKey))
4487+
.slice(0, followsHighlights ? 3 : 2);
4488+
const labelsSubtitlePart = (c: ObjectGridColumnDraft): boolean => {
4489+
if (!followsHighlights) return false;
4490+
if (c.type === 'number' || c.type === 'currency' || c.type === 'percent') return true;
4491+
if (c.type !== 'formula' && c.type !== 'summary') return false;
4492+
const def = objectFields?.[c.accessorKey];
4493+
if (def?.type !== c.type) return false;
4494+
const valueType = resolveFormulaValueType(def, 0);
4495+
return valueType === 'number' || valueType === 'currency' || valueType === 'percent';
4496+
};
4497+
const subtitlePartLabel = (c: ObjectGridColumnDraft): string | undefined => {
4498+
if (!labelsSubtitlePart(c)) return undefined;
4499+
return typeof c.header === 'string' && c.header !== '' ? c.header : undefined;
4500+
};
44534501
const isEmptyCardValue = (value: unknown) => value == null || value === '';
44544502
const cardCell = (col: ObjectGridColumnDraft, row: any): React.ReactNode => {
44554503
const value = row[col.accessorKey];
@@ -4613,7 +4661,12 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
46134661
{subtitle.map((col, i) => (
46144662
<React.Fragment key={col.accessorKey}>
46154663
{i > 0 && <span className="shrink-0 whitespace-pre"> · </span>}
4616-
<span data-testid="grid-card-subtitle-part" className="min-w-0 truncate">{cardCell(col, row)}</span>
4664+
<span data-testid="grid-card-subtitle-part" className="min-w-0 truncate">
4665+
{subtitlePartLabel(col) !== undefined && (
4666+
<span data-testid="grid-card-subtitle-label">{subtitlePartLabel(col)} </span>
4667+
)}
4668+
{cardCell(col, row)}
4669+
</span>
46174670
</React.Fragment>
46184671
))}
46194672
</div>

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

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,141 @@ describe('the phone card amount slot takes a formula or summary that draws as mo
257257
expect(within(card).queryByTestId('grid-card-amount-line')).toBeNull();
258258
});
259259
});
260+
261+
/**
262+
* objectstack#37891 — when the object declares `highlightFields` (ADR-0085,
263+
* "which fields matter most", in order), the phone card reads its amount and
264+
* subtitle from that list, not from the view's column order: the amount is
265+
* the first highlighted field that draws as money, the subtitle the next
266+
* three, in that order, empty values dropped, and a number, currency or
267+
* percent part carries its field label. A highlighted field no column shows
268+
* is drawn too, and the grid's fetch asks for it. An object that declares no
269+
* `highlightFields` keeps the column-order rule above.
270+
*
271+
* The fixture is HotCRM's order line (`crm_sales_order_line`), whose related
272+
* list shows `line_number, product_title, quantity, unit_price, discount,
273+
* total_price`: on the base tree its card read `1 · 2` with the unit price as
274+
* the amount, whatever `highlightFields` said.
275+
*
276+
* ── Directions on the base tree (measured by reverting the fix) ──────────
277+
* amount is the highlighted total, not the unit price RED
278+
* subtitle is the labelled highlighted parts, in order RED
279+
* a text part is drawn bare RED
280+
* a highlighted field no column shows is drawn and fetched RED
281+
* an empty highlighted part is dropped RED
282+
* control: a masked highlighted field is neither amount nor part RED (its amount half: the base tree shows the unit price)
283+
* control: no highlightFields keeps `1 · 2`, unit price, no labels GREEN
284+
*/
285+
describe('the phone card follows the object\'s highlightFields (objectstack#37891)', () => {
286+
const LINE_OBJECT = 'crm_sales_order_line_37891';
287+
const LINE_FIELDS = {
288+
id: { type: 'text' },
289+
product_title: { type: 'text', label: 'Product Title' },
290+
crm_product: { type: 'text', label: 'Product' },
291+
quantity: { type: 'number', label: 'Quantity', scale: 0 },
292+
unit_price: { type: 'currency', label: 'Sales Price' },
293+
discount: { type: 'percent', label: 'Discount %', scale: 2 },
294+
total_price: {
295+
type: 'formula',
296+
label: 'Total',
297+
returnType: 'currency',
298+
expression: 'record.quantity * record.unit_price * (1 - record.discount)',
299+
},
300+
line_number: { type: 'number', label: 'Line #', scale: 0 },
301+
access_pin: { type: 'password', label: 'Access PIN' },
302+
};
303+
const LINE_ROWS = [
304+
{ id: 'l1', line_number: 1, product_title: 'Admin Training Workshop', crm_product: 'Training', quantity: 2, unit_price: 6000, discount: 0.1, total_price: 10800, access_pin: 's3cr3t-pin' },
305+
{ id: 'l2', line_number: 2, product_title: 'AI Agent Seat (Annual)', crm_product: 'Seat', quantity: 10, unit_price: 1000, discount: null, total_price: 10000, access_pin: 's3cr3t-pin' },
306+
];
307+
/** HotCRM's `relatedListColumns` for the order's lines. */
308+
const RELATED = ['line_number', 'product_title', 'quantity', 'unit_price', 'discount', 'total_price'];
309+
310+
async function lineCards(columns: string[], highlightFields?: string[]) {
311+
setWidth(390);
312+
const find = vi.fn(async () => ({ data: LINE_ROWS, total: LINE_ROWS.length, hasMore: false, pageSize: 50 }));
313+
const dataSource = {
314+
find,
315+
getObjectSchema: async (name: string) => ({
316+
name,
317+
nameField: 'product_title',
318+
...(highlightFields ? { highlightFields } : {}),
319+
fields: structuredClone(LINE_FIELDS),
320+
}),
321+
} as never;
322+
render(
323+
<LocalizationProvider value={{ currency: 'CNY', locale: 'en' }}>
324+
<ActionProvider>
325+
<SchemaRendererProvider dataSource={dataSource}>
326+
<ObjectGrid
327+
schema={{ type: 'object-grid', objectName: LINE_OBJECT, columns: columns.map((field) => ({ field })), pagination: { pageSize: 50 } } as never}
328+
dataSource={dataSource}
329+
/>
330+
</SchemaRendererProvider>
331+
</ActionProvider>
332+
</LocalizationProvider>,
333+
);
334+
// The money cells read the field defs, so a CN¥ amount proves they landed.
335+
await waitFor(() => expect(cards()).toHaveLength(2));
336+
await waitFor(() => expect(document.body.textContent).toContain('CN¥'));
337+
expect(document.querySelector('table'), 'the card layout, not the table').toBeNull();
338+
return { find, first: cardOf('Admin Training Workshop'), second: cardOf('AI Agent Seat (Annual)') };
339+
}
340+
const parts = (card: HTMLElement) => within(card).getAllByTestId('grid-card-subtitle-part');
341+
const labels = (card: HTMLElement) =>
342+
within(card).queryAllByTestId('grid-card-subtitle-label').map((el) => el.textContent?.trim());
343+
344+
it('takes the first highlighted money field as the amount: the line total, not the unit price the table shows first', async () => {
345+
const { first } = await lineCards(RELATED, ['total_price', 'quantity', 'unit_price', 'discount']);
346+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
347+
});
348+
349+
it('draws the next highlighted fields as the subtitle, in order, each figure under its field label', async () => {
350+
const { first } = await lineCards(RELATED, ['total_price', 'quantity', 'unit_price', 'discount']);
351+
expect(parts(first)).toHaveLength(3);
352+
expect(labels(first)).toEqual(['Quantity', 'Sales Price', 'Discount %']);
353+
const [quantity, price, discount] = parts(first).map((p) => p.textContent);
354+
expect(quantity).toBe('Quantity 2');
355+
expect(price).toBe('Sales Price CN¥6,000.00');
356+
expect(discount).toMatch(/^Discount % 10\.00\s?%$/);
357+
// The line number the table shows first is no longer a subtitle part.
358+
expect(within(first).getByTestId('grid-card-subtitle').textContent).not.toMatch(/^1 ·/);
359+
});
360+
361+
it('labels only figures: a text part is drawn bare', async () => {
362+
const { first } = await lineCards(RELATED, ['total_price', 'crm_product', 'quantity']);
363+
expect(parts(first).map((p) => p.textContent)).toEqual(['Training', 'Quantity 2']);
364+
expect(labels(first)).toEqual(['Quantity']);
365+
});
366+
367+
it('drops an empty highlighted part rather than drawing it', async () => {
368+
const { second } = await lineCards(RELATED, ['total_price', 'quantity', 'unit_price', 'discount']);
369+
expect(within(second).getByTestId('grid-card-amount').textContent).toBe('CN¥10,000.00');
370+
expect(labels(second)).toEqual(['Quantity', 'Sales Price']);
371+
});
372+
373+
it('draws a highlighted field no column shows, and the fetch asks for it', async () => {
374+
const { first, find } = await lineCards(
375+
['line_number', 'product_title', 'quantity', 'unit_price'],
376+
['total_price', 'quantity', 'unit_price', 'discount'],
377+
);
378+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
379+
expect(labels(first)).toEqual(['Quantity', 'Sales Price', 'Discount %']);
380+
const select = (find.mock.calls.at(-1) as unknown[] | undefined)?.[1] as { $select?: string[] } | undefined;
381+
expect(select?.$select).toEqual(expect.arrayContaining(['total_price', 'discount']));
382+
});
383+
384+
it('CONTROL: an object with no highlightFields keeps the column-order card (line number · quantity, unit price, no labels)', async () => {
385+
const { first } = await lineCards(RELATED);
386+
expect(within(first).getByTestId('grid-card-subtitle').textContent).toBe('1 · 2');
387+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥6,000.00');
388+
expect(labels(first)).toEqual([]);
389+
});
390+
391+
it('CONTROL: a masked highlighted field is neither the amount nor a subtitle part, and its value is never printed', async () => {
392+
const { first } = await lineCards(RELATED, ['access_pin', 'total_price', 'quantity']);
393+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
394+
expect(labels(first)).toEqual(['Quantity']);
395+
expect(first.textContent).not.toContain('s3cr3t-pin');
396+
});
397+
});

0 commit comments

Comments
 (0)