Skip to content

Commit dca608a

Browse files
feat(grid): a lookup chip in a list cell opens its record in the side drawer; lookup cells draw an edit button (#36015) (#36128)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuLB1HMq57UcoRZFjpa8YhHZ)_ repo:objectstack#1 · os-sales · session_01L6bhgWkLah49N6UoD4CS3S Fixes #36015 The card's 11:13Z revision (maintainer: 「同意,改卡」): a single click on a lookup chip opens that record in the side drawer, and a lookup cell has a pencil button. #36033 landed the rest of the card with `Refs #36015`; this PR is the lookup-cell part and closes the card. Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 列表里单击关联记录的小标签(比如联系人列表里的「客户」),右侧抽屉打开那条记录,列表不动。关掉抽屉后,滚动位置和选中的格子都还在。 - 点格子里小标签旁边的空白,只是选中这一格。一格里有几个标签,点哪个开哪个;选中后按 Ctrl+Enter / Cmd+Enter 在抽屉里开第一个;按住 Ctrl / Cmd 点,仍是新标签页整页打开。 - 关联格在鼠标移上去或已选中时,右边出现铅笔按钮,点了进入编辑(出现关联记录选择器),和双击、回车一样。没有编辑权限、字段只读、记录被锁时不出现。这个位置原来放「打开」图标,关联格不再画它。 - 人员的小标签(负责人、创建人,指向 `sys_user` 的关联)不变:单击只选中,选中后有「打开」图标,没有铅笔。邮箱、电话、网址、名称列都不变。手机上照旧整页打开。 - 抽屉的网址带上了记录和它的对象(`?recordId=…&recordObject=…`):刷新后抽屉还在,按后退关掉抽屉,和名称列「在侧边打开」一样。 - 风险:改到五个包(字段格子、表格、网格、列表、控制台抽屉);给宿主加了两个可选接口,不传时行为和以前完全一样;没有新文案键(铅笔用已有的「编辑」`table.edit`)。 ## What changes On a grid with the select-first cell model whose host opts in (today the console's list page), a **reference cell** is a column of `lookup`, `master_detail` or `tree` type whose `reference` is not `sys_user`. **`@object-ui/fields`: `index.tsx`** - `ReferencedRecordLink`'s anchor carries `data-record-object` and `data-record-id`, the record the chip names. Nothing else changes in its markup or its click. **`@object-ui/components`: `context/gridCellSelection.tsx`, `index.ts`** - `GridCellSelection` gains an optional `referenceCells?: GridReferenceCells | null`. `GridReferenceCells` (exported as a type) is `isReferenceColumn(columnKey)` (asked per column on every render, so it answers from the column alone) and `openRecord(objectName, recordId)`. **`@object-ui/components`: `renderers/complex/data-table.tsx`, `dataTableCellSelection.ts`** - New `recordChipAt` / `firstRecordChip`: the record a chip (`a[data-record-link][data-record-object][data-record-id]`) at or around the target names. - In a reference cell, the select-first `onClickCapture` that #36033 added still cancels a plain click on the chip and selects the cell, and then calls `referenceCells.openRecord` for the chip clicked. A click beside the chips only selects. Ctrl, Cmd, Shift and Alt clicks, a non-primary button and a touch tap pass through to the link as before. - A double-click on a reference chip does not also edit the cell (its first click opened the record). - Ctrl/Cmd+Enter on a selected reference cell opens its first chip through `referenceCells.openRecord`; every other cell keeps #36033's behaviour. - New `CellEditButton` in every reference cell while no editor is open: a pencil at the cell's right edge, labelled with the existing `table.edit` key, shown on cell hover (`group-hover/cell`) and while the cell is selected. Its click calls `attemptEdit`, the same gate double-click and Enter pass through. It is drawn only when `readOnlyReasonOf(row, col)` is `null`; that is asked when the pointer enters the cell and when the cell becomes selected, never per render (the `describeCell` contract). It takes no focus. A reference cell does not draw #36033's `CellOpenButton`. **`@object-ui/plugin-grid`: `ObjectGrid.tsx`** - New runtime prop `openReferencedRecord?: (objectName, recordId) => void`. With `cellSelection` and this prop, the grid's `GridCellSelection` carries `referenceCells`: `isReferenceColumn` reads the column's field (`opensReferenceInPlace`: lookup / master_detail / tree, reference not `sys_user`), `openRecord` is the prop. **`@object-ui/plugin-list`: `ListView.tsx`** - New host prop `openReferencedRecord`, handed to the grid only (`object-grid` views), as `recordLinkAdornment` is. **`@object-ui/app-shell`: `urlParams.ts`, `views/objectViewRecordNavigation.ts`, `ObjectView.tsx`, `objectViewListRenderer.tsx`, `objectViewRecordOverlay.tsx`, `recordDrawerStack.tsx`** - New reserved URL param `RECORD_DRAWER_OBJECT_PARAM` (`recordObject`), listed in `RESERVED_URL_PARAMS`: the object of the drawer root's record when it is not the listed object. - `handleOpenReferencedRecord(objectName, recordId)`: the listed object's record opens as the name cell's 「在侧边打开」 icon opens it (`?recordId=` only); another object's sets `?recordId=` and `?recordObject=` (a push, so Back closes it). A chip clicked while the drawer is open swaps its root. - `drawerRoot` is that record when `?recordObject=` names another object the console knows and the server reads one record of (`servesRecordRead`); it has no sibling set, so the drawer draws no ↑ ↓ counter. Unknown or unread object: no drawer. - Closing the drawer, the name cell's icon and the page origin a phone redirect builds drop `?recordObject=` with `?recordId=`. - The drawer's ⤢ at a root of another object opens that object's page (`expandedRecordPath`); the listed object's root keeps its list-relative route and origin. - On a phone a `?recordObject=` link answers with that record's own page, as `?recordId=` does for the listed object. - `RecordStackDrawer` takes `listObjectName`; the list marks the root's row as active only when the root is a record of the listed object. - `ObjectView` passes `handleOpenReferencedRecord` only when its list has the drawer (`navOverlay.mode === 'drawer'`, not a phone), the same condition as `openInPanel`. A list whose rows open nothing (`none`, a list-only object) keeps #36033's behaviour: the chip only selects. **Field types this reaches:** `lookup`, `master_detail`, `tree` drawn through `LookupCellRenderer` / `ReferencedRecordLink`, when the referenced object is routable from the list (the chip is an anchor only then). A `user` field (`UserCellRenderer`, avatars) draws no link and is untouched. **Readings (claim A–G):** - **A.** Only grids whose host passes `openReferencedRecord` (the console's object list). Every other host keeps #36033's behaviour. - **B.** Ctrl/Cmd+Enter on a lookup cell opens its first chip in the drawer. - **C.** Person cells (lookups to `sys_user`) draw no pencil and keep #36033's open button. - **D.** A chip clicked with the drawer open swaps the drawer's root, as the name cell's icon does. - **E.** A lookup to the listed object itself opens the listed object's drawer, with `?recordId=` alone. - **F.** A chip with no link (unroutable, unread, restricted or name-only) only selects; an editable cell still draws the pencil. - **G.** The drawer's record and object live in the URL, as `?recordId=` does (ui `AGENTS.md` #8). Docs: `content/docs/frontend/plugins/plugin-grid.mdx` § On an object's list page (new bullet after the click bullet; the click bullet #36033 wrote now leaves out the lookup chip a host opens in place). #36033's changeset is untouched; this PR's own changeset says it (Notes, below). ## Notes - **#36033's pending release note is left as it is** (`.changeset/36015-list-cell-click-only-selects.md`, restored from the base in `87d42cbd`; head `b59bf991`..`9c225b51` had added a sentence to it as a declared correction, which kept `Check Changeset` red). This PR's own note, `.changeset/36015-lookup-chip-opens-in-drawer.md`, now says what it changes about that note instead: "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 docs bullet in `plugin-grid.mdx` keeps the L1-b N1 rewording. ## Tests Added, each a top-level `describe` in the component's existing harness file: - `components/src/__tests__/data-table-select-first-35684.test.tsx`, "a reference chip opens its record in place": a plain click on the chip calls `openRecord` with the chip's record, cancels the default and selects the cell, and a double-click on it opens no editor; a click beside the chip only selects, Ctrl and Cmd clicks follow the link; Ctrl+Enter opens the first chip through the host; the edit button is hidden until the pointer enters the cell, then shown on hover and while selected, opens the editor, and the cell draws no open button; a cell the host says opens no editor draws no edit button; a column the host does not name (a person) keeps the link behaviour and the open button; control: with no `referenceCells` the chip only selects and no edit button is drawn. - `plugin-grid/src/__tests__/ObjectGrid.cellSelection-35684.test.tsx`, "a lookup chip opens its record in the host's place": through `ObjectGrid` with a routing host, the account chip carries `data-record-object` / `data-record-id` and a single click calls `openReferencedRecord('crm_account', 'a7')` without following the link; the lookup cell's edit button opens its editor and the `owner_id` (lookup to `sys_user`) cell draws none; a person chip only selects; control without the prop. - `app-shell/src/views/objectViewRecordNavigation.listRows-27524.test.tsx`, "a lookup chip opens the record it names in the list's drawer": the URL params for another object and for the listed object, `drawerRoot` for another object (no siblings), for an unknown object (`null`) and for the listed object (siblings kept), close drops both params, ⤢ opens the other object's page. - After L1-b's S1 (fixed in `9c225b51`: a double-click on a chip opened its record twice, so the console's router pushed the same URL twice and the first Back left the drawer open). The grid opens a chip on a click's first press only (`e.detail > 1` opens nothing), and `handleOpenReferencedRecord` returns when the URL already names that record of that object, which also covers a fast repeat click. Each test below fails without the fix: - `data-table-select-first-35684.test.tsx`, "a double-click on the chip opens its record once": click, click (`detail: 2`), dblclick; `openRecord` is called once and no editor opens. - `objectViewRecordNavigation.listRows-27524.test.tsx`, "the record the drawer already shows is not pushed again": no `setSearchParams` for the record already shown, of another object or of the listed one; the same id under another object still opens. - same file, "in a router: a chip opened twice (a double-click) leaves one history entry, and one Back closes the drawer": a declarative `MemoryRouter` (it pushes on every navigate, the same URL included); after two opens the URL names the record, and one `navigate(-1)` returns to `?view=all`. No existing test was rewritten or dropped. Local runs. First on main `8145424b` merged with #36033's head `cefd3e31`, a full `pnpm build`: - `vitest run packages/components/`: 501 files passed. `packages/fields/`: 316 passed. `packages/plugin-grid/`: 298 passed. `packages/plugin-list/`: 181 passed. - `packages/app-shell/` in full did not finish inside this container's 50-minute window; the parts this diff touches ran: `src/views/ObjectView*`, `src/views/objectView*`, `src/views/__tests__/recordDrawer*`, `src/views/__tests__/recordPane*`, `src/urlParams*`, `src/__tests__/`: 128 files passed. - After #36033 merged, the change was replayed on main `dc10b3b4` as one commit (conflicts only in `objectViewListRenderer.tsx`'s memo dependencies and the two appended describes of `ObjectGrid.cellSelection-35684.test.tsx`, both sides kept), then a full `pnpm build` and `vitest run` of `components/src/__tests__/data-table*`, `plugin-grid/src/__tests__/ObjectGrid.cellSelection*`, `app-shell/src/views/objectViewRecordNavigation*`, `app-shell/src/views/__tests__/recordDrawer*` and `fields/src/`: 348 files passed (2 skipped). - `type-check` in `components`, `fields`, `plugin-grid`, `plugin-list`, `app-shell`: exit 0 (on both bases). - `eslint` on the changed files: 0 errors. - `overlap-check` on the pushed head `b59bf991`: clean against `origin/main` (`dc10b3b4`, #36033 merged) and the four open PRs sharing a file (#36114, #36105, #36096, #36024). - `87d42cbd`: `main` `6c7c6db2` merged in (clean). `check-empty-changeset` and `check-changeset-no-major`: pass. `overlap-check`: clean against `main` and #36123; #36133 (draft) conflicts only on the one-line `useMemo` dependency list in `objectViewListRenderer.tsx`, which each PR extends by one name; the second to land merges `main`. ## Verification (browser) CRM and Todo examples (`--fresh`), Console via Vite on this tree, Chromium, 1280 light and dark, 375 light and dark. Screenshots and the journey log: project folder `build-seat1/36015/PR2/` (`after-*`, `after-journey.log`). The before state is #36033's after state (`build-seat1/36015/after-*`): a chip only selected its cell. | Step | After | |:--|:--| | Contacts, hover the Account cell | pencil at the cell's right edge | | Click the Acme Corp chip | drawer opens Acme Corp (`?recordId=…&recordObject=crm_account`), the list stays, the cell is selected | | Close the drawer | params gone, the Account cell still selected | | Click beside the chip | cell selected, nothing opens | | Click the pencil | the lookup editor opens in the cell | | Ctrl+Enter on the selected Account cell | drawer opens Acme Corp | | Click the email text | cell selected, no navigation, open button in the cell | | Click the name | the contact's record page | | Todo tasks, hover the Assigned To cell (lookup to `sys_user`) | no pencil | | Click the Dev Admin chip | cell selected, page stays, open button on hover | | 375 | phone cards (no grid), unchanged | ## Acceptance notes 1. Click a lookup chip: the drawer opens that record, the list stays, closing it keeps scroll and selection: yes (browser). 2. Click beside the chip: the cell is selected, nothing opens: yes. 3. Hover a lookup cell: a pencil; it opens the cell's editor (the lookup picker); none on a read-only field: yes (browser for the pencil and the editor; read-only unit-pinned). 4. Person chips (owner): single click only selects: yes (browser, Todo's Assigned To, a lookup to `sys_user`). 5. Ctrl/Cmd-click a chip opens the record in a new tab: yes (the click passes through to the anchor; unit-pinned). 6. Email, phone, URL, Ctrl/Cmd+Enter on them and the name column: unchanged from #36033: yes. 7. This body lists the field types reached and the tests: above (none rewritten). --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgWkLah49N6UoD4CS3S)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgWkLah49N6UoD4CS3S <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgWkLah49N6UoD4CS3S --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 59b5779 commit dca608a

18 files changed

Lines changed: 665 additions & 25 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/fields': patch
4+
'@object-ui/plugin-grid': patch
5+
'@object-ui/plugin-list': patch
6+
'@object-ui/app-shell': patch
7+
---
8+
9+
feat(grid): on the list page a lookup chip opens its record in the side drawer, and a lookup cell has an edit button
10+
11+
Clause-②: yes (widening)
12+
Metadata-protocol: none
13+
14+
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.
15+
16+
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.
17+
18+
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.
19+
20+
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`.

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,21 @@ object and the view does not declare `userActions.editInline: false`, and
398398

399399
- **A click selects** a cell (a ring around it); it neither edits nor opens the
400400
record. Only the name link keeps its own click (it opens the record). Every
401-
other link a cell draws (an email, a phone number, a URL, a file, a lookup or
402-
user chip, an image thumbnail) is selected by a click too (objectstack#36015);
403-
to open it, Ctrl/Cmd-click it, press the **Open** button the selected cell
404-
shows on hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the
405-
first one that way. The email and phone cells draw no copy button here:
406-
Ctrl/Cmd+C copies the selected cell. On a touch screen a tap opens the
407-
record.
401+
other link a cell draws (an email, a phone number, a URL, a file, a user
402+
chip, an image thumbnail, and a lookup chip unless the host opens it in
403+
place, below) is selected by a click too (objectstack#36015); to open it,
404+
Ctrl/Cmd-click it, press the **Open** button the selected cell shows on
405+
hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the first one
406+
that way. The email and phone cells draw no copy button here: Ctrl/Cmd+C
407+
copies the selected cell. On a touch screen a tap opens the record.
408+
- **A lookup chip opens its record in place** when the host passes
409+
`openReferencedRecord` (the console's list page opens it in the side drawer,
410+
over the list): a single click on the chip opens that record, a click beside
411+
it selects the cell, and Ctrl/Cmd+Enter opens the first chip the same way. A
412+
lookup cell draws an **Edit** (pencil) button on hover and while selected,
413+
which opens its editor; it is not drawn when the cell cannot be edited, and
414+
it takes the place of the **Open** button. A chip naming a person (a lookup
415+
to `sys_user`) keeps the click-selects behaviour above.
408416
- **A cut-off value shows in full** when its cell is selected: a long text, a
409417
multi-line text or a list of tags that the column truncates opens on a
410418
layer over the cell, wrapped, scrolling inside past a few lines. Escape, an

‎ui/packages/app-shell/src/urlParams.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
8585
*/
8686
export const RECORD_DRAWER_PARAM = 'recordId';
8787

88+
/**
89+
* The object of the record the drawer's root shows, when it is not the
90+
* listed object's (objectstack#36015): a lookup chip in the list opens the
91+
* record it names in the list's drawer. Absent ⇒ the listed object. Read
92+
* only beside {@link RECORD_DRAWER_PARAM}.
93+
*/
94+
export const RECORD_DRAWER_OBJECT_PARAM = 'recordObject';
95+
8896
/** Global record-form overlay: `new` | `<recordId>` (framework#2604). */
8997
export const RECORD_FORM_PARAM = 'form';
9098

@@ -156,6 +164,7 @@ export { NAV_RUN_ACTION_PARAM };
156164
*/
157165
export const RESERVED_URL_PARAMS: readonly string[] = [
158166
RECORD_DRAWER_PARAM,
167+
RECORD_DRAWER_OBJECT_PARAM,
159168
RECORD_FORM_PARAM,
160169
RECORD_FORM_OBJECT_PARAM,
161170
RECORD_FORM_LINK_PARAM,

‎ui/packages/app-shell/src/views/ObjectView.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
10471047
// objectstack#27058 — on a phone the record is always a page: a row tap
10481048
// navigates to it, and no pane is mounted beside or over the list.
10491049
const phone = usePhoneViewport();
1050-
const { listRecordActions, navOverlay, handleDrawerClose, handleRowClick, handleOpenAsPage, handleOpenRowInPanel, drawerRoot, drawerRestore, handleListRowsChange, handleListTotalChange, handleRootStep, listLabel } = useObjectViewRecordNavigation({
1050+
const { listRecordActions, navOverlay, handleDrawerClose, handleRowClick, handleOpenAsPage, handleOpenRowInPanel, handleOpenReferencedRecord, drawerRoot, drawerRestore, handleListRowsChange, handleListTotalChange, handleRootStep, listLabel } = useObjectViewRecordNavigation({
10511051
activeView,
10521052
objectDef,
10531053
objects,
@@ -1073,6 +1073,9 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
10731073
: null),
10741074
[navOverlay.mode, phone, openInPanelLabel, handleOpenRowInPanel],
10751075
);
1076+
// objectstack#36015 — a lookup chip in the grid opens its record in the
1077+
// same side drawer, where this list has one.
1078+
const openReferencedRecord = navOverlay.mode === 'drawer' && !phone ? handleOpenReferencedRecord : undefined;
10761079

10771080
// objectstack#25992 slice 8: the `filter[...]` URL equality filters and the `uf_*`
10781081
// user-filter selections moved to `./objectViewListUrlState.ts`.
@@ -1188,6 +1191,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
11881191
handleListRowsChange,
11891192
handleListTotalChange,
11901193
openInPanel,
1194+
openReferencedRecord,
11911195
// objectstack#33317 — the resolved mode: `none` for an authored
11921196
// `none` and for a list-only object (`servesRecordRead`).
11931197
rowOpensRecord: navOverlay.mode !== 'none',

‎ui/packages/app-shell/src/views/objectViewListRenderer.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function useObjectViewListRenderer({
101101
handleListRowsChange,
102102
handleListTotalChange,
103103
openInPanel,
104+
openReferencedRecord,
104105
rowOpensRecord,
105106
phoneTitle,
106107
viewBarTrailing,
@@ -145,6 +146,8 @@ export function useObjectViewListRenderer({
145146
handleListTotalChange: ReturnType<typeof useObjectViewRecordNavigation>['handleListTotalChange'];
146147
/** objectstack#35854 — the name cell's 「在侧边打开」 (`./objectViewOpenAsPage.tsx`), or `null` for none. */
147148
openInPanel: { label: string; open: (recordId: string | number) => void } | null;
149+
/** objectstack#36015 — a lookup chip's record in the side drawer, or `undefined` where the list has none. */
150+
openReferencedRecord: ((objectName: string, recordId: string) => void) | undefined;
148151
/** objectstack#33317 — whether a row click opens the record: `false` for the `none` mode. */
149152
rowOpensRecord: boolean;
150153
/**
@@ -1183,6 +1186,9 @@ export function useObjectViewListRenderer({
11831186
: null;
11841187
}
11851188
: undefined}
1189+
// objectstack#36015 — a lookup chip in the grid opens the record it
1190+
// names in the same side drawer.
1191+
openReferencedRecord={openReferencedRecord}
11861192
// objectstack#33317 — a row that opens nothing (the view
11871193
// authored `navigation.mode: 'none'`, or a list-only object)
11881194
// draws no record link and no Open in its context menu.
@@ -1203,7 +1209,7 @@ export function useObjectViewListRenderer({
12031209
dataSource={ds}
12041210
/>
12051211
);
1206-
}, [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]);
1212+
}, [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]);
12071213

12081214
return { renderListView };
12091215
}

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

Lines changed: 108 additions & 1 deletion
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

@@ -82,3 +82,110 @@ describe('a page the list opens carries the list\'s rows (objectstack#27524, Tar
8282
expect(lastState(navigate)).toEqual({ from: { pathname: '/apps/crm/crm_lead?view=all', label: 'All leads' } });
8383
});
8484
});
85+
86+
describe('a lookup chip opens the record it names in the list\'s drawer (objectstack#36015)', () => {
87+
const OBJECTS = [{ name: 'crm_lead', label: 'Lead' }, { name: 'crm_account', label: 'Account' }];
88+
89+
function mountDrawer(search: string) {
90+
const navigate = vi.fn();
91+
const setSearchParams = vi.fn();
92+
const { result } = renderHook(() =>
93+
useObjectViewRecordNavigation({
94+
activeView: { id: 'all', name: 'all', label: 'All leads' } as never,
95+
objectDef: { name: 'crm_lead', label: 'Lead', fields: {} } as never,
96+
objects: OBJECTS as never,
97+
appName: 'crm',
98+
viewId: undefined,
99+
searchParams: new URLSearchParams(search),
100+
setSearchParams,
101+
location: { ...LIST, search: `?${search}` },
102+
navigate,
103+
routerRootHref: '/',
104+
servedViews: { views: [], objects: [] } as never,
105+
viewLabel: (_object: string, _view: string, fallback: string) => fallback,
106+
unlabelledViewText: 'Untitled view',
107+
language: 'en',
108+
phone: false,
109+
}),
110+
{ wrapper: ({ children }: { children: React.ReactNode }) => <MemoryRouter initialEntries={[`/apps/crm/crm_lead?${search}`]}>{children}</MemoryRouter> },
111+
);
112+
act(() => result.current.handleListRowsChange(ROWS));
113+
const lastParams = () => String(setSearchParams.mock.calls.at(-1)![0]);
114+
return { result, navigate, lastParams, setSearchParams };
115+
}
116+
117+
it('another object\'s record: its id and its object in the URL, beside the list\'s own params', () => {
118+
const { result, lastParams } = mountDrawer('view=all');
119+
act(() => result.current.handleOpenReferencedRecord('crm_account', 'a7'));
120+
expect(lastParams()).toBe('view=all&recordId=a7&recordObject=crm_account');
121+
});
122+
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+
171+
it('a record of the listed object opens as the name cell\'s icon opens it, with no object param', () => {
172+
const { result, lastParams } = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
173+
act(() => result.current.handleOpenReferencedRecord('crm_lead', 'r-2'));
174+
expect(lastParams()).toBe('view=all&recordId=r-2');
175+
});
176+
177+
it('the drawer\'s root is that record, with no sibling set; an object the console does not know opens nothing', () => {
178+
expect(mountDrawer('recordId=a7&recordObject=crm_account').result.current.drawerRoot).toEqual({ objectName: 'crm_account', recordId: 'a7' });
179+
expect(mountDrawer('recordId=a7&recordObject=crm_unknown').result.current.drawerRoot).toBeNull();
180+
// The listed object's row keeps its sibling set.
181+
expect(mountDrawer('recordId=r-2').result.current.drawerRoot).toEqual({ objectName: 'crm_lead', recordId: 'r-2', siblings: ['r-1', 'r-2', 'r-3'] });
182+
});
183+
184+
it('closing the drawer drops both params; its full-page button opens that object\'s page', () => {
185+
const { result, navigate, lastParams } = mountDrawer('view=all&recordId=a7&recordObject=crm_account');
186+
act(() => result.current.handleDrawerClose());
187+
expect(lastParams()).toBe('view=all');
188+
act(() => result.current.handleOpenAsPage([{ objectName: 'crm_account', recordId: 'a7' }]));
189+
expect(navigate).toHaveBeenLastCalledWith('/apps/crm/crm_account/record/a7');
190+
});
191+
});

0 commit comments

Comments
 (0)