Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/36015-lookup-chip-opens-in-drawer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/components': patch
'@object-ui/fields': patch
'@object-ui/plugin-grid': patch
'@object-ui/plugin-list': patch
'@object-ui/app-shell': patch
---

feat(grid): on the list page a lookup chip opens its record in the side drawer, and a lookup cell has an edit button

Clause-②: yes (widening)
Metadata-protocol: none

On the console's list page, a single click on a lookup chip (a record of another object, such as a contact's account) now opens that record in the side drawer over the list. This replaces, for lookup chips on that page, the earlier change in this release where a plain click on a lookup chip only selected its cell. The list stays where it was: closing the drawer leaves its scroll position and the selected cell as they were. The drawer's address carries the record and its object (`?recordId=…&recordObject=…`), so a reload keeps it open and Back closes it, as with the name cell's "Open in side panel" icon. A click beside the chips only selects the cell. A cell of several chips opens the chip that was clicked; Ctrl/Cmd+Enter on the selected cell opens the first one in the drawer; Ctrl/Cmd-click still opens the record's page in a new tab.

A lookup cell now draws an edit (pencil) button while the pointer is over it and while it is selected. It opens the cell's editor, as a double-click or Enter does, and it is not drawn when the cell cannot be edited (no permission, a read-only field, a locked record). It takes the place of the open button a selected cell shows.

A chip naming a person (an owner, a creator: a lookup to `sys_user`) keeps the behaviour it had: a single click only selects the cell, and it opens from the open button or Ctrl/Cmd+Enter. Email, phone and URL cells and the name column are unchanged. On a phone every record still opens as its page.

For hosts: `ListView` and `ObjectGrid` take a new runtime prop, `openReferencedRecord(objectName, recordId)`, that opens such a record in the host's place; `GridCellSelection` gains an optional `referenceCells` member (`isReferenceColumn`, `openRecord`), exported with its type `GridReferenceCells` from `@object-ui/components`. A host that passes neither keeps the previous behaviour, where a chip only selects its cell. `ReferencedRecordLink`'s anchor now carries `data-record-object` and `data-record-id`.
22 changes: 15 additions & 7 deletions content/docs/frontend/plugins/plugin-grid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,21 @@ object and the view does not declare `userActions.editInline: false`, and

