Skip to content

Commit ebb4713

Browse files
fix(plugin-grid): a phone list card never repeats a formula title in its subtitle (#37079)
Fixes #37010 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:手机上打开工单、线索这类以公式字段作标题的列表时,卡片副标题不再重复标题里的内容,而是显示紧急程度、客户等下一批信息。 - 为什么做:手机列表卡片的标题与副标题重复,用户在一张卡上看不到记录的其他关键信息。 - 出错会怎样:最坏情况是手机卡片副标题少显示或多显示一列,数据与保存都不受影响,可直接撤回本改动。 - 要你做什么:无 ## What changes `buildMobileCardRenderer` in `ui/packages/plugin-grid/src/ObjectGrid.tsx`: when the object's declared name field is a `formula`, the card's subtitle skips every shown column whose field the formula reads, and takes the next shown columns instead. The reads are the formula's `record.FIELD` references as `collectPredicateFieldRefs` (`@object-ui/core`) names them, the same reader this grid's projection already uses for a CEL expression's reads (`objectGridQueryInputs.ts`); a read through a lookup (`record.account.name`) names the lookup, so its column is skipped too. This holds whether or not the formula column itself is shown. A name field that is not a formula reads nothing, so its card is unchanged. Status chip and amount line are untouched. Case list, as filed: title `CASE-00037 - Demo case 29 — critical problem`, subtitle `紧急 · Polar Cargo` (was `CASE-00037 · Demo case 29 — critical problem`). Changeset: `.changeset/37010-phone-card-formula-title-subtitle.md`, `@object-ui/plugin-grid` patch. Read first (by risk): 1. `ObjectGrid.tsx`, the `titleReads` block and the `subtitleColumns` filter in `buildMobileCardRenderer`. 2. `__tests__/phoneCardFormulaTitle-37010.test.tsx`. Two-minute check: `cd ui/packages/plugin-grid && pnpm exec vitest run --root ../.. packages/plugin-grid/src/__tests__/phoneCardFormulaTitle-37010.test.tsx` shows 3 passed. ## Tests New file `ui/packages/plugin-grid/src/__tests__/phoneCardFormulaTitle-37010.test.tsx`, through the real `ObjectGrid` card renderer at 375 px with the object schema served by the data source: - formula name field over the two leading columns: subtitle is `紧急 · Polar Cargo`; - the formula column shown as well: the subtitle still skips the formula's parts; - CONTROL: a text name field (`subject`) keeps `CASE-00037 · 紧急`. ## Acceptance notes - Reader choice: the platform's AST member reader for a formula's reads is `analyzeRelationshipTraversals` (`@objectstack/formula`), which `planObjectFormulas` in `@object-ui/core` uses. `@object-ui/plugin-grid` does not depend on `@objectstack/formula`, and adding it (its `package.json` and `pnpm-lock.yaml`) is outside this card's claimed file surface. This PR uses `collectPredicateFieldRefs`, already a dependency of this grid for the same question. The two readers differ only on spellings a name formula does not use in practice (a `record.FIELD` inside a string literal, a `data.FIELD` root); either difference can only skip a column, never draw a wrong value. - Seat decision on that reader question: option A, `collectPredicateFieldRefs`, the reader this grid's projection already uses, with no new dependency. - Overlap with #36978 (also edits `ObjectGrid.tsx`): `scripts/pm/overlap-check.mjs` VERDICT clean exit 0, against origin/main and against #36978. ## Verification All readings at head `84c9eec38eb`. <details><summary>New test file</summary> `phoneCardFormulaTitle-37010.test.tsx`: Test Files 1 passed, Tests 3 passed. </details> <details><summary>Ablation (one run)</summary> `scripts/ablation-replace.mjs` replaced the anchor `!titleReads.has(c.accessorKey)` with a marker. Anchor count went 1 to 0, blob `5fbd40d54cf4` to `52c21da6b1a0`. Result: 2 failed and 1 passed (the control). Both failures received `CASE-00037 · Demo case 29 — critical problem`, which is the filed defect. After restore the blob equals the HEAD blob (`5fbd40d54cf4`) and `git diff HEAD` is empty. The first attempt was a no-op that the tool refused (the replacement was a substring of the anchor), so no test ran then. It was redone with a distinct marker. </details> <details><summary>Package @object-ui/plugin-grid</summary> `type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`) passed. vitest: Test Files 311 passed, Tests 2763 passed. </details> <details><summary>Derived gates</summary> `dispatch-gates --commands` derived 39 commands. On the first pass 37 exited 0. - `pnpm --dir ui exec vitest run scripts/` exited 1. Four tests in three files hit the 15000 ms timeout while the box was contended, and none of them touch this diff. Those three files were re-run under the lock: 231/231 passed. - `pnpm check:type-check-debt` exited 3 (lock queue-timeout, NOT MEASURED). The re-run under the lock exited 0. `--ran` reconciliation on the first-pass codes: 39 derived, 38 run, 1 NOT-MEASURED, 0 UNRUN. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1b3b1b4 commit ebb4713

3 files changed

Lines changed: 182 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
---
4+
5+
fix(plugin-grid): a phone list card never repeats a formula title in its subtitle
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On a phone, a list card whose object names its records with a `formula` name field (a case's `display_title` = `case_number - subject`) showed the title's parts again in the subtitle when the view showed them as its leading columns, so the subtitle had no room for anything else. The subtitle now skips every shown column whose field the name field's formula reads (a read through a lookup, `record.account.name`, skips the lookup's column) and takes the next shown columns instead: `CASE-00037 - Demo case 29 — critical problem` over `紧急 · Polar Cargo`. A name field that is not a formula keeps the subtitle it had.

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import {
7171
AlertDialogHeader,
7272
AlertDialogTitle,
7373
} from '@object-ui/components';
74-
import { captureUpdateUndoData, resolveConditionalFormatting, declaredNameField, buildExportFileName, resolveAffordance, resolveAffordanceGrant, resolveFieldAffordance, isObjectExportOffered, type SchemaLike, isExpandableFieldType, isUnmaterializedFieldType, readObjectSortability, isPlatformSortableField, filterPlatformSortableSort, filterRefusalSubject, FilterOperatorError, resolveRecordSourceConfig, resolveRecordSourceObjectName, partitionRowsByPredicate, csvBlob, readActionPayload } from '@object-ui/core';
74+
import { captureUpdateUndoData, resolveConditionalFormatting, declaredNameField, collectPredicateFieldRefs, buildExportFileName, resolveAffordance, resolveAffordanceGrant, resolveFieldAffordance, isObjectExportOffered, type SchemaLike, isExpandableFieldType, isUnmaterializedFieldType, readObjectSortability, isPlatformSortableField, filterPlatformSortableSort, filterRefusalSubject, FilterOperatorError, resolveRecordSourceConfig, resolveRecordSourceObjectName, partitionRowsByPredicate, csvBlob, readActionPayload } from '@object-ui/core';
7575
import { usePermissions } from '@object-ui/permissions';
7676
import {
7777
RECORD_OVERLAY_DEFAULT_WIDTH,
@@ -4452,6 +4452,21 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44524452
// that titles the card, so a first column the name field displaced (the
44534453
// Owner above) reads as an ordinary body row.
44544454
const bodyColumns = displayColumns.filter((c) => c !== titleCol);
4455+
// objectstack#37010 — a name field that is a FORMULA titles the card with
4456+
// the fields it reads (`case_number - subject`), and a view shows those
4457+
// parts as columns of their own, usually its leading ones, since a table
4458+
// has no use for the concatenation. So the subtitle also skips every
4459+
// shown column whose field the formula reads: it never repeats the
4460+
// title's parts and takes the next shown columns instead. The reads are
4461+
// the formula's `record.<field>` references as `collectPredicateFieldRefs`
4462+
// names them, the reader this grid's projection names a CEL expression's
4463+
// reads with; a read through a lookup (`record.account.name`) names the
4464+
// lookup, so the lookup's column is skipped too. A name field that is not
4465+
// a formula reads nothing here.
4466+
const nameFieldDef = nameFieldKey !== undefined ? objectFields?.[nameFieldKey] : undefined;
4467+
const titleReads = new Set<string>(
4468+
nameFieldDef?.type === 'formula' ? collectPredicateFieldRefs([nameFieldDef.expression]) : [],
4469+
);
44554470

44564471
// objectui#10583 — a MASKED column (the rule that stamps `TableColumn.masked`)
44574472
// is drawn only through its own `cell`, which draws the mask. The branches
@@ -4471,7 +4486,8 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44714486
// read), when a column shows it, drawn through that column's own cell as
44724487
// the desktop row draws it. The subtitle joins the first two other shown
44734488
// columns' display values, each through its own cell, and skips a masked
4474-
// or empty value rather than drawing it.
4489+
// or empty value rather than drawing it, and a column the title's formula
4490+
// reads (`titleReads` above).
44754491
const statusKey = detectStatusField(objectSchema);
44764492
const statusCol = statusKey !== null ? bodyColumns.find((c) => c.accessorKey === statusKey) : undefined;
44774493
// objectstack#34615 — the card's AMOUNT is the first shown body column whose
@@ -4484,7 +4500,9 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44844500
const amountCol = bodyColumns.find(
44854501
(c) => c !== statusCol && c.type === 'currency' && !isMaskedCardColumn(c.accessorKey),
44864502
);
4487-
const subtitleColumns = bodyColumns.filter((c) => c !== statusCol && c !== amountCol).slice(0, 2);
4503+
const subtitleColumns = bodyColumns
4504+
.filter((c) => c !== statusCol && c !== amountCol && !titleReads.has(c.accessorKey))
4505+
.slice(0, 2);
44884506
const isEmptyCardValue = (value: unknown) => value == null || value === '';
44894507
const cardCell = (col: ObjectGridColumnDraft, row: any): React.ReactNode => {
44904508
const value = row[col.accessorKey];
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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#37010 — on a phone, a list card whose object names its records
11+
* with a FORMULA name field never repeats the title in its subtitle. The
12+
* formula (`display_title` = `case_number - subject`) titles the card, and the
13+
* view shows its parts as its own leading columns. The subtitle skips every
14+
* shown column whose field the formula reads and takes the next shown columns
15+
* instead. A name field that is not a formula keeps today's subtitle.
16+
*
17+
* Driven through the real card renderer (`ObjectGrid` at 375 px), with the
18+
* object schema served by the data source as a list page receives it.
19+
*
20+
* ── Directions on the base tree (predicted before the first run) ─────────
21+
* formula title, parts as leading columns: subtitle is the next two RED
22+
* formula title, formula column shown too: subtitle skips the parts RED
23+
* control: a text name field keeps today's subtitle GREEN
24+
*/
25+
import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest';
26+
import { render, cleanup, waitFor, screen, within } from '@testing-library/react';
27+
import '@testing-library/jest-dom';
28+
import React from 'react';
29+
30+
import { ObjectGrid } from '../ObjectGrid';
31+
import { LocalizationProvider } from '@object-ui/i18n';
32+
import { ActionProvider, SchemaRendererProvider } from '@object-ui/react';
33+
import { registerAllFields } from '@object-ui/fields';
34+
35+
beforeAll(() => {
36+
registerAllFields();
37+
if (!Element.prototype.scrollIntoView) {
38+
Element.prototype.scrollIntoView = vi.fn() as unknown as Element['scrollIntoView'];
39+
}
40+
});
41+
42+
const ORIGINAL_INNER_WIDTH = window.innerWidth;
43+
44+
function setWidth(px: number) {
45+
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: px });
46+
}
47+
48+
afterEach(() => {
49+
cleanup();
50+
setWidth(ORIGINAL_INNER_WIDTH);
51+
});
52+
53+
const OBJECT = 'case_37010';
54+
55+
const FIELDS = {
56+
id: { type: 'text' },
57+
case_number: { type: 'text', label: 'Case Number' },
58+
subject: { type: 'text', label: 'Subject' },
59+
status: {
60+
type: 'select',
61+
label: 'Status',
62+
options: [
63+
{ value: 'open', label: 'Open' },
64+
{ value: 'closed', label: 'Closed' },
65+
],
66+
},
67+
priority: {
68+
type: 'select',
69+
label: 'Priority',
70+
options: [
71+
{ value: 'critical', label: '紧急' },
72+
{ value: 'low', label: '低' },
73+
],
74+
},
75+
account: { type: 'text', label: 'Account' },
76+
display_title: {
77+
type: 'formula',
78+
label: 'Title',
79+
returnType: 'text',
80+
expression: { dialect: 'cel', source: "record.case_number + ' - ' + record.subject" },
81+
},
82+
};
83+
84+
const TITLE = 'CASE-00037 - Demo case 29 — critical problem';
85+
86+
const ROWS = [
87+
{
88+
id: 'c37',
89+
case_number: 'CASE-00037',
90+
subject: 'Demo case 29 — critical problem',
91+
status: 'open',
92+
priority: 'critical',
93+
account: 'Polar Cargo',
94+
display_title: TITLE,
95+
},
96+
];
97+
98+
/** The formula's parts lead the view, as a real case list shows them; the formula column itself is not shown. */
99+
const PART_COLUMNS = ['case_number', 'subject', 'status', 'priority', 'account'].map((field) => ({ field }));
100+
101+
function renderGrid(nameField: string, columns: unknown[]) {
102+
const dataSource = {
103+
find: vi.fn(async () => ({ data: ROWS, total: ROWS.length, hasMore: false, pageSize: 50 })),
104+
getObjectSchema: async (name: string) => ({ name, nameField, fields: structuredClone(FIELDS) }),
105+
} as never;
106+
return render(
107+
<LocalizationProvider value={{ locale: 'en' }}>
108+
<ActionProvider>
109+
<SchemaRendererProvider dataSource={dataSource}>
110+
<ObjectGrid
111+
schema={{ type: 'object-grid', objectName: OBJECT, columns, pagination: { pageSize: 50 } } as never}
112+
dataSource={dataSource}
113+
/>
114+
</SchemaRendererProvider>
115+
</ActionProvider>
116+
</LocalizationProvider>,
117+
);
118+
}
119+
120+
async function phoneCard(nameField: string, columns: unknown[] = PART_COLUMNS) {
121+
setWidth(375);
122+
renderGrid(nameField, columns);
123+
// The status chip reads its label off the object schema, so it proves the
124+
// field defs (and with them the name field's formula) have arrived.
125+
await waitFor(() => expect(screen.getByText('Open')).toBeInTheDocument());
126+
expect(document.querySelector('table'), 'the card layout, not the table').toBeNull();
127+
const cards = [...document.querySelectorAll('[data-testid="grid-mobile-card"]')] as HTMLElement[];
128+
expect(cards).toHaveLength(1);
129+
return cards[0];
130+
}
131+
132+
describe('the phone list card subtitle never repeats a formula title (objectstack#37010)', () => {
133+
it('a formula name field over the two leading columns: the subtitle is the next two shown columns', async () => {
134+
const card = await phoneCard('display_title');
135+
expect(within(card).getByTestId('grid-card-title').textContent).toBe(TITLE);
136+
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('紧急 · Polar Cargo');
137+
});
138+
139+
it('the formula column shown as well: the subtitle still skips the columns the formula reads', async () => {
140+
const columns = ['display_title', 'case_number', 'subject', 'status', 'priority', 'account'].map((field) => ({ field }));
141+
const card = await phoneCard('display_title', columns);
142+
expect(within(card).getByTestId('grid-card-title').textContent).toBe(TITLE);
143+
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('紧急 · Polar Cargo');
144+
});
145+
146+
it('CONTROL: a name field that is not a formula keeps the first two other shown columns', async () => {
147+
const card = await phoneCard('subject');
148+
expect(within(card).getByTestId('grid-card-title').textContent).toBe('Demo case 29 — critical problem');
149+
expect(within(card).getByTestId('grid-card-subtitle').textContent).toBe('CASE-00037 · 紧急');
150+
});
151+
});

0 commit comments

Comments
 (0)