Skip to content

Commit 50bfbb8

Browse files
fix(fields): a tap on a lookup picker option's preview chip selects the option (#36602)
Fixes #36479 Clause-②: no Metadata-protocol: none repo:objectstack#2 · os-steve · session_01ADHkmNmMEXS4EzeVz9RjvD ## 维护者速读 - 用户在关联字段的下拉选择里点选项下方预览中的记录标签(如「客户:Fabrikam」),以前会直接跳到那条记录、编辑被丢下;现在点选项任何位置都是选中该选项,手机和电脑一样。 - 记录页字段区的体验修补,替在手机上编辑关联字段的用户解决「点错就跳走」的问题。 - 出错时最坏是预览里的记录标签或邮箱、网址不再能点开(本来在选择框里也不该点开);记录页、列表里的链接不受影响,改动可直接撤回。 - 无。 ## What changes The lookup quick-picker's option preview drew each extra column through the read cell. A reference column became a link to its record whenever the host answers `recordHref` (on a record page, the record chip), and that link's click handler stops propagation and calls the host's `openRecord`, so the option row's own click never fired. An `email` / `url` / `phone` / file column did the same with its own anchor (the email cell's anchor also stops propagation). `renderLookupColumnValue` is the one renderer both picker surfaces call (the dropdown preview and the browse-all dialog table). It now carries the picker rule the dialog applied on its own (objectui#11903, point 7): every candidate cell renders under a host with no record destination (`WithoutRecordLinks`), so a reference keeps its face (the chip included) without the anchor or hover card, and a self-linking type is drawn with the `text` face. The fix sits where the preview gets the read cell's link; no event is swallowed anywhere. Desktop answer the card asked for: yes, the same click navigated with a mouse too. The defect was the link's click handler, not the pointer type; the pin drives both `[TouchA]` and `[MouseLeft]`. ## First read (by risk) 1. `ui/packages/fields/src/widgets/lookupColumnDisplay.tsx`: the renderer branch of `renderLookupColumnValue` (face substitution + `WithoutRecordLinks`). 2. `ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx`: the pin. ## Tests <details><summary>Premise reproduced on main (c0eecb1 code, pin only)</summary> ``` × [TouchA] on the chip selects the option and opens no record × [MouseLeft] on the chip selects the option and opens no record × draws the chip with no anchor, so the option is the one click target × draws a self-linking column with its text face, so a tap on it selects too AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times (openRecord) AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times (onChange, email column) Tests 4 failed (4) ``` </details> <details><summary>With the fix</summary> ``` LookupField.previewLinkFree-36479.test.tsx Tests 4 passed (4) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation (fix committed first; renderer branch reverted with scripts/ablation-replace.mjs)</summary> ``` ablation-replace: ok mutation landed: anchor 1 -> 0, blob f2aef5e -> a27207a105b6 × [TouchA] on the chip selects the option and opens no record × [MouseLeft] on the chip selects the option and opens no record × draws the chip with no anchor, so the option is the one click target × draws a self-linking column with its text face, so a tap on it selects too Tests 4 failed (4) ablation-replace: ok restored: blob == HEAD (f2aef5e) and `git diff HEAD` is empty ``` `@object-ui/fields` resolves to `src/` through the ui vitest alias, so no dist rebuild was involved in either leg. </details> <details><summary>Package suite and type-check</summary> At head 186d4b4: ``` pnpm exec vitest run --root ../.. --maxWorkers=2 packages/fields/ && pnpm run type-check (under os-verify-lock) Test Files 323 passed | 1 skipped (324) Tests 4895 passed | 7 skipped (4902) tsc --noEmit && tsc -p tsconfig.test.json (the test program includes src/**/*.test.tsx) os-verify-lock: VERDICT command-exit 0 ``` Only `@object-ui/fields` changes, and its public surface is byte-unchanged (no export added or removed), so no importer owes a run. </details> ## Acceptance notes - `RecordPickerDialog.tsx` keeps its own `SELF_LINKING_CELL_TYPES` substitution and `WithoutRecordLinks` wrapper; with the rule now in the shared renderer they are redundant there (idempotent, no behaviour change). Removing them is outside this card's file surface and left in place. - The record page's chip face (`ReferenceChipContext`) still reaches the preview through the popover, so a reference in an option preview draws as an unlinked chip there and as plain text elsewhere. Unchanged here; noted only. ## Verification Two-minute check: `cd ui/packages/fields && pnpm exec vitest run --root ../.. packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx` shows 4 passed. In the Console (not driven in a browser by this PR; the component pin is the evidence): showcase Field Zoo record at 375 px, inline-edit the Master-Detail field, open the picker, tap the `Account: Fabrikam` chip in an option preview: expect the option to be selected and no record to open. <details><summary>Gate families derived for this diff (head 186d4b4)</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 38 families; all 38 ran locally and exited 0 (the vitest one under os-verify-lock). `--ran` reconciliation: `38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN` (a derived zero: every line carries its exit code). The type-check programs CI runs over the whole workspace (`Type Check UI` and the `lint.yml` type-check lanes) are CI's; the package's own `type-check` above is the local reading. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 89ce4fb commit 50bfbb8

3 files changed

Lines changed: 223 additions & 2 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/fields': patch
3+
---
4+
5+
fix(fields): a tap anywhere on a lookup picker option selects it, including on a record chip in its preview
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A lookup picker's option shows a preview of its other columns under its label. A column that references another record drew a link to that record there (on a record page, its chip), and a tap or a click on it opened that record instead of selecting the option, leaving the edit behind. An email, URL or phone column in the preview did the same with the mail client, the browser or the dialer.
11+
12+
The preview now draws every column the way the "browse all records" picker table already did: a reference keeps its face, the record page's chip included, without the link, and an email, URL, phone or file column shows its text. A tap or a click anywhere on the option selects it, on a phone and on a desktop. Both picker surfaces now take this rule from the one renderer they share.
13+
14+
What does not change: the read cells outside the picker (record page fields, list and grid cells) keep their links. No metadata key, value or default changes.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
* A tap anywhere on a lookup quick-picker option selects that option —
11+
* objectstack#36479.
12+
*
13+
* Seen on the showcase Field Zoo record at 375 px: editing the Master-Detail
14+
* field (target: Project) and tapping the record chip `Account: Fabrikam`
15+
* inside an option's preview opened the Fabrikam record mid-edit; the option
16+
* was not selected. The preview draws each column through the read cell, and
17+
* the read cell draws a reference as a link to its record whenever the host
18+
* answers `recordHref`. The link's own click handler stops propagation and
19+
* hands the click to the host's `openRecord`, so the option row never heard it
20+
* — whatever the pointer: a mouse click on a desktop did the same.
21+
*
22+
* The rule is the picker table's (objectui#11903, point 7), now held by the
23+
* one renderer both picker surfaces call (`renderLookupColumnValue`): a
24+
* candidate's column never renders as a navigational link. A reference keeps
25+
* its face (the record page's chip) without the anchor, and a type that draws
26+
* its own anchor (`mailto:`, a URL, `tel:`, a file) is drawn with the text face.
27+
*/
28+
29+
import * as React from 'react';
30+
import { describe, it, expect, vi, afterEach } from 'vitest';
31+
import { render, screen, cleanup, waitFor, act, fireEvent, within } from '@testing-library/react';
32+
import userEvent from '@testing-library/user-event';
33+
import '@testing-library/jest-dom';
34+
import { RelatedRecordActionsProvider } from '@object-ui/react';
35+
import { LookupField } from './LookupField';
36+
// Installs the cell-renderer resolver the preview draws its values with, and
37+
// the record page's chip context.
38+
import { ReferenceChipContext } from '../index';
39+
40+
/** The referenced object (`showcase_project`) as `getObjectSchema` serves it. */
41+
const FIELDS: Record<string, Record<string, unknown>> = {
42+
name: { type: 'text', label: 'Project Name' },
43+
account: { type: 'lookup', label: 'Account', reference: 'showcase_account' },
44+
contact_email: { type: 'email', label: 'Contact Email' },
45+
};
46+
47+
const ROW = {
48+
id: 'prj_1',
49+
name: 'Website Relaunch',
50+
// As the candidate query serves it, `$expand`-ed (objectui#10223).
51+
account: { id: 'acc_9', name: 'Fabrikam' },
52+
contact_email: 'pm@fabrikam.example.com',
53+
};
54+
55+
function makeDataSource() {
56+
return {
57+
find: vi.fn(async () => ({ data: [ROW], total: 1 })),
58+
findOne: vi.fn(async () => ROW),
59+
getObjectSchema: vi.fn(async (objectName: string) => ({ name: objectName, fields: FIELDS })),
60+
};
61+
}
62+
63+
/** The record page's host: it routes every object, and opens records in-app. */
64+
function makeHost() {
65+
return {
66+
recordHref: (objectName: string, recordId: string | number) =>
67+
`/apps/showcase/${objectName}/record/${encodeURIComponent(String(recordId))}`,
68+
openRecord: vi.fn(),
69+
};
70+
}
71+
72+
async function openPicker(columns: string[]) {
73+
const host = makeHost();
74+
const onChange = vi.fn();
75+
render(
76+
// The record page's field area: references are drawn as chips (objectstack#36147).
77+
<RelatedRecordActionsProvider value={host as never}>
78+
<ReferenceChipContext.Provider value>
79+
<LookupField
80+
value={undefined}
81+
onChange={onChange}
82+
dataSource={makeDataSource() as never}
83+
field={{
84+
reference: 'showcase_project',
85+
displayField: 'name',
86+
lookupColumns: columns.map((field) => ({ field, label: FIELDS[field].label as string })),
87+
} as never}
88+
/>
89+
</ReferenceChipContext.Provider>
90+
</RelatedRecordActionsProvider>,
91+
);
92+
await act(async () => {
93+
fireEvent.click(screen.getByTestId('lookup-trigger'));
94+
});
95+
await waitFor(() => expect(screen.getByText('Website Relaunch')).toBeInTheDocument());
96+
return { host, onChange };
97+
}
98+
99+
/** The value one previewed column renders. */
100+
function previewValue(field: string): HTMLElement {
101+
const el = document.querySelector<HTMLElement>(`[data-lookup-preview="${field}"]`);
102+
if (!el) throw new Error(`no previewed value for ${field}`);
103+
return el;
104+
}
105+
106+
afterEach(() => {
107+
cleanup();
108+
vi.restoreAllMocks();
109+
});
110+
111+
describe('LookupField option preview: a record chip selects its option (objectstack#36479)', () => {
112+
// Touch (the phone the card was read on) and a mouse (a desktop) take the
113+
// same path: the defect was the link's click handler, not the pointer.
114+
it.each(['[TouchA]', '[MouseLeft]'])('%s on the chip selects the option and opens no record', async (keys) => {
115+
const { host, onChange } = await openPicker(['account']);
116+
const chip = await waitFor(() => {
117+
const el = previewValue('account').querySelector<HTMLElement>('[data-record-chip]');
118+
if (!el) throw new Error('the account column drew no chip');
119+
return el;
120+
});
121+
expect(chip).toHaveTextContent('Fabrikam');
122+
123+
const user = userEvent.setup();
124+
await user.pointer({ keys, target: chip });
125+
126+
expect(host.openRecord).not.toHaveBeenCalled();
127+
expect(onChange).toHaveBeenCalledTimes(1);
128+
expect(onChange.mock.calls[0][0]).toBe('prj_1');
129+
});
130+
131+
it('draws the chip with no anchor, so the option is the one click target', async () => {
132+
await openPicker(['account']);
133+
await waitFor(() =>
134+
expect(previewValue('account').querySelector('[data-record-chip]')).toHaveTextContent('Fabrikam'),
135+
);
136+
expect(screen.getByRole('option').querySelector('a')).toBeNull();
137+
});
138+
139+
it('draws a self-linking column with its text face, so a tap on it selects too', async () => {
140+
const { onChange } = await openPicker(['contact_email']);
141+
const value = previewValue('contact_email');
142+
await waitFor(() => expect(value).toHaveTextContent('pm@fabrikam.example.com'));
143+
144+
// Read before the pick: a pick closes the popover.
145+
const anchor = screen.getByRole('option').querySelector('a');
146+
147+
const user = userEvent.setup();
148+
// The element that carries the address's text: the anchor, before the fix.
149+
await user.click(within(value).getByText('pm@fabrikam.example.com'));
150+
151+
expect(onChange).toHaveBeenCalledTimes(1);
152+
expect(onChange.mock.calls[0][0]).toBe('prj_1');
153+
expect(anchor).toBeNull();
154+
});
155+
});

‎ui/packages/fields/src/widgets/lookupColumnDisplay.tsx‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import React from 'react';
3939
import { formatDate, getRecordDisplayName } from '@object-ui/core';
40+
import { RelatedRecordActionsProvider, useRelatedRecordActions } from '@object-ui/react';
4041
import type { LookupColumnDef } from '@object-ui/types';
4142
import { BooleanValueText } from './booleanValueLabel.js';
4243

@@ -167,9 +168,54 @@ export interface LookupColumnRenderContext {
167168
displayLocale?: string;
168169
}
169170

171+
/**
172+
* Cell renderer keys that draw their value as their OWN anchor without asking
173+
* the host — `mailto:`, a URL, `tel:`, and the file family's download link. A
174+
* candidate's column draws them with {@link PICKER_TEXT_FACE} instead: the
175+
* address, the URL, the number, the file's name.
176+
*/
177+
const PICKER_SELF_LINKING_CELL_TYPES: ReadonlySet<string> = new Set([
178+
'email',
179+
'url',
180+
'phone',
181+
'file',
182+
'video',
183+
'audio',
184+
]);
185+
186+
/** The cell renderer key a self-linking value is drawn with in a picker. */
187+
const PICKER_TEXT_FACE = 'text';
188+
189+
/**
190+
* The reference family (the lookup cell's `ReferencedRecordLink`, its hover
191+
* card) draws an anchor only when the host answers `recordHref`; under this
192+
* wrapper the host answers no record destination, which the context documents
193+
* as "render the plain value". Every other member of the host passes through;
194+
* with no host there is nothing to withhold.
195+
*/
196+
function WithoutRecordLinks({ children }: { children: React.ReactNode }): React.ReactElement {
197+
const host = useRelatedRecordActions();
198+
if (!host) return <>{children}</>;
199+
return (
200+
<RelatedRecordActionsProvider value={{ ...host, recordHref: undefined, openRecord: undefined }}>
201+
{children}
202+
</RelatedRecordActionsProvider>
203+
);
204+
}
205+
170206
/**
171207
* Render one column of one candidate record.
172208
*
209+
* A candidate's column is never a navigational link, on either picker surface:
210+
* the option row (the dropdown) or the table row (the browse-all dialog) is the
211+
* one click target, and a link inside it is a second one that competes with
212+
* the pick — a record chip opening its record, a `mailto:` opening the mail
213+
* client, instead of selecting the candidate (objectui#11903,
214+
* objectstack#36479). So a self-linking type is drawn with the text face
215+
* ({@link PICKER_SELF_LINKING_CELL_TYPES}), and every cell renders under a host
216+
* with no record destination ({@link WithoutRecordLinks}): a reference keeps
217+
* its face — the record page's chip included — without the anchor.
218+
*
173219
* Order:
174220
* 1. the record title, for the display column only and only when the
175221
* referenced object's schema is given: `getRecordDisplayName` with the
@@ -213,9 +259,15 @@ export function renderLookupColumnValue(
213259
// schema field's type via `fieldsMeta`) and a resolver are available.
214260
const descriptor = descriptors[col.field];
215261
if (descriptor && cellRenderer) {
216-
const Renderer = cellRenderer(descriptor.type);
262+
const Renderer = cellRenderer(
263+
PICKER_SELF_LINKING_CELL_TYPES.has(descriptor.type) ? PICKER_TEXT_FACE : descriptor.type,
264+
);
217265
if (Renderer) {
218-
return <Renderer value={val} field={descriptor} />;
266+
return (
267+
<WithoutRecordLinks>
268+
<Renderer value={val} field={descriptor} />
269+
</WithoutRecordLinks>
270+
);
219271
}
220272
}
221273

0 commit comments

Comments
 (0)