- **A click selects** a cell (a ring around it); it neither edits nor opens the
record. Only the name link keeps its own click (it opens the record). Every
other link a cell draws (an email, a phone number, a URL, a file, a lookup or
user chip, an image thumbnail) is selected by a click too (objectstack#36015);
to open it, Ctrl/Cmd-click it, press the **Open** button the selected cell
shows on hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the
first one that way. The email and phone cells draw no copy button here:
Ctrl/Cmd+C copies the selected cell. On a touch screen a tap opens the
record.
other link a cell draws (an email, a phone number, a URL, a file, a user
chip, an image thumbnail, and a lookup chip unless the host opens it in
place, below) is selected by a click too (objectstack#36015); to open it,
Ctrl/Cmd-click it, press the **Open** button the selected cell shows on
hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the first one
that way. The email and phone cells draw no copy button here: Ctrl/Cmd+C
copies the selected cell. On a touch screen a tap opens the record.
- **A lookup chip opens its record in place** when the host passes
`openReferencedRecord` (the console's list page opens it in the side drawer,
over the list): a single click on the chip opens that record, a click beside
it selects the cell, and Ctrl/Cmd+Enter opens the first chip the same way. A
lookup cell draws an **Edit** (pencil) button on hover and while selected,
which opens its editor; it is not drawn when the cell cannot be edited, and
it takes the place of the **Open** button. A chip naming a person (a lookup
to `sys_user`) keeps the click-selects behaviour above.
- **A cut-off value shows in full** when its cell is selected: a long text, a
multi-line text or a list of tags that the column truncates opens on a
layer over the cell, wrapped, scrolling inside past a few lines. Escape, an
Expand Down
9 changes: 9 additions & 0 deletions ui/packages/app-shell/src/urlParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
*/
export const RECORD_DRAWER_PARAM = 'recordId';

/**
* The object of the record the drawer's root shows, when it is not the
* listed object's (objectstack#36015): a lookup chip in the list opens the
* record it names in the list's drawer. Absent ⇒ the listed object. Read
* only beside {@link RECORD_DRAWER_PARAM}.
*/
export const RECORD_DRAWER_OBJECT_PARAM = 'recordObject';

/** Global record-form overlay: `new` | `<recordId>` (framework#2604). */
export const RECORD_FORM_PARAM = 'form';

Expand Down Expand Up @@ -156,6 +164,7 @@ export { NAV_RUN_ACTION_PARAM };
*/
export const RESERVED_URL_PARAMS: readonly string[] = [
RECORD_DRAWER_PARAM,
RECORD_DRAWER_OBJECT_PARAM,
RECORD_FORM_PARAM,
RECORD_FORM_OBJECT_PARAM,
RECORD_FORM_LINK_PARAM,
Expand Down
6 changes: 5 additions & 1 deletion ui/packages/app-shell/src/views/ObjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
// objectstack#27058 — on a phone the record is always a page: a row tap
// navigates to it, and no pane is mounted beside or over the list.
const phone = usePhoneViewport();
const { listRecordActions, navOverlay, handleDrawerClose, handleRowClick, handleOpenAsPage, handleOpenRowInPanel, drawerRoot, drawerRestore, handleListRowsChange, handleListTotalChange, handleRootStep, listLabel } = useObjectViewRecordNavigation({
const { listRecordActions, navOverlay, handleDrawerClose, handleRowClick, handleOpenAsPage, handleOpenRowInPanel, handleOpenReferencedRecord, drawerRoot, drawerRestore, handleListRowsChange, handleListTotalChange, handleRootStep, listLabel } = useObjectViewRecordNavigation({
activeView,
objectDef,
objects,
Expand All @@ -1073,6 +1073,9 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
: null),
[navOverlay.mode, phone, openInPanelLabel, handleOpenRowInPanel],
);
// objectstack#36015 — a lookup chip in the grid opens its record in the
// same side drawer, where this list has one.
const openReferencedRecord = navOverlay.mode === 'drawer' && !phone ? handleOpenReferencedRecord : undefined;

// objectstack#25992 slice 8: the `filter[...]` URL equality filters and the `uf_*`
// user-filter selections moved to `./objectViewListUrlState.ts`.
Expand Down Expand Up @@ -1188,6 +1191,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
handleListRowsChange,
handleListTotalChange,
openInPanel,
openReferencedRecord,
// objectstack#33317 — the resolved mode: `none` for an authored
// `none` and for a list-only object (`servesRecordRead`).
rowOpensRecord: navOverlay.mode !== 'none',
Expand Down
8 changes: 7 additions & 1 deletion ui/packages/app-shell/src/views/objectViewListRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function useObjectViewListRenderer({
handleListRowsChange,
handleListTotalChange,
openInPanel,
openReferencedRecord,
rowOpensRecord,
phoneTitle,
viewBarTrailing,
Expand Down Expand Up @@ -145,6 +146,8 @@ export function useObjectViewListRenderer({
handleListTotalChange: ReturnType<typeof useObjectViewRecordNavigation>['handleListTotalChange'];
/** objectstack#35854 — the name cell's 「在侧边打开」 (`./objectViewOpenAsPage.tsx`), or `null` for none. */
openInPanel: { label: string; open: (recordId: string | number) => void } | null;
/** objectstack#36015 — a lookup chip's record in the side drawer, or `undefined` where the list has none. */
openReferencedRecord: ((objectName: string, recordId: string) => void) | undefined;
/** objectstack#33317 — whether a row click opens the record: `false` for the `none` mode. */
rowOpensRecord: boolean;
/**
Expand Down Expand Up @@ -1183,6 +1186,9 @@ export function useObjectViewListRenderer({
: null;
}
: undefined}
// objectstack#36015 — a lookup chip in the grid opens the record it
// names in the same side drawer.
openReferencedRecord={openReferencedRecord}
// objectstack#33317 — a row that opens nothing (the view
// authored `navigation.mode: 'none'`, or a list-only object)
// draws no record link and no Open in its context menu.
Expand All @@ -1203,7 +1209,7 @@ export function useObjectViewListRenderer({
dataSource={ds}
/>
);
}, [hasViewBarTrailing, trailStore, rowEndStore, activeView, activeViewDeclaresColumns, activeViewIsSaved, objectDef, objectName, refreshKey, createRecord, urlFilters, initialUfSelections, handleUserFilterSelectionsChange, writeListUrlState, listPage, user?.id, pageOffersCreate, listAddRecordOpensCreate, listIdentityKey, listPrefs.ready, listPrefs.preference, listPrefs.patchView, listDraft.draft, listDraft.patch, managedUsers, managedUserMarker, openInPanel, rowOpensRecord, handleListRowsChange, handleListTotalChange, hasPhoneTitle, leadStore, wideViewport, handleListPersonalizationChange, workspaceTimeZone, viewPanelFilters, offersRename, offersSave, offersReset, offersSummaryPick, summaryPickKey, previewDrafts, previewDataSource, unpublishedObjects]);
}, [hasViewBarTrailing, trailStore, rowEndStore, activeView, activeViewDeclaresColumns, activeViewIsSaved, objectDef, objectName, refreshKey, createRecord, urlFilters, initialUfSelections, handleUserFilterSelectionsChange, writeListUrlState, listPage, user?.id, pageOffersCreate, listAddRecordOpensCreate, listIdentityKey, listPrefs.ready, listPrefs.preference, listPrefs.patchView, listDraft.draft, listDraft.patch, managedUsers, managedUserMarker, openInPanel, openReferencedRecord, rowOpensRecord, handleListRowsChange, handleListTotalChange, hasPhoneTitle, leadStore, wideViewport, handleListPersonalizationChange, workspaceTimeZone, viewPanelFilters, offersRename, offersSave, offersReset, offersSummaryPick, summaryPickKey, previewDrafts, previewDataSource, unpublishedObjects]);

return { renderListView };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import * as React from 'react';
import { describe, it, expect, vi } from 'vitest';
import { act, renderHook } from '@testing-library/react';
import { MemoryRouter, type Location } from 'react-router-dom';
import { MemoryRouter, useLocation, useNavigate, useSearchParams, type Location } from 'react-router-dom';

import { useObjectViewRecordNavigation } from './objectViewRecordNavigation';

Expand Down Expand Up @@ -82,3 +82,110 @@ describe('a page the list opens carries the list\'s rows (objectstack#27524, Tar
expect(lastState(navigate)).toEqual({ from: { pathname: '/apps/crm/crm_lead?view=all', label: 'All leads' } });
});
});

describe('a lookup chip opens the record it names in the list\'s drawer (objectstack#36015)', () => {
const OBJECTS = [{ name: 'crm_lead', label: 'Lead' }, { name: 'crm_account', label: 'Account' }];

function mountDrawer(search: string) {
const navigate = vi.fn();
const setSearchParams = vi.fn();
const { result } = renderHook(() =>
useObjectViewRecordNavigation({
activeView: { id: 'all', name: 'all', label: 'All leads' } as never,
objectDef: { name: 'crm_lead', label: 'Lead', fields: {} } as never,
objects: OBJECTS as never,
appName: 'crm',
viewId: undefined,
searchParams: new URLSearchParams(search),
setSearchParams,
location: { ...LIST, search: `?${search}` },
navigate,
routerRootHref: '/',
servedViews: { views: [], objects: [] } as never,
viewLabel: (_object: string, _view: string, fallback: string) => fallback,
unlabelledViewText: 'Untitled view',
language: 'en',
phone: false,
}),
{ wrapper: ({ children }: { children: React.ReactNode }) => <MemoryRouter initialEntries={[`/apps/crm/crm_lead?${search}`]}>{children}</MemoryRouter> },
);
act(() => result.current.handleListRowsChange(ROWS));
const lastParams = () => String(setSearchParams.mock.calls.at(-1)![0]);
return { result, navigate, lastParams, setSearchParams };
}

it('another object\'s record: its id and its object in the URL, beside the list\'s own params', () => {
const { result, lastParams } = mountDrawer('view=all');
act(() => result.current.handleOpenReferencedRecord('crm_account', 'a7'));
expect(lastParams()).toBe('view=all&recordId=a7&recordObject=crm_account');
});

it('the record the drawer already shows is not pushed again, so one Back still closes it', () => {
const foreign = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
act(() => foreign.result.current.handleOpenReferencedRecord('crm_account', 'a7'));
const own = mountDrawer('view=all&recordId=r-2');
act(() => own.result.current.handleOpenReferencedRecord('crm_lead', 'r-2'));
expect(foreign.setSearchParams).not.toHaveBeenCalled();
expect(own.setSearchParams).not.toHaveBeenCalled();
// The same id under another object is another record.
act(() => foreign.result.current.handleOpenReferencedRecord('crm_lead', 'a7'));
expect(foreign.lastParams()).toBe('view=all&recordId=a7');
});

it('in a router: a chip opened twice (a double-click) leaves one history entry, and one Back closes the drawer', () => {
// The console's declarative router pushes on every navigate, the same URL included.
function useRouted() {
const [searchParams, setSearchParams] = useSearchParams();
const location = useLocation();
const navigate = useNavigate();
const nav = useObjectViewRecordNavigation({
activeView: { id: 'all', name: 'all', label: 'All leads' } as never,
objectDef: { name: 'crm_lead', label: 'Lead', fields: {} } as never,
objects: OBJECTS as never,
appName: 'crm',
viewId: undefined,
searchParams,
setSearchParams,
location,
navigate,
routerRootHref: '/',
servedViews: { views: [], objects: [] } as never,
viewLabel: (_object: string, _view: string, fallback: string) => fallback,
unlabelledViewText: 'Untitled view',
language: 'en',
phone: false,
});
return { nav, search: location.search, back: () => navigate(-1) };
}
const { result } = renderHook(useRouted, {
wrapper: ({ children }: { children: React.ReactNode }) => <MemoryRouter initialEntries={['/apps/crm/crm_lead?view=all']}>{children}</MemoryRouter>,
});
act(() => result.current.nav.handleListRowsChange(ROWS));
act(() => result.current.nav.handleOpenReferencedRecord('crm_account', 'a7'));
act(() => result.current.nav.handleOpenReferencedRecord('crm_account', 'a7'));
expect(result.current.search).toBe('?view=all&recordId=a7&recordObject=crm_account');
act(() => result.current.back());
expect(result.current.search).toBe('?view=all');
});

it('a record of the listed object opens as the name cell\'s icon opens it, with no object param', () => {
const { result, lastParams } = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
act(() => result.current.handleOpenReferencedRecord('crm_lead', 'r-2'));
expect(lastParams()).toBe('view=all&recordId=r-2');
});

it('the drawer\'s root is that record, with no sibling set; an object the console does not know opens nothing', () => {
expect(mountDrawer('recordId=a7&recordObject=crm_account').result.current.drawerRoot).toEqual({ objectName: 'crm_account', recordId: 'a7' });
expect(mountDrawer('recordId=a7&recordObject=crm_unknown').result.current.drawerRoot).toBeNull();
// The listed object's row keeps its sibling set.
expect(mountDrawer('recordId=r-2').result.current.drawerRoot).toEqual({ objectName: 'crm_lead', recordId: 'r-2', siblings: ['r-1', 'r-2', 'r-3'] });
});

it('closing the drawer drops both params; its full-page button opens that object\'s page', () => {
const { result, navigate, lastParams } = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
act(() => result.current.handleDrawerClose());
expect(lastParams()).toBe('view=all');
act(() => result.current.handleOpenAsPage([{ objectName: 'crm_account', recordId: 'a7' }]));
expect(navigate).toHaveBeenLastCalledWith('/apps/crm/crm_account/record/a7');
});
});
Loading
Loading