Skip to content

Commit eb1f85d

Browse files
fix(plugin-detail): the compact related card labels its rows from the list columns when they leave the name out (#35497)
Fixes #35263 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户看到的变化:记录页右侧的紧凑关联卡片,如果关系声明了要显示的列且这些列不含子记录名称,每行改用其中第一个可读的查找列(例如所属商机)来命名,不再每行都重复当前页面记录的名字。 - 为什么改:产品页上的商机明细行名称是产品标题的副本,卡片三行都显示同一个产品名,看不出是哪几笔交易;作者已声明了能区分各行的列,只有紧凑卡片没用。 - 改错的后果与回滚:最坏情况是某些卡片的行名从记录标题变成一个查找值;未声明列、列中含名称、无可读查找列或使用标题模板的卡片保持原样;只动一个渲染组件,直接回滚即可。 - 需要你做的:无,席位落地。 ## What changes The compact related card (record page, right column) labelled every row by the child's record title. A child whose name field is a stored copy of the parent's title (an opportunity line named by its product's title, seen from the product page) therefore read the page's own name on every row, even though the relationship declared the columns that tell the rows apart. `compactNameField` in `ui/packages/plugin-detail/src/RelatedList.tsx` keeps the objectstack#27524 Target 11 rule unchanged (child's name field IS the key back to this record: first authored column, then declared field, that is not the key). The guard that returned `undefined` for every other child, `resolveNameField(objectSchema) !== referenceField`, now opens a second, narrower path (route N of the dispatch): - the list declares authored columns, and none of them is the child's name field (`resolveNameField`), and - the title is not a template (`titleFormat` with no declared name keeps the template title), - then the row is labelled from the first AUTHORED column that passes the existing candidate test (not the key back, not redacted, not a platform column, declared on the child, readable by the principal) AND is a reference-bearing field (`isExpandableFieldType`: lookup / master_detail / tree / user). Declared-but-unauthored fields are not read on this path. - Otherwise `undefined`: the row keeps the record title, as before. objectstack#27056 Target 2 holds: `compactSelect` already projects `compactNameField` in place of the name, so the card asks for `id` plus the label column (and its `$expand` root) and nothing more. Optional secondary text from the next authored column is out of scope. ## Tests New top-level `describe` in the shared harness `RelatedPanel.header-27524.test.tsx` (six cases): - A1: columns `[quantity, opportunity]`, name `product_title` (a copy of the product title) labels the rows `Acme renewal` / `Globex pilot`; A2: the request is `$select: ['id', 'opportunity']`, `$expand: ['opportunity']`. - Controls: columns include the name (title kept); no authored columns (title kept); no lookup among the columns (title kept); template title (kept); the lookup unreadable under field-level security (title kept, the value is not drawn and not in `$select`). - The three existing Target 11 cases stay green unchanged. <details><summary>Red on main's RelatedList.tsx (tree-only restore from the merge base 609b675, then restored from HEAD and proven by blob hash)</summary> ```text × columns that leave the name out label the row from their first lookup, and the card asks for exactly that AssertionError: expected [ 'Widget', 'Widget' ] to deeply equal [ 'Acme renewal', 'Globex pilot' ] Test Files 1 failed (1) Tests 1 failed | 14 passed (15) os-verify-lock: VERDICT command-exit 1 ``` </details> <details><summary>Green at 4bba85e</summary> ```text RelatedPanel.header-27524.test.tsx: Test Files 1 passed (1) · Tests 15 passed (15) · VERDICT command-exit 0 pnpm --filter @object-ui/plugin-detail test: Test Files 387 passed | 1 skipped (388) · Tests 3517 passed | 18 skipped (3535) pnpm --filter @object-ui/plugin-detail type-check (tsc --noEmit && tsc -p tsconfig.test.json): exit 0 os-verify-lock: VERDICT command-exit 0 ``` </details> ## Acceptance notes - Metadata-protocol measured as `none`: no key, value or default an author writes changes; `relatedListColumns` keeps its meaning (the columns the related list draws) and the compact card now reads it as it already did for Target 11. - Follow-up idea, not filed: secondary row text from the next authored column (the card's Expected mentions it; the dispatch put it out of scope). - The reference-type test uses the existing `isExpandableFieldType` (lookup, master_detail, tree, user), the same set the card's `$expand` is built from, so a chosen label column is always one the server can expand. ## Verification Local gate subset derived by `node scripts/pm/dispatch-gates.mjs --commands` at 4bba85e: 36 of 38 families exit 0; `pnpm check:type-check-debt` and `pnpm --dir ui exec vitest run scripts/` are NOT MEASURED locally (verify-lock queue timeout behind a sibling's long suite; the second was SIGKILLed on the shared box) and are left to CI. Full gate farm and dogfood belong to CI. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 895dd43 commit eb1f85d

3 files changed

Lines changed: 140 additions & 10 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-detail': patch
3+
---
4+
5+
fix(plugin-detail): a record page's compact related card labels its rows from the list's columns when those columns leave the child's name out
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A compact related card in the record page's right column labelled every row by the child's record title, so a line item named by a stored copy of its product's title read the product page's own name on every row, even when the relationship declared the columns that tell the lines apart (`relatedListColumns: [opportunity, quantity, ...]`). When the related list declares columns and they leave the child's name field out, the compact row is now labelled from the first of those columns that is a lookup to another record, the principal may read and the block does not redact; the card still asks the server for that one column and nothing more. A list with no declared columns, columns that include the name, no readable lookup among them, or a template title (`titleFormat`) keeps the record title, and a child named by the key back to the page keeps the rule it had.

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,28 +1401,44 @@ export const RelatedList: React.FC<RelatedListProps> = ({
14011401
* columns, redacted and unreadable fields. The key is skipped even when no
14021402
* authored column survives: the declared fields are read next. `undefined`:
14031403
* the row names the record as everywhere else.
1404+
*
1405+
* Otherwise, when the list declares authored columns and they leave the
1406+
* child's name field out (objectstack#35263), the row names the first
1407+
* authored column that is a lookup to another record, under the same
1408+
* candidate test: a line named by a stored COPY of the product's title reads
1409+
* the product page's own name on every row, and the author already said
1410+
* which columns tell the rows apart. Only the authored columns are read on
1411+
* this path, and a template title (`titleFormat` with no declared name) is
1412+
* no name field: the row keeps it.
14041413
*/
14051414
const compactNameField = React.useMemo((): string | undefined => {
14061415
if (!compact || !objectSchema || !referenceField) return undefined;
1407-
if (resolveNameField(objectSchema) !== referenceField) return undefined;
1416+
const nameField = resolveNameField(objectSchema);
14081417
const relatedObjectName = objectName || api || '';
1409-
const authored = dropRedactedColumns(Array.isArray(columns) ? columns : [], redactedFields)
1418+
const authoredColumns = Array.isArray(columns) ? columns : [];
1419+
const authored = dropRedactedColumns(authoredColumns, redactedFields)
14101420
.map(drawnColumnKey)
14111421
.filter((key): key is string => !!key);
14121422
const fields = objectSchema.fields;
1423+
const candidate = (key: string): boolean =>
1424+
key !== referenceField &&
1425+
!redactedFields.has(key) &&
1426+
!PLATFORM_RECORD_COLUMNS.has(key) &&
1427+
parentRelationshipFieldDef(fields, key) !== undefined &&
1428+
!(perms?.isLoaded && relatedObjectName && !perms.checkField(relatedObjectName, key, 'read'));
1429+
if (nameField !== referenceField) {
1430+
const declaredName = declaredNameField(objectSchema);
1431+
if (!(typeof declaredName === 'string' && declaredName) && objectSchema.titleFormat) return undefined;
1432+
if (!nameField || authored.length === 0) return undefined;
1433+
if (authoredColumns.some((c) => drawnColumnKey(c) === nameField)) return undefined;
1434+
return authored.find((key) => candidate(key) && isExpandableFieldType(parentRelationshipFieldDef(fields, key)));
1435+
}
14131436
const declared = Array.isArray(fields)
14141437
? fields.map((f: any) => f?.name).filter((n: unknown): n is string => typeof n === 'string')
14151438
: fields && typeof fields === 'object'
14161439
? Object.keys(fields)
14171440
: [];
1418-
return [...authored, ...declared].find(
1419-
(key) =>
1420-
key !== referenceField &&
1421-
!redactedFields.has(key) &&
1422-
!PLATFORM_RECORD_COLUMNS.has(key) &&
1423-
parentRelationshipFieldDef(fields, key) !== undefined &&
1424-
!(perms?.isLoaded && relatedObjectName && !perms.checkField(relatedObjectName, key, 'read')),
1425-
);
1441+
return [...authored, ...declared].find(candidate);
14261442
}, [compact, objectSchema, referenceField, columns, redactedFields, objectName, api, perms]);
14271443

14281444
/**

‎ui/packages/plugin-detail/src/__tests__/RelatedPanel.header-27524.test.tsx‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* collapse, no ⤢; ⌥↑ / ⌥↓ on the focused handle move the panel.
1919
* - Target 11: the compact row's first column skips the foreign key that
2020
* points back at this record.
21+
*
22+
* objectstack#35263 — authored columns that leave the child's name out label
23+
* the compact row from their first lookup, so a child named by a copy of the
24+
* parent's title does not read the page's own name on every row.
2125
*/
2226
import { describe, it, expect, vi, beforeAll, afterEach } from 'vitest';
2327
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
@@ -26,6 +30,7 @@ import '@testing-library/jest-dom';
2630
import React from 'react';
2731
import { RelatedList } from '../RelatedList';
2832
import { RelatedCardChromeContext, RelatedListCompactContext, type RelatedCardChrome } from '../relatedListCompact';
33+
import { PermissionProvider } from '@object-ui/permissions';
2934

3035
// Desktop, pinned rather than inherited: below 768 px a table list renders as a gallery.
3136
beforeAll(() => {
@@ -225,3 +230,102 @@ describe('the compact row’s first column (objectstack#27524, Target 11)', () =
225230
await waitFor(() => expect(names()).toEqual(['Widget', 'Widget']));
226231
});
227232
});
233+
234+
describe('the compact row label from the authored columns (objectstack#35263)', () => {
235+
// An order line seen from its product: the line is named by a stored COPY of
236+
// the product's title, not by the key back to it, so every row of the card
237+
// on the product page would read the page's own name.
238+
const lineFields = {
239+
product: { type: 'lookup', label: 'Product', reference: 'product' },
240+
product_title: { type: 'text', label: 'Product title' },
241+
opportunity: { type: 'lookup', label: 'Opportunity', reference: 'opportunity' },
242+
quantity: { type: 'number', label: 'Qty' },
243+
};
244+
const lineRows = [
245+
{ id: 'l1', product: { id: 'p1', name: 'Widget' }, product_title: 'Widget', opportunity: { id: 'o1', name: 'Acme renewal' }, quantity: 2 },
246+
{ id: 'l2', product: { id: 'p1', name: 'Widget' }, product_title: 'Widget', opportunity: { id: 'o2', name: 'Globex pilot' }, quantity: 5 },
247+
];
248+
const lineSchema = { name: 'line_item', nameField: 'product_title', fields: lineFields };
249+
250+
afterEach(() => vi.unstubAllGlobals());
251+
252+
const renderLines = (columns: string[] | undefined, opts: { schema?: Record<string, unknown>; restricted?: boolean } = {}) => {
253+
// No IntersectionObserver: the card reads its rows at once.
254+
vi.stubGlobal('IntersectionObserver', undefined);
255+
const find = vi.fn(async () => ({ data: lineRows, total: lineRows.length }));
256+
const list = (
257+
<RelatedListCompactContext.Provider value>
258+
<RelatedList
259+
title="Line items"
260+
type="table"
261+
api="line_item"
262+
objectName="line_item"
263+
referenceField="product"
264+
parentId="p1"
265+
columns={columns as never}
266+
dataSource={{ find, getObjectSchema: vi.fn(async () => opts.schema ?? lineSchema) } as any}
267+
/>
268+
</RelatedListCompactContext.Provider>
269+
);
270+
render(
271+
opts.restricted ? (
272+
<PermissionProvider
273+
roles={[{ name: 'restricted', label: 'Restricted' }]}
274+
permissions={[
275+
{
276+
object: 'line_item',
277+
roles: { restricted: { actions: ['read'], fieldPermissions: [{ field: 'opportunity', read: false }] } },
278+
},
279+
]}
280+
userRoles={['restricted']}
281+
>
282+
{list}
283+
</PermissionProvider>
284+
) : (
285+
list
286+
),
287+
);
288+
return find;
289+
};
290+
const names = () =>
291+
Array.from(document.querySelectorAll('[data-related-card-row]')).map((row) => row.firstElementChild?.textContent);
292+
const lastQuery = (find: ReturnType<typeof vi.fn>) =>
293+
(find.mock.calls.at(-1) as unknown as [string, Record<string, unknown>])[1];
294+
295+
it('columns that leave the name out label the row from their first lookup, and the card asks for exactly that', async () => {
296+
const find = renderLines(['quantity', 'opportunity']);
297+
await waitFor(() => expect(names()).toEqual(['Acme renewal', 'Globex pilot']));
298+
const query = lastQuery(find);
299+
expect(query.$select).toEqual(['id', 'opportunity']);
300+
expect(query.$expand).toEqual(['opportunity']);
301+
});
302+
303+
it('columns that include the name keep the title', async () => {
304+
renderLines(['product_title', 'opportunity', 'quantity']);
305+
await waitFor(() => expect(names()).toEqual(['Widget', 'Widget']));
306+
});
307+
308+
it('no authored columns keep the title', async () => {
309+
renderLines(undefined);
310+
await waitFor(() => expect(names()).toEqual(['Widget', 'Widget']));
311+
});
312+
313+
it('authored columns with no lookup among them keep the title', async () => {
314+
renderLines(['quantity']);
315+
await waitFor(() => expect(names()).toEqual(['Widget', 'Widget']));
316+
});
317+
318+
it('a template title is no name field: the row keeps it', async () => {
319+
renderLines(['quantity', 'opportunity'], {
320+
schema: { name: 'line_item', titleFormat: '{product_title} x {quantity}', fields: lineFields },
321+
});
322+
await waitFor(() => expect(names()).toEqual(['Widget x 2', 'Widget x 5']));
323+
});
324+
325+
it('a lookup the principal may not read labels nothing and is not asked for: the row keeps the title', async () => {
326+
const find = renderLines(['quantity', 'opportunity'], { restricted: true });
327+
await waitFor(() => expect(names()).toEqual(['Widget', 'Widget']));
328+
expect(screen.queryByText('Acme renewal')).toBeNull();
329+
expect(lastQuery(find).$select).not.toContain('opportunity');
330+
});
331+
});

0 commit comments

Comments
 (0)