From 93040f95610ec1cf6d2ef9df80f31eb9a37b1cc3 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 14:38:32 +0000 Subject: [PATCH 01/14] wip(ui): name opens the page, hover icon opens the side drawer; drawer is a floating card Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6Cbrs4FaLzn1HMmRDi1 --- .../src/utils/recordOpenPreference.test.ts | 87 ------- .../src/utils/recordOpenPreference.ts | 121 ---------- .../app-shell/src/views/ObjectView.tsx | 48 +--- .../src/views/objectViewListRenderer.tsx | 29 ++- .../src/views/objectViewOpenAsPage.tsx | 93 +++----- .../src/views/objectViewRecordNavigation.ts | 222 +++++++++--------- .../src/views/objectViewRecordOverlay.tsx | 9 +- .../app-shell/src/views/recordDrawerStack.tsx | 214 +++++------------ .../src/custom/navigation-overlay.tsx | 135 ++++------- ui/packages/plugin-list/src/ListView.tsx | 18 -- .../src/components/ViewSettingsPopover.tsx | 119 +--------- 11 files changed, 281 insertions(+), 814 deletions(-) delete mode 100644 ui/packages/app-shell/src/utils/recordOpenPreference.test.ts delete mode 100644 ui/packages/app-shell/src/utils/recordOpenPreference.ts diff --git a/ui/packages/app-shell/src/utils/recordOpenPreference.test.ts b/ui/packages/app-shell/src/utils/recordOpenPreference.test.ts deleted file mode 100644 index c9b67c8b200..00000000000 --- a/ui/packages/app-shell/src/utils/recordOpenPreference.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -/** - * ObjectUI - * Copyright (c) 2024-present ObjectStack Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** - * objectstack#26677 — the reader's record-open preference, read side. - * - * How a drawer-mode record opens is a reader's own choice, kept per browser - * under `os:record-open-mode`. These rows pin what the console reads: the - * values it knows, and the default for everything else — no value, an - * unknown one, no storage, a storage that throws. objectstack#28915: the - * drawer is the default, the split pane retired, and a stored `split` is an - * unknown value like any other (no compatibility read). - */ - -import { describe, it, expect } from 'vitest'; -import { - DEFAULT_RECORD_OPEN_PREFERENCE, - RECORD_OPEN_PREFERENCE_KEY, - readRecordOpenPreference, - writeRecordOpenPreference, -} from './recordOpenPreference'; - -const storageWith = (value: string | null) => ({ getItem: (key: string) => (key === RECORD_OPEN_PREFERENCE_KEY ? value : null) }); - -describe('readRecordOpenPreference (objectstack#26677)', () => { - it('the key and the default are the ones the Display-menu control will write against', () => { - expect(RECORD_OPEN_PREFERENCE_KEY).toBe('os:record-open-mode'); - expect(DEFAULT_RECORD_OPEN_PREFERENCE).toBe('drawer'); - }); - - it('reads the two values it knows', () => { - expect(readRecordOpenPreference(storageWith('drawer'))).toBe('drawer'); - expect(readRecordOpenPreference(storageWith('page'))).toBe('page'); - }); - - it('answers the drawer for no value, an unknown value, or a retired mode name — a stored `split` included', () => { - expect(readRecordOpenPreference(storageWith(null))).toBe('drawer'); - expect(readRecordOpenPreference(storageWith('split'))).toBe('drawer'); - expect(readRecordOpenPreference(storageWith('modal'))).toBe('drawer'); - expect(readRecordOpenPreference(storageWith('PAGE'))).toBe('drawer'); - }); - - it('answers the drawer with no storage, and with a storage that throws', () => { - expect(readRecordOpenPreference(null)).toBe('drawer'); - const throwing = { getItem: () => { throw new Error('SecurityError'); } }; - expect(readRecordOpenPreference(throwing)).toBe('drawer'); - }); - - it('with no `window` at all (SSR — this file runs in the node project), the default storage is absent: the drawer', () => { - // The browser's own `localStorage` is read by the console's object page; - // `ObjectView.recordOpenPreference-26677.test.tsx` drives that path. - expect(typeof window).toBe('undefined'); - expect(readRecordOpenPreference()).toBe('drawer'); - }); -}); - -describe('writeRecordOpenPreference (objectstack#26681)', () => { - /** A storage double that keeps what it is handed. */ - const memoryStorage = () => { - const kept = new Map(); - return { - getItem: (key: string) => kept.get(key) ?? null, - setItem: (key: string, value: string) => void kept.set(key, value), - }; - }; - - it('keeps the choice under the key the read side reads', () => { - const storage = memoryStorage(); - writeRecordOpenPreference('page', storage); - expect(storage.getItem(RECORD_OPEN_PREFERENCE_KEY)).toBe('page'); - expect(readRecordOpenPreference(storage)).toBe('page'); - writeRecordOpenPreference('drawer', storage); - expect(storage.getItem(RECORD_OPEN_PREFERENCE_KEY)).toBe('drawer'); - expect(readRecordOpenPreference(storage)).toBe('drawer'); - }); - - it('writes nothing and throws nothing with no storage, or with a storage that refuses the write', () => { - expect(() => writeRecordOpenPreference('page', null)).not.toThrow(); - const refusing = { setItem: () => { throw new Error('QuotaExceededError'); } }; - expect(() => writeRecordOpenPreference('page', refusing)).not.toThrow(); - }); -}); diff --git a/ui/packages/app-shell/src/utils/recordOpenPreference.ts b/ui/packages/app-shell/src/utils/recordOpenPreference.ts deleted file mode 100644 index 76c2c533cc7..00000000000 --- a/ui/packages/app-shell/src/utils/recordOpenPreference.ts +++ /dev/null @@ -1,121 +0,0 @@ -/** - * ObjectUI - * Copyright (c) 2024-present ObjectStack Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { - defineWorkspacePreference, - readWorkspacePreference, - useWorkspacePreference, - writeWorkspacePreference, - workspacePreferenceStorage, -} from './workspacePreference.js'; - -/** - * How the console's object page opens a record a reader clicks, when the - * object opens its records in the drawer — a READER's own preference, not - * metadata (objectstack#26677). - * - * The maintainer's record-page model: an object opens its records one way — - * the drawer, which expands to the full page, by default, or the full page - * where the object declares `navigation.mode: 'page'`. A reader of a drawer - * object chooses between two: `drawer` draws the record in the drawer over - * the list, which keeps its full width, and `page` opens the full page. - * - * The drawer is the default (objectstack#28915, maintainer ruling - * 2026-11-02: 「默认改抽屉,分屏彻底退役,只留抽屉和整页」). The pane beside - * the list that objectstack#27545 made the default is retired: a stored - * `split` is an unknown value like any other and reads as the default, with - * no compatibility read. - * - * Both sides live here: {@link readRecordOpenPreference} and - * {@link writeRecordOpenPreference}, and {@link useRecordOpenPreference}, the - * live pair the object page reads — the Display menu's 「打开记录」 control - * writes through it and the next row click opens the new way, with no reload - * (objectstack#26681). - * - * Read per browser: the value lives in `localStorage` under - * {@link RECORD_OPEN_PREFERENCE_KEY}, across objects. An absent value, an - * unknown one, a host with no `window` (SSR), or a storage that throws - * (private mode, a blocked origin) all answer {@link DEFAULT_RECORD_OPEN_PREFERENCE}. - * It never overrides a declaration: an object whose resolved mode is `page`, - * `new_window` or `none` ignores it, because the host reads it only for a - * drawer-mode record. - * - * A thin alias over the console's one preference store, - * `workspacePreference.ts` (objectstack#27052): the preference is - * {@link RECORD_OPEN_PREFERENCE} there, in the `user` scope, and it keeps the - * spelling it was first stored with — a bare `drawer` / `page` under - * {@link RECORD_OPEN_PREFERENCE_KEY} — so a reader's earlier choice reads - * back unchanged. - */ -export type RecordOpenPreference = 'drawer' | 'page'; - -/** The `localStorage` key the preference is kept under. */ -export const RECORD_OPEN_PREFERENCE_KEY = 'os:record-open-mode'; - -/** What a reader who never chose gets: the drawer over the list. */ -export const DEFAULT_RECORD_OPEN_PREFERENCE: RecordOpenPreference = 'drawer'; - -/** The storage surface this module reads — `localStorage`, or a test double. */ -export type RecordOpenPreferenceStorage = Pick; - -/** The storage surface this module writes — `localStorage`, or a test double. */ -export type RecordOpenPreferenceWriteStorage = Pick; - -/** - * The preference in the console's store: one key for every object (`user` - * scope), stored as the bare value. Any other stored spelling — an unknown - * value, a retired mode name, another case — is no choice. - */ -export const RECORD_OPEN_PREFERENCE = defineWorkspacePreference({ - name: 'record.open-mode', - storageKey: () => RECORD_OPEN_PREFERENCE_KEY, - codec: { - decode: (stored) => (stored === 'drawer' || stored === 'page' ? stored : undefined), - encode: (value) => value, - }, -}); - -/** - * The reader's record-open preference, or {@link DEFAULT_RECORD_OPEN_PREFERENCE} - * when none is stored, the stored value is not one of the two (a retired - * `split` included), or there is no readable storage. `storage` defaults to - * the browser's `localStorage`; `null` says there is none. - */ -export function readRecordOpenPreference( - storage: RecordOpenPreferenceStorage | null = workspacePreferenceStorage(), -): RecordOpenPreference { - return readWorkspacePreference(RECORD_OPEN_PREFERENCE, 'user', storage) ?? DEFAULT_RECORD_OPEN_PREFERENCE; -} - -/** - * Keep the reader's choice. `storage` defaults to the browser's - * `localStorage`; `null` says there is none. With no storage, or one that - * refuses the write, nothing is kept and nothing throws: the choice holds on - * this page, through {@link useRecordOpenPreference}, and the next page load - * reads the default. - * - * Every live {@link useRecordOpenPreference} on this page hears the write; - * another tab of the same origin hears it through the browser's `storage` - * event. - */ -export function writeRecordOpenPreference( - next: RecordOpenPreference, - storage: RecordOpenPreferenceWriteStorage | null = workspacePreferenceStorage(), -): void { - writeWorkspacePreference(RECORD_OPEN_PREFERENCE, 'user', next, storage); -} - -/** - * The reader's record-open preference as live state, and the setter the - * Display menu writes it with (objectstack#26681). A write here, in another - * component of this page, or in another tab re-renders every caller, so the - * object page opens the next record the way the reader just chose. - */ -export function useRecordOpenPreference(): [RecordOpenPreference, (next: RecordOpenPreference) => void] { - return useWorkspacePreference(RECORD_OPEN_PREFERENCE, 'user', DEFAULT_RECORD_OPEN_PREFERENCE); -} diff --git a/ui/packages/app-shell/src/views/ObjectView.tsx b/ui/packages/app-shell/src/views/ObjectView.tsx index 4c24e16db0a..909812e8770 100644 --- a/ui/packages/app-shell/src/views/ObjectView.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.tsx @@ -52,10 +52,8 @@ import { IdentityImportOptions, IdentityImportResultExtra, identityImportFields import { ManagedUsersInviteLine } from './managedEnvironmentUsers.js'; import { importTargetFields } from './importTargetFields.js'; import { resolveViewId } from '../utils/resolveViewId.js'; -import { useRecordOpenPreference } from '../utils/recordOpenPreference.js'; import { usePhoneViewport } from '../hooks/usePhoneViewport.js'; import { LIST_PINNED_VIEW_PREFERENCE, objectPreferenceScope, useWorkspacePreference } from '../utils/workspacePreference.js'; -import type { ListViewProps } from '@object-ui/plugin-list'; import { defaultListViewId, viewRowId } from '../utils/viewIdentity.js'; import { useObjectActions } from '../hooks/useObjectActions.js'; import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n'; @@ -928,19 +926,12 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co // objectstack#25992 slice 6: the record navigation overlay (drawer state in the // URL, row click, open as page, record links) moved to `./objectViewRecordNavigation.ts`. - // objectstack#26677 — how a drawer-mode record opens is a READER's - // preference, not a `navigation.mode`: the drawer (the default) or the - // full page. Live state: the Display menu's Open records section writes it - // (objectstack#26681) and the next row click opens the new way. It applies - // only to a record that opens in the drawer: an object that declares - // `page` (or `new_window` / `none`) keeps its declaration. objectstack#28915 - // — the pane beside the list retired, so the drawer is the default and the - // list under it keeps its full width. - const [recordOpenPreference, setRecordOpenPreference] = useRecordOpenPreference(); + // objectstack#35854 — one rule, no setting: the record's name opens the + // full page, the name cell's hover icon the side drawer over the list. // 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, handleOpenRowAsPage, drawerRoot, drawerRestore, handleListRowsChange, handleRootStep, listLabel } = useObjectViewRecordNavigation({ + const { listRecordActions, navOverlay, handleDrawerClose, handleRowClick, handleOpenAsPage, handleOpenRowInPanel, drawerRoot, drawerRestore, handleListRowsChange, handleListTotalChange, handleRootStep, listLabel } = useObjectViewRecordNavigation({ activeView, objectDef, objects, @@ -955,31 +946,16 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co viewLabel, unlabelledViewText, language, - recordOpenPreference, phone, }); - // objectstack#26681 — the Display menu's Open records section: the mode this - // object and view resolved to, and the reader's preference with its setter: - // the drawer or the full page (objectstack#27545, objectstack#28915). A - // reader who prefers the page still gets the drawer for a `?recordId=` - // link. Not on a phone, where every record is a page (objectstack#27058). - const recordOpen = useMemo( - () => (phone ? undefined : { - resolvedMode: navOverlay.mode, - preference: recordOpenPreference, - setPreference: setRecordOpenPreference, - }), - [phone, navOverlay.mode, recordOpenPreference, setRecordOpenPreference], - ); - // objectstack#26681 — the name cell's ↗, "open as full page", for a row that - // opens the drawer. A `page` object's row - // already opens the page; a `new_window` / `none` one keeps its declaration. - const openAsPageLabel = t('console.objectView.openAsPage', { defaultValue: 'Open as full page' }); - const openAsPage = useMemo( - () => (navOverlay.mode === 'drawer' - ? { objectName: objectDef.name, label: openAsPageLabel, open: handleOpenRowAsPage } + // objectstack#35854 — the name cell's 「在侧边打开」 icon, for a row with a + // record surface on a desktop; a phone opens every record as a page. + const openInPanelLabel = t('console.objectView.openInSidePanel', { defaultValue: 'Open in side panel' }); + const openInPanel = useMemo( + () => (navOverlay.mode === 'drawer' && !phone + ? { label: openInPanelLabel, open: handleOpenRowInPanel } : null), - [navOverlay.mode, objectDef.name, openAsPageLabel, handleOpenRowAsPage], + [navOverlay.mode, phone, openInPanelLabel, handleOpenRowInPanel], ); // objectstack#25992 slice 8: the `filter[...]` URL equality filters and the `uf_*` @@ -1063,8 +1039,8 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co actions, handleRowClick, handleListRowsChange, - recordOpen, - openAsPage, + handleListTotalChange, + openInPanel, // objectstack#33317 — the resolved mode: `none` for an authored // `none` and for a list-only object (`servesRecordRead`). rowOpensRecord: navOverlay.mode !== 'none', diff --git a/ui/packages/app-shell/src/views/objectViewListRenderer.tsx b/ui/packages/app-shell/src/views/objectViewListRenderer.tsx index 47ab0125be3..02204e94aa0 100644 --- a/ui/packages/app-shell/src/views/objectViewListRenderer.tsx +++ b/ui/packages/app-shell/src/views/objectViewListRenderer.tsx @@ -15,7 +15,7 @@ import type { useObjectListPreferences, ListViewPreference, ListViewPreferencePa const ObjectChart = lazy(() => import('@object-ui/plugin-charts').then((m) => ({ default: m.ObjectChart })), ); -import { ListView, type ListViewProps } from '@object-ui/plugin-list'; +import { ListView } from '@object-ui/plugin-list'; import type { ListViewSchema, TreeViewConfig } from '@object-ui/types'; import type { FilterBuilderRowGroup } from '@object-ui/components'; import type { useAuth } from '@object-ui/auth'; @@ -41,7 +41,7 @@ import { } from './objectViewOptions.js'; import { useViewTabsFit } from './objectViewChrome.js'; import { ListRecordCountContext } from './objectViewTitleSwitcher.js'; -import { OpenAsPageLink } from './objectViewOpenAsPage.js'; +import { OpenInSidePanelButton } from './objectViewOpenAsPage.js'; import type { useObjectViewIdentity } from './objectViewIdentity.js'; import type { useObjectViewRecordNavigation } from './objectViewRecordNavigation.js'; import type { useObjectViewToolbarAffordances } from './objectViewToolbarAffordances.js'; @@ -97,8 +97,8 @@ export function useObjectViewListRenderer({ actions, handleRowClick, handleListRowsChange, - recordOpen, - openAsPage, + handleListTotalChange, + openInPanel, rowOpensRecord, phoneTitle, handleListPersonalizationChange, @@ -135,10 +135,10 @@ export function useObjectViewListRenderer({ handleRowClick: ReturnType['handleRowClick']; /** objectstack#26679 — the rows the list shows, for the drawer's root `↑` `↓`. */ handleListRowsChange: ReturnType['handleListRowsChange']; - /** objectstack#26681 — the Display menu's Open records section; none on a phone (objectstack#27058). */ - recordOpen: ListViewProps['recordOpen']; - /** objectstack#26681 — the name cell's ↗ (`./objectViewOpenAsPage.tsx`), or `null` for none. */ - openAsPage: { objectName: string; label: string; open: (recordId: string | number) => void } | null; + /** objectstack#35853 — the count the list matched, the M of the record's 「第 N 条,共 M 条」. */ + handleListTotalChange: ReturnType['handleListTotalChange']; + /** objectstack#35854 — the name cell's 「在侧边打开」 (`./objectViewOpenAsPage.tsx`), or `null` for none. */ + openInPanel: { label: string; open: (recordId: string | number) => void } | null; /** objectstack#33317 — whether a row click opens the record: `false` for the `none` mode. */ rowOpensRecord: boolean; /** @@ -1071,6 +1071,7 @@ export function useObjectViewListRenderer({ handleRowClick(record, event); }} onRowsChange={handleListRowsChange} + onTotalChange={handleListTotalChange} // objectstack#30850 — the page lives in the address (`uf__page`, // replace): the list reads it and reports every move back. page={listPage} @@ -1115,13 +1116,13 @@ export function useObjectViewListRenderer({ // marks a user who holds nothing beyond the baseline. A host // prop the grid draws beside the row's title. rowAdornment={managedUsers ? managedUserMarker : undefined} - // objectstack#26681 — for a row that opens the drawer, the ↗ - // beside its record link that opens the record as the full page. - recordLinkAdornment={openAsPage + // objectstack#35854 — the name opens the full page; the icon + // beside it, on hover, opens the record in the side drawer. + recordLinkAdornment={openInPanel ? (row: Record) => { const id = row?.id ?? row?._id; return (typeof id === 'string' && id !== '') || typeof id === 'number' - ? + ? : null; } : undefined} @@ -1129,8 +1130,6 @@ export function useObjectViewListRenderer({ // authored `navigation.mode: 'none'`, or a list-only object) // draws no record link and no Open in its context menu. rowOpensRecord={rowOpensRecord} - // objectstack#26681 — the Display menu's Open records section. - recordOpen={recordOpen} // The toolbar row is the view bar: the view switcher, then the // filter / sort / options tools (objectstack#27058, // objectstack#35548). The switcher shows the list's own record @@ -1143,7 +1142,7 @@ export function useObjectViewListRenderer({ dataSource={ds} /> ); - }, [activeView, activeViewDeclaresColumns, activeViewIsSaved, objectDef, objectName, refreshKey, createRecord, urlFilters, initialUfSelections, handleUserFilterSelectionsChange, writeListUrlState, listPage, user?.id, pageOffersCreate, listAddRecordOpensCreate, listIdentityKey, listPrefs.ready, listPrefs.preference, listPrefs.patchView, managedUsers, managedUserMarker, recordOpen, openAsPage, rowOpensRecord, handleListRowsChange, hasPhoneTitle, leadStore, wideViewport, handleListPersonalizationChange, workspaceTimeZone, viewPanelFilters, offersRename, offersSave, offersReset, previewDrafts, previewDataSource, unpublishedObjects]); + }, [activeView, activeViewDeclaresColumns, activeViewIsSaved, objectDef, objectName, refreshKey, createRecord, urlFilters, initialUfSelections, handleUserFilterSelectionsChange, writeListUrlState, listPage, user?.id, pageOffersCreate, listAddRecordOpensCreate, listIdentityKey, listPrefs.ready, listPrefs.preference, listPrefs.patchView, managedUsers, managedUserMarker, openInPanel, rowOpensRecord, handleListRowsChange, handleListTotalChange, hasPhoneTitle, leadStore, wideViewport, handleListPersonalizationChange, workspaceTimeZone, viewPanelFilters, offersRename, offersSave, offersReset, previewDrafts, previewDataSource, unpublishedObjects]); return { renderListView }; } diff --git a/ui/packages/app-shell/src/views/objectViewOpenAsPage.tsx b/ui/packages/app-shell/src/views/objectViewOpenAsPage.tsx index b6ed118dbca..008f0ddb2ce 100644 --- a/ui/packages/app-shell/src/views/objectViewOpenAsPage.tsx +++ b/ui/packages/app-shell/src/views/objectViewOpenAsPage.tsx @@ -7,89 +7,66 @@ */ /** - * The name cell's ↗ on the Console object list (objectstack#26681): open this - * row's record as the full page, whatever the reader's drawer | split - * preference, without changing it. + * The name cell's 「在侧边打开」 icon on the Console object list + * (objectstack#35854, maintainer 2026-11-20: 「鼠标滑到…行,右侧显示一个右侧打开 + * 的图标,点击才从右侧打开,否则都是进全屏打开。这样就不需要任何设置」). * - * A row of an object that opens its records in the drawer opens the drawer - * (or the pane beside the list, by the reader's preference); the record page - * itself is one ↗ away. It is drawn after the row's record link — the name the - * row opens from — through the grid's host channel (`recordLinkAdornment`), - * and only for a drawer-mode object: a row of a `page` object already opens - * the page, and a `none` list opens nothing. - * - * **The URL is not built here.** The list page publishes its record builder on - * `RelatedRecordActionsContext` (`listRecordActionsValue`): `recordHref` is the - * anchor's href and `openRecord` the SPA navigation a plain left click takes — - * the record route, with the list as the record's origin. A host that cannot - * route to the record answers `null`, and nothing is drawn. A host that - * passes `onOpen` takes the plain click itself: the console's object list - * hands the page the way back to this list with the record open, which the - * page offers as 「Collapse to drawer」 (objectstack#27545). + * The record's name opens the full page; this icon, drawn inside the name + * cell after the name through the grid's host channel (`recordLinkAdornment`), + * opens the record in the side drawer over the list, which stays. It takes no + * column of its own. * * Hidden by OPACITY until the row is hovered or holds focus, so it keeps its - * Tab stop and its name; a coarse pointer, which has no hover, always shows - * it. This is deliberately NOT the row ⋯ menu's treatment: that trigger - * (`RowActionMenu`, `data-table`'s row actions) is drawn at rest in a muted - * tone because an `Actions` header over empty-looking cells reads as "no - * actions" (objectstack#28871, #28923). This ↗ is an extra beside the name, - * under no header of its own, and drawn on every row it would crowd the name - * column, so it stays hover-revealed. + * Tab stop and its name. A coarse pointer (touch), which has no hover, gets no + * icon at all: there the name opens the page and that is the one way + * (objectstack#35854 item 7). This is deliberately NOT the row ⋯ menu's + * treatment: that trigger (`RowActionMenu`, `data-table`'s row actions) is + * drawn at rest in a muted tone because an `Actions` header over + * empty-looking cells reads as "no actions" (objectstack#28871, #28923). This + * icon is an extra beside the name, under no header of its own, and drawn on + * every row it would crowd the name column, so it stays hover-revealed. */ -import { ArrowUpRight } from 'lucide-react'; -import { useRelatedRecordActions } from '@object-ui/react'; +import { PanelRight } from 'lucide-react'; -const OPEN_AS_PAGE_CLASS = +const OPEN_IN_PANEL_CLASS = 'inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground ' + 'opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-within/row:opacity-100 ' - + 'focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring pointer-coarse:opacity-100'; + + 'focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring pointer-coarse:hidden'; -export function OpenAsPageLink({ - objectName, +export function OpenInSidePanelButton({ recordId, label, onOpen, }: { - objectName: string; recordId: string | number; - /** The tooltip and accessible name: 「整页打开」. */ + /** The tooltip and accessible name: 「在侧边打开」. */ label: string; - /** The plain left click, in place of the host's `openRecord`. */ - onOpen?: (recordId: string | number) => void; + /** Open the record in the side drawer over the list. */ + onOpen: (recordId: string | number) => void; }) { - const host = useRelatedRecordActions(); - const href = host?.recordHref?.(objectName, recordId) ?? null; - if (href === null || !host?.openRecord) return null; - const hostOpenRecord = host.openRecord; - const openRecord = onOpen ? () => onOpen(recordId) : () => hostOpenRecord(objectName, recordId); return ( - { - // The row under it opens the drawer on a click: following this - // link must never also do that. + // The name beside it opens the page on a click, and the row + // under it selects: this click is the icon's alone. e.stopPropagation(); - // A modifier or non-primary click belongs to the browser (a new - // tab of the same record page), as on the name's own link. - if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return; e.preventDefault(); - openRecord(); + onOpen(recordId); }} onKeyDown={(e) => { - // Enter is the anchor's own activation (the browser turns it into - // the click above). The grid cell around it reads Enter as "edit - // this cell" in inline-edit mode and would cancel that click, so - // the key stops here. - if (e.key === 'Enter') e.stopPropagation(); + // Enter and Space are the button's own activation. The grid + // cell around it reads Enter as "edit this cell" in inline-edit + // mode and would cancel that click, so the key stops here. + if (e.key === 'Enter' || e.key === ' ') e.stopPropagation(); }} > - +