Skip to content

Commit 9c225b5

Browse files
committed
fix(grid): a double-click on a lookup chip opens its record once, so one Back closes the drawer (#36015)
Both clicks of a double-click reached the select-first click capture, so the host's openRecord ran twice and the console's router pushed the same URL twice. The grid now opens a chip on a click's first press only, and the list page does not push the record its drawer already shows (a fast repeat click too). Claude-Session: https://claude.ai/code/session_01L6bhgWkLah49N6UoD4CS3S Co-authored-by: Claude <noreply@anthropic.com>
1 parent b59bf99 commit 9c225b5

4 files changed

Lines changed: 70 additions & 6 deletions

File tree

‎ui/packages/app-shell/src/views/objectViewRecordNavigation.listRows-27524.test.tsx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import * as React from 'react';
1313
import { describe, it, expect, vi } from 'vitest';
1414
import { act, renderHook } from '@testing-library/react';
15-
import { MemoryRouter, type Location } from 'react-router-dom';
15+
import { MemoryRouter, useLocation, useNavigate, useSearchParams, type Location } from 'react-router-dom';
1616

1717
import { useObjectViewRecordNavigation } from './objectViewRecordNavigation';
1818

@@ -111,7 +111,7 @@ describe('a lookup chip opens the record it names in the list\'s drawer (objects
111111
);
112112
act(() => result.current.handleListRowsChange(ROWS));
113113
const lastParams = () => String(setSearchParams.mock.calls.at(-1)![0]);
114-
return { result, navigate, lastParams };
114+
return { result, navigate, lastParams, setSearchParams };
115115
}
116116

