Skip to content

Commit ab44198

Browse files
fix(plugin-detail): related list row Delete confirm names the row by its declared nameField (#34890)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBU5y97XtBcJ8qSLSR3B3Djd)_ repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs Fixes #34788 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:相关列表(如「商机 → 相关 → 商机产品明细」)的行删除确认框,现在用子对象声明的 `nameField` 显示记录名,不再显示「Record #ID」。 - **为什么改**:列表配置了列且列里没有名称字段时,取数只取列字段,删除确认框拿不到名称,用户确认删除时看不到删的是哪条。 - **风险与回滚**:风险低,只是取数多带一个名称字段;无权读取或被屏蔽的名称字段仍不取。回滚即 revert 本 PR。 - **先看**:`ui/packages/plugin-detail/src/RelatedList.tsx` 的 `selectFields`(新增的 declared name field 一段);`RelatedList.deleteConfirmNamed-13333.test.tsx` 新增的 describe。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/plugin-detail/src/__tests__/RelatedList.deleteConfirmNamed-13333.test.tsx`,预期 6 个用例全部通过。 - **需要你做的**:无,席位落地。 ## What changes `RelatedList`'s `$select` projection (`selectFields`) now also asks for the child object's DECLARED name field (`declaredNameField`: `nameField`, then its deprecated `displayNameField` alias), so the row Delete confirm (`detail.deleteRowConfirmation`, resolved by `getRecordDisplayName`) can name a row whose name column is not shown. The name field goes through the same gates as the projection's other non-column members (predicate operands, gallery cover): the child object declares it or it is a platform column; the viewer may read it (FLS) when it is declared; the block does not redact it. It is fetched only and never drawn as a column. A derived title field and a `titleFormat` template are not requested: neither is a declared pointer. This is the same arm `ObjectGrid` (`objectGridRowLoad.ts`) and `ListView` already carry for their bulk confirms. A list with no authored columns still sends no projection. ## Why A related list with authored columns projected its fetch to those columns, `id`, the `$expand` roots, predicate operands and the gallery cover. The confirm reads the name from the row that fetch returned. When the declared `nameField` was not a column, the row arrived without it and the sentence fell to the resolver's `Record #ID` floor. ## Tests New top-level describe in the delete confirm's existing harness, `RelatedList.deleteConfirmNamed-13333.test.tsx`. Its data source honours `$select` the way the data API does: only the requested keys come back. - `a nameField no column shows is requested, never drawn, and names the row`: every `$select` contains `full_name`, the fetched row carries it, the drawn columns stay `['email']`, and the dialog says `Are you sure you want to delete "Ada Lovelace"?`. - `a nameField the principal cannot read is not requested, and the confirm reads the id floor`: FLS denies `full_name`, no `$select` contains it, and the dialog reads `Record #c1` as before. - `CONTROL: a shown name column is requested once, as before`: columns `['full_name','email']` give the projection `{email, full_name, id}` with no duplicate entry. Ablation of the fix on commit `33e54b63d3` (`scripts/ablation-replace.mjs`, anchor `projection.add(declaredName);` replaced by a no-op marker, auto-restored): the main pin went red (`Tests 1 failed | 5 passed (6)`). The FLS and CONTROL cases stay green under the ablation, as expected, because they assert absence and an unchanged projection. The restore was verified as blob equal to HEAD and an empty `git diff HEAD`. ## Acceptance notes - **Live repro, before and after** (CRM example, `objectstack dev` on a private port, Console Vite dev server from this branch's `ui/` source). I made a temporary local edit, `relatedListColumns: ['email']` on `crm_contact.account` (`crm_contact` declares `nameField: 'full_name'`), and restored it afterwards. Steps: Acme Corp account, Contacts tab, row menu, Delete. - Before: the request was `GET /api/v1/data/crm_contact?top=25&skip=0&select=id,email&filter=["account","=","f0XomXLBbu835454"]`. Each response row had the keys `id,email`. The dialog said `Are you sure you want to delete "Record #nbkWdK1xsYpQsMvN"?`. - After: the request was `...&select=id,email,full_name&...`. Each response row had the keys `id,email,full_name`. The dialog said `Are you sure you want to delete "Ada Lovelace"?`. The table still draws only the Email column. - The compact related-card face already projects the name (`compactSelect`), so the record page's side panels were unaffected. Only the full table face (the tab, as in the reported path) lost the name. - Not measured: an object with NO declared `nameField`, whose derived title field (`deriveTitleField`) is not a column, still reads `Record #ID` in this confirm. This matches the `ObjectGrid`/`ListView` arms, which also request only the declared pointer, and an existing pin requires `$select` to be exactly `['id']` for such an object. Left as is. ## Verification <details><summary>Local runs on head 33e54b6</summary> - `pnpm --dir ui exec vitest run packages/plugin-detail/` (under the verify lock): `Test Files 384 passed | 1 skipped (385)`, `Tests 3457 passed | 18 skipped (3475)`, lock VERDICT command-exit 0. - `pnpm --filter @object-ui/plugin-detail run type-check`: exit 0. `--listFiles` on `tsconfig.test.json` includes the edited test file. - `node scripts/pm/dispatch-gates.mjs --commands` derived 38 families. All 38 ran with exit 0. `--ran` reconciliation: `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero)`. - `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0` (origin/main d947a93, 0 PR heads). - `ui` `check:new-line-citations`: 0 new citations. `eslint` on the two edited files: 0 errors. - The full lint and test farm runs in CI. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (`packages/spec` untouched.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (`eslint` on the edited files reports 0 errors; the repo-wide run is CI's.) - [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: its generated artifacts are regenerated and committed. (Not touched.) - [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. (The 维护者速读 block is the dispatch contract's Chinese summary.) - [ ] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent f012183 commit ab44198

3 files changed

Lines changed: 140 additions & 1 deletion

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 related list's row Delete confirm names the row by its declared `nameField` when no column shows it
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A related list with authored columns sends a `$select` projection, and the row Delete confirm names the row from the row that projection fetched. The projection did not ask for the child object's declared `nameField` unless a column showed it, so the confirm read `Are you sure you want to delete "Record #<id>"?` for a row that has a name. The projection now asks for the declared `nameField` (or its deprecated `displayNameField` alias) through the same gates as its other members: the field must be declared by the child object or be a platform column, the viewer must be allowed to read it, and the block must not redact it. It is fetched only, never drawn as a column. A list without authored columns sends no projection, as before. A name field the viewer cannot read is still not requested, and its confirm keeps the `Record #<id>` wording.

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,9 @@ export const RelatedList: React.FC<RelatedListProps> = ({
12571257
* (objectui#10690), so the first query carries the operands;
12581258
* - the mobile card gallery's cover (`MOBILE_GALLERY_COVER_FIELD`), which
12591259
* no column shows and the gallery reads off every row — through the same
1260-
* declared-and-readable gate, once the child schema has landed.
1260+
* declared-and-readable gate, once the child schema has landed;
1261+
* - the child object's DECLARED name field, which the row Delete confirm
1262+
* names the row by — through the same gates, never drawn.
12611263
*
12621264
* ⛔ `pruneEmpty` is NOT applied: it judges emptiness from the rows this
12631265
* request fetches, so the projection is taken before it — it only ever
@@ -1328,6 +1330,23 @@ export const RelatedList: React.FC<RelatedListProps> = ({
13281330
&& readable(MOBILE_GALLERY_COVER_FIELD)) {
13291331
projection.add(MOBILE_GALLERY_COVER_FIELD);
13301332
}
1333+
// The object's DECLARED name field (ADR-0079 D2/D4). The row Delete
1334+
// confirm names the row from the row this projection fetched
1335+
// (`getRecordDisplayName`), so a `nameField` no column shows must still
1336+
// be on the row, or the sentence reads the `Record #<id>` floor. Fetched,
1337+
// never drawn: it joins the projection, not the columns — the arm
1338+
// `ObjectGrid` and `ListView` carry for their own confirms. Asked by
1339+
// name whatever its type (the server serves a formula field like any
1340+
// other), through the operands' gates: declared or a platform column,
1341+
// readable when declared, and not one the block redacts. A derived or
1342+
// `titleFormat` title is not asked for: it is no declared pointer.
1343+
const declaredName = declaredNameField(objectSchema);
1344+
if (typeof declaredName === 'string' && declaredName !== '' && !redactedFields.has(declaredName)) {
1345+
const declared = parentRelationshipFieldDef(fields, declaredName) !== undefined;
1346+
if ((declared || PLATFORM_RECORD_COLUMNS.has(declaredName)) && (!declared || readable(declaredName))) {
1347+
projection.add(declaredName);
1348+
}
1349+
}
13311350
}
13321351
return Array.from(projection);
13331352
}, [columns, redactedFields, referenceField, objectName, api, perms, expandFields, objectSchema, rowActions]);

‎ui/packages/plugin-detail/src/__tests__/RelatedList.deleteConfirmNamed-13333.test.tsx‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import { describe, it, expect, vi, beforeEach, beforeAll, afterEach } from 'vitest';
1818
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
1919
import * as React from 'react';
20+
import { PermissionProvider } from '@object-ui/permissions';
21+
import type { ObjectPermissionConfig } from '@object-ui/types';
2022
import { RelatedList } from '../RelatedList';
2123

2224
beforeAll(() => {
@@ -115,3 +117,111 @@ describe('RelatedList — the row delete confirm names the row (objectui#13333)'
115117
expect(onRowDelete).not.toHaveBeenCalled();
116118
});
117119
});
120+
121+
/**
122+
* objectstack#34788 — the confirm names a FETCHED row, and the list's `$select`
123+
* projection decides which keys that row carries. A child whose declared
124+
* `nameField` no authored column shows must still have it requested, through
125+
* the projection's own gates (declared, readable), or the sentence reads the
126+
* `Record #<id>` floor. The backend below honours `$select` the way the
127+
* ObjectStack data API does: only the asked keys come back.
128+
*/
129+
describe('RelatedList — the row delete confirm names a fetched row by its declared nameField (objectstack#34788)', () => {
130+
const CONTACT = 'crm_contact';
131+
const CONTACT_SCHEMA = {
132+
name: CONTACT,
133+
nameField: 'full_name',
134+
fields: {
135+
first_name: { name: 'first_name', type: 'text', label: 'First Name' },
136+
last_name: { name: 'last_name', type: 'text', label: 'Last Name' },
137+
full_name: { name: 'full_name', type: 'formula', returnType: 'text', label: 'Full Name' },
138+
email: { name: 'email', type: 'email', label: 'Email' },
139+
account: { name: 'account', type: 'lookup', reference: 'crm_account', label: 'Account' },
140+
},
141+
};
142+
const STORED = {
143+
id: 'c1',
144+
first_name: 'Ada',
145+
last_name: 'Lovelace',
146+
full_name: 'Ada Lovelace',
147+
email: 'ada@acme.example',
148+
account: 'acc_1',
149+
};
150+
151+
function projectingDataSource() {
152+
return {
153+
getObjectSchema: vi.fn(async () => CONTACT_SCHEMA),
154+
find: vi.fn(async (_api: string, params: any) => {
155+
const select: string[] | undefined = params?.$select;
156+
const row = select
157+
? Object.fromEntries(Object.entries(STORED).filter(([k]) => select.includes(k)))
158+
: { ...STORED };
159+
return { data: [row], total: 1 };
160+
}),
161+
} as any;
162+
}
163+
164+
const denying = (...fields: string[]): ObjectPermissionConfig[] => [
165+
{
166+
object: CONTACT,
167+
roles: { staff: { actions: ['read', 'delete'], fieldPermissions: fields.map((field) => ({ field, read: false })) } },
168+
},
169+
];
170+
171+
/** Render the list, wait for the table to hold the fetched row, then open Delete on THAT row. */
172+
async function openDeleteOnFetchedRow(ds: any, columns: string[], permissions: ObjectPermissionConfig[]) {
173+
render(
174+
<PermissionProvider roles={[{ name: 'staff', label: 'Staff' }]} permissions={permissions} userRoles={['staff']}>
175+
<RelatedList
176+
title="Contacts"
177+
type="table"
178+
api={CONTACT}
179+
objectName={CONTACT}
180+
referenceField="account"
181+
parentId="acc_1"
182+
dataSource={ds}
183+
columns={columns}
184+
onRowDelete={vi.fn()}
185+
/>
186+
</PermissionProvider>,
187+
);
188+
await waitFor(() => expect(h.schema?.data?.length ?? 0).toBeGreaterThan(0));
189+
const fetched = h.schema.data[0];
190+
act(() => {
191+
h.schema.onRowDelete(fetched);
192+
});
193+
const dialog = await screen.findByRole('alertdialog');
194+
const selects: string[][] = ds.find.mock.calls
195+
.filter(([api]: any[]) => api === CONTACT)
196+
.map(([, params]: any[]) => params?.$select);
197+
return { dialog, fetched, selects, drawn: (h.schema.columns ?? []).map((c: any) => c.accessorKey) };
198+
}
199+
200+
it('a nameField no column shows is requested, never drawn, and names the row', async () => {
201+
const ds = projectingDataSource();
202+
const { dialog, fetched, selects, drawn } = await openDeleteOnFetchedRow(ds, ['email'], denying());
203+
expect(selects.length).toBeGreaterThan(0);
204+
for (const select of selects) expect(select).toEqual(expect.arrayContaining(['id', 'email', 'full_name']));
205+
expect(fetched.full_name).toBe('Ada Lovelace');
206+
expect(drawn).toEqual(['email']);
207+
expect(dialog.textContent).toContain('Are you sure you want to delete "Ada Lovelace"?');
208+
});
209+
210+
it('a nameField the principal cannot read is not requested, and the confirm reads the id floor', async () => {
211+
const ds = projectingDataSource();
212+
const { dialog, fetched, selects } = await openDeleteOnFetchedRow(ds, ['email'], denying('full_name'));
213+
for (const select of selects) expect(select).not.toContain('full_name');
214+
expect(fetched).not.toHaveProperty('full_name');
215+
expect(dialog.textContent).toContain('Are you sure you want to delete "Record #c1"?');
216+
});
217+
218+
it('CONTROL: a shown name column is requested once, as before', async () => {
219+
const ds = projectingDataSource();
220+
const { dialog, selects, drawn } = await openDeleteOnFetchedRow(ds, ['full_name', 'email'], denying());
221+
for (const select of selects) {
222+
expect([...select].sort()).toEqual(['email', 'full_name', 'id']);
223+
}
224+
expect(drawn).toEqual(['full_name', 'email']);
225+
expect(dialog.textContent).toContain('Are you sure you want to delete "Ada Lovelace"?');
226+
});
227+
});

0 commit comments

Comments
 (0)