117117
it('another object\'s record: its id and its object in the URL, beside the list\'s own params', () => {
@@ -120,6 +120,54 @@ describe('a lookup chip opens the record it names in the list\'s drawer (objects
120120
expect(lastParams()).toBe('view=all&recordId=a7&recordObject=crm_account');
121121
});
122122

123+
it('the record the drawer already shows is not pushed again, so one Back still closes it', () => {
124+
const foreign = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
125+
act(() => foreign.result.current.handleOpenReferencedRecord('crm_account', 'a7'));
126+
const own = mountDrawer('view=all&recordId=r-2');
127+
act(() => own.result.current.handleOpenReferencedRecord('crm_lead', 'r-2'));
128+
expect(foreign.setSearchParams).not.toHaveBeenCalled();
129+
expect(own.setSearchParams).not.toHaveBeenCalled();
130+
// The same id under another object is another record.
131+
act(() => foreign.result.current.handleOpenReferencedRecord('crm_lead', 'a7'));
132+
expect(foreign.lastParams()).toBe('view=all&recordId=a7');
133+
});
134+
135+
it('in a router: a chip opened twice (a double-click) leaves one history entry, and one Back closes the drawer', () => {
136+
// The console's declarative router pushes on every navigate, the same URL included.
137+
function useRouted() {
138+
const [searchParams, setSearchParams] = useSearchParams();
139+
const location = useLocation();
140+
const navigate = useNavigate();
141+
const nav = useObjectViewRecordNavigation({
142+
activeView: { id: 'all', name: 'all', label: 'All leads' } as never,
143+
objectDef: { name: 'crm_lead', label: 'Lead', fields: {} } as never,
144+
objects: OBJECTS as never,
145+
appName: 'crm',
146+
viewId: undefined,
147+
searchParams,
148+
setSearchParams,
149+
location,
150+
navigate,
151+
routerRootHref: '/',
152+
servedViews: { views: [], objects: [] } as never,
153+
viewLabel: (_object: string, _view: string, fallback: string) => fallback,
154+
unlabelledViewText: 'Untitled view',
155+
language: 'en',
156+
phone: false,
157+
});
158+
return { nav, search: location.search, back: () => navigate(-1) };
159+
}
160+
const { result } = renderHook(useRouted, {
161+
wrapper: ({ children }: { children: React.ReactNode }) => <MemoryRouter initialEntries={['/apps/crm/crm_lead?view=all']}>{children}</MemoryRouter>,
162+
});
163+
act(() => result.current.nav.handleListRowsChange(ROWS));
164+
act(() => result.current.nav.handleOpenReferencedRecord('crm_account', 'a7'));
165+
act(() => result.current.nav.handleOpenReferencedRecord('crm_account', 'a7'));
166+
expect(result.current.search).toBe('?view=all&recordId=a7&recordObject=crm_account');
167+
act(() => result.current.back());
168+
expect(result.current.search).toBe('?view=all');
169+
});
170+
123171
it('a record of the listed object opens as the name cell\'s icon opens it, with no object param', () => {
124172
const { result, lastParams } = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
125173
act(() => result.current.handleOpenReferencedRecord('crm_lead', 'r-2'));

‎ui/packages/app-shell/src/views/objectViewRecordNavigation.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,18 @@ export function useObjectViewRecordNavigation({
421421
* in the side drawer over the list, which stays — the same drawer and the
422422
* same URL state as the name cell's icon, its object beside `?recordId=`
423423
* when it is not the listed object. A chip clicked while the drawer is
424-
* open swaps its root record.
424+
* open swaps its root record. The record the drawer already shows is not
425+
* pushed again, so one Back still closes it after a double-click.
425426
*/
426427
const handleOpenReferencedRecord = useCallback((targetObjectName: string, recordId: string) => {
427-
if (targetObjectName === objectDef.name) {
428+
const { searchParams: params, setSearchParams: setParams, mode } = panelInputs.current;
429+
const own = targetObjectName === objectDef.name;
430+
const shownObject = params.get(RECORD_DRAWER_OBJECT_PARAM);
431+
if (params.get(RECORD_DRAWER_PARAM) === recordId && (own ? !shownObject || shownObject === objectDef.name : shownObject === targetObjectName)) return;
432+
if (own) {
428433
handleOpenRowInPanel(recordId);
429434
return;
430435
}
431-
const { searchParams: params, setSearchParams: setParams, mode } = panelInputs.current;
432436
if (mode !== 'drawer') return;
433437
const next = new URLSearchParams(params);
434438
next.set(RECORD_DRAWER_PARAM, recordId);

‎ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ describe('data-table select-first — a reference chip opens its record in place
431431
expect(t.editor()).toBeNull();
432432
});
433433

434+
it('a double-click on the chip opens its record once', () => {
435+
const t = renderReferences();
436+
const chipText = screen.getByText('Account acc_1');
437+
fireEvent.click(chipText, { detail: 1 });
438+
fireEvent.click(chipText, { detail: 2 });
439+
fireEvent.doubleClick(chipText, { detail: 2 });
440+
expect(t.openRecord).toHaveBeenCalledTimes(1);
441+
expect(t.openRecord).toHaveBeenCalledWith('crm_account', 'acc_1');
442+
expect(t.editor()).toBeNull();
443+
});
444+
434445
it('a click beside the chip only selects; a Ctrl or Cmd click follows the link', () => {
435446
const t = renderReferences();
436447
fireEvent.click(t.cell(1, 1));

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5219,7 +5219,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
52195219
selectCell(rowIndex, colIndex);
52205220
// A reference cell's chip opens its record in place: the
52215221
// list's side drawer, with the list and its selection kept.
5222-
const chip = isReferenceColumn(col) ? recordChipAt(e.target, e.currentTarget) : null;
5222+
// A double-click's second click opens it no second time.
5223+
const chip = isReferenceColumn(col) && e.detail <= 1 ? recordChipAt(e.target, e.currentTarget) : null;
52235224
if (chip && referenceCells) referenceCells.openRecord(chip.objectName, chip.recordId);
52245225
} : undefined}
52255226
onMouseDown={selectFirst ? (e) => {

0 commit comments

Comments
 (0)