From 3c797168a4f4b83c5c400bb29c8045ea080df496 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 12:15:14 +0000 Subject: [PATCH 1/4] wip(app-shell): palette current-page Add view and Edit rows (#36286) --- .../src/chrome/PaletteCurrentPage.tsx | 78 ++++++++--- .../app-shell/src/chrome/PaletteEnterHint.tsx | 16 ++- .../app-shell/src/chrome/paletteCommands.ts | 128 ++++++++++++++++++ .../app-shell/src/views/RecordDetailView.tsx | 7 + .../src/views/objectViewSwitcherMenu.tsx | 11 +- .../src/views/objectViewTitleSwitcher.tsx | 26 +++- .../app-shell/src/views/recordPaletteEdit.tsx | 35 +++++ 7 files changed, 281 insertions(+), 20 deletions(-) create mode 100644 ui/packages/app-shell/src/chrome/paletteCommands.ts create mode 100644 ui/packages/app-shell/src/views/recordPaletteEdit.tsx diff --git a/ui/packages/app-shell/src/chrome/PaletteCurrentPage.tsx b/ui/packages/app-shell/src/chrome/PaletteCurrentPage.tsx index b6ae734d502..37f7732dafa 100644 --- a/ui/packages/app-shell/src/chrome/PaletteCurrentPage.tsx +++ b/ui/packages/app-shell/src/chrome/PaletteCurrentPage.tsx @@ -20,6 +20,15 @@ * the `record` favorite `recordFavoriteItem` builds, named by the title the * record was last visited under. * + * - On an object's list, 「Add view」: what the view switcher's own 「Add + * view」 runs (its create card, or the admin's Create View dialog), listed + * while the switcher offers it. + * - On a record page, 「Edit」: the header's own Edit, listed while the header + * draws it, and off while the header's button is off. + * + * Those two are published by the page beside its own control + * (`paletteCommands.ts`), never recomputed here. + * * The page is read off the address, matched against the route table the * console's own route reads are matched against (`APP_ROUTE_METADATA_READS`), * so a static route that shadows `:objectName` (`search`, `reports`) is not a @@ -29,7 +38,7 @@ import { matchPath, matchRoutes } from 'react-router-dom'; import { CommandGroup, CommandItem } from '@object-ui/components'; -import { Star, StarOff } from 'lucide-react'; +import { Pencil, Plus, Star, StarOff } from 'lucide-react'; import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n'; import { APP_ROUTE_METADATA_READS } from '../console/appRouteMetadataReads.js'; import { objectViewRouteObject } from '../console/appObjectScope.js'; @@ -39,7 +48,8 @@ import { useRecentItems } from '../context/RecentItemsProvider.js'; import { useRecentItemLabel } from '../hooks/useRecentItemLabel.js'; import { useObjectListFavorite } from '../layout/SidebarItemMenu.js'; import { servedObjectPluralLabel } from '../hooks/servedObjectLabel.js'; -import { FAVORITE_ADD_KIND, FAVORITE_REMOVE_KIND } from './PaletteEnterHint.js'; +import { ADD_VIEW_KIND, EDIT_RECORD_KIND, FAVORITE_ADD_KIND, FAVORITE_REMOVE_KIND } from './PaletteEnterHint.js'; +import { usePageCommands, type PageCommandId } from './paletteCommands.js'; /** The page behind the palette, when it is one the group offers entries for. */ export type PaletteCurrentPage = @@ -120,23 +130,59 @@ export function PaletteCurrentPageGroup({ const item = recordFavoriteItem(page.appSegment, page.objectName, page.recordId, visit ? recentLabel(visit) : undefined); favorite = { isFavorite: isFavorite(item.id), toggle: () => toggleFavorite(item) }; } - if (!favorite) return null; + const pageFavorite = favorite; + // The page's own command for this kind of page, as the page publishes it. + const commandId: PageCommandId = page.kind === 'list' ? 'add-view' : 'edit-record'; + const command = usePageCommands().find((published) => published.id === commandId); + if (!pageFavorite && !command) return null; - const { isFavorite: starred, toggle } = favorite; return ( - run(toggle)} - > - {starred ? : } - - {starred - ? t('common.removeFromFavorites', { defaultValue: 'Remove from favorites' }) - : t('common.addToFavorites', { defaultValue: 'Add to favorites' })} - - + {pageFavorite && ( + run(pageFavorite.toggle)} + > + {pageFavorite.isFavorite ? : } + + {pageFavorite.isFavorite + ? t('common.removeFromFavorites', { defaultValue: 'Remove from favorites' }) + : t('common.addToFavorites', { defaultValue: 'Add to favorites' })} + + + )} + {command?.id === 'add-view' && ( + run(command.run)} + > + + {/* The switcher's own words for it. */} + {t('view.switcher.addView', { defaultValue: 'Add view' })} + + )} + {command?.id === 'edit-record' && ( + run(command.run)} + > + + + {/* The header button's own words for it. */} + {t('detail.edit', { defaultValue: 'Edit' })} + {command.disabled && command.disabledReason && ( + + {command.disabledReason} + + )} + + + )} ); } diff --git a/ui/packages/app-shell/src/chrome/PaletteEnterHint.tsx b/ui/packages/app-shell/src/chrome/PaletteEnterHint.tsx index 5afbd5ed6d4..f6aa6af2301 100644 --- a/ui/packages/app-shell/src/chrome/PaletteEnterHint.tsx +++ b/ui/packages/app-shell/src/chrome/PaletteEnterHint.tsx @@ -9,8 +9,8 @@ /** * The ⌘K palette's footer (objectstack#36286): what Enter does to the entry * the keyboard is on — open the record, create one, switch app, apply a - * theme, add the current page to the favorites or take it off, or open the - * page the entry names. + * theme, add the current page to the favorites or take it off, add a view to + * the list, edit the record, or open the page the entry names. * * The entry is named by its cmdk `value`, and every palette entry's value * starts with the word for its kind (`record …`, `create …`, `app …`); the @@ -29,11 +29,16 @@ export type PaletteEnterAction = | 'applyTheme' | 'addFavorite' | 'removeFavorite' + | 'addView' + | 'editRecord' | 'open'; /** The leading word of a current-page favorites row's value (`PaletteCurrentPage`). */ export const FAVORITE_ADD_KIND = 'favorite-add'; export const FAVORITE_REMOVE_KIND = 'favorite-remove'; +/** The leading word of the current-page 「Add view」 and 「Edit」 rows. */ +export const ADD_VIEW_KIND = 'view-add'; +export const EDIT_RECORD_KIND = 'record-edit'; const ACTION_BY_KIND: Record = { record: 'openRecord', @@ -43,6 +48,8 @@ const ACTION_BY_KIND: Record = { theme: 'applyTheme', [FAVORITE_ADD_KIND]: 'addFavorite', [FAVORITE_REMOVE_KIND]: 'removeFavorite', + [ADD_VIEW_KIND]: 'addView', + [EDIT_RECORD_KIND]: 'editRecord', }; /** The action Enter runs on the entry whose cmdk value is `value`; `null` when nothing is selected. */ @@ -71,6 +78,11 @@ export function PaletteEnterHint({ value }: { value: string | null | undefined } return t('common.addToFavorites', { defaultValue: 'Add to favorites' }); case 'removeFavorite': return t('common.removeFromFavorites', { defaultValue: 'Remove from favorites' }); + // The page controls' own words, as the row shows them. + case 'addView': + return t('view.switcher.addView', { defaultValue: 'Add view' }); + case 'editRecord': + return t('detail.edit', { defaultValue: 'Edit' }); default: return t('console.commandPalette.enterOpen', { defaultValue: 'Open' }); } diff --git a/ui/packages/app-shell/src/chrome/paletteCommands.ts b/ui/packages/app-shell/src/chrome/paletteCommands.ts new file mode 100644 index 00000000000..f4914c7af6e --- /dev/null +++ b/ui/packages/app-shell/src/chrome/paletteCommands.ts @@ -0,0 +1,128 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * Page commands — what the page behind the ⌘K palette offers it, published by + * the page beside the control that runs it (objectstack#36286). + * + * The palette's "Current page" group lists a page's 「Add view」 and 「Edit」. + * Neither can be recomputed where the palette is mounted: the list's create + * card is state inside its view switcher, and the record's Edit is offered + * by a verdict only the record page holds (approval lock, `edit.visibleWhen` + * / `disabledWhen`, the state lock, the edit state). So the page publishes + * the command it draws, with the handler its own control runs and the + * verdict its own control is drawn under, for exactly as long as that + * control is drawn; the palette lists what is published. Nothing is derived + * twice, so the row and the page's control cannot disagree. + * + * A module store rather than a context, for the reason `advertisedShortcuts` + * gives: the publishers sit on a different branch of the tree from the + * palette. + * + * @module + */ + +import { useLayoutEffect, useRef, useSyncExternalStore } from 'react'; + +/** The commands a page can publish, one per control. */ +export type PageCommandId = 'add-view' | 'edit-record'; + +export interface PageCommand { + id: PageCommandId; + /** Runs what the page's control runs. */ + run: () => void; + /** The page's control is drawn but off: the row is listed, and off. */ + disabled?: boolean; + /** Why it is off, as the page's control says it. */ + disabledReason?: string; +} + +/** What the palette reads: a command's state, and a `run` that calls the latest handler. */ +export interface PublishedPageCommand { + id: PageCommandId; + disabled: boolean; + disabledReason?: string; + run: () => void; +} + +interface Holding { + /** The publisher's latest command; its `run` changes every render. */ + command: PageCommand; +} + +// Publishers in the order they published: the last one of an id is listed. +const holdings: Holding[] = []; +const listeners = new Set<() => void>(); +let snapshot: readonly PublishedPageCommand[] = []; + +function shownState(command: PageCommand): string { + return JSON.stringify([command.id, !!command.disabled, command.disabledReason ?? '']); +} + +function commit(): void { + const byId = new Map(); + for (const holding of holdings) byId.set(holding.command.id, holding); + snapshot = Array.from(byId.values(), (holding) => ({ + id: holding.command.id, + disabled: !!holding.command.disabled, + disabledReason: holding.command.disabledReason, + // Read at the press, so the handler is the publisher's latest render's. + run: () => holding.command.run(), + })); + for (const listener of listeners) listener(); +} + +/** + * Publish `command` (or `null` for none) while the calling component is + * mounted. Call it on every render, beside the control the command names, + * under the same condition that control is drawn under. + */ +export function usePublishPageCommand(command: PageCommand | null): void { + const holdingRef = useRef(null); + useLayoutEffect(() => { + const holding = holdingRef.current; + if (!command) { + if (holding) { + holdings.splice(holdings.indexOf(holding), 1); + holdingRef.current = null; + commit(); + } + return; + } + if (!holding) { + holdingRef.current = { command }; + holdings.push(holdingRef.current); + commit(); + return; + } + const before = shownState(holding.command); + holding.command = command; + // A new handler alone is not a change the palette draws. + if (shownState(command) !== before) commit(); + }); + useLayoutEffect( + () => () => { + const holding = holdingRef.current; + if (!holding) return; + holdings.splice(holdings.indexOf(holding), 1); + holdingRef.current = null; + commit(); + }, + [], + ); +} + +function subscribe(listener: () => void): () => void { + listeners.add(listener); + return () => { + listeners.delete(listener); + }; +} + +function getSnapshot(): readonly PublishedPageCommand[] { + return snapshot; +} + +/** The commands the page publishes right now. */ +export function usePageCommands(): readonly PublishedPageCommand[] { + return useSyncExternalStore(subscribe, getSnapshot, getSnapshot); +} diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index 94604d68093..843fd492401 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -43,6 +43,7 @@ import { useRecordChangeOwnerOffer } from './changeOwner.js'; import { FlowRunner, type ScreenFlowState, type ScreenSpec } from './FlowRunner.js'; import { FlowRefusalNotice, type FlowRefusalState } from './FlowRefusalNotice.js'; import { RelatedRecordActionsBridge } from './RelatedRecordActionsBridge.js'; +import { PublishRecordEditCommand, type RecordHeaderEditEntry } from './recordPaletteEdit.js'; import { RecordEditStateController, bodyTablesSaveTogether, isMasterDetailChild, withDetailWritesWithheld, type RecordEditStateControl, type RecordEditStateEntry } from './recordEditState.js'; import { isRecordPagePushed, useRecordPageScrollMemory } from './recordPagePush.js'; import { phoneRecordHeader } from './recordPhoneHeader.js'; @@ -5575,6 +5576,11 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri } return items; })(); + // objectstack#36286 — the header's Edit, offered by the ⌘K palette on the + // record's own page (not a drawer or a pane over a list). + const paletteEdit = embedded + ? undefined + : (synthSystemActions.find((action) => action.name === 'sys_edit') as RecordHeaderEditEntry | undefined); // The synth path hands ONLY business actions (authored on objectDef and // routed to the record_header location, e.g. Lead.convert) to the page @@ -6139,6 +6145,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri defaultValue: 'This record has a pending approval request; editing is locked', })} > + ('list'); + const [mode, setMode] = useState<'list' | 'create'>(startOnCreate && create ? 'create' : 'list'); + // A body kept mounted while closed (the phone's sheet) is asked again. + const [askedOnCreate, setAskedOnCreate] = useState(startOnCreate); + if (startOnCreate !== askedOnCreate) { + setAskedOnCreate(startOnCreate); + if (startOnCreate && create) setMode('create'); + } const [query, setQuery] = useState(''); const byId = new Map(views.map((v) => [v.id, v])); diff --git a/ui/packages/app-shell/src/views/objectViewTitleSwitcher.tsx b/ui/packages/app-shell/src/views/objectViewTitleSwitcher.tsx index cc439c05dfa..c9b9cf65d60 100644 --- a/ui/packages/app-shell/src/views/objectViewTitleSwitcher.tsx +++ b/ui/packages/app-shell/src/views/objectViewTitleSwitcher.tsx @@ -36,6 +36,7 @@ */ import { createContext, createElement, useContext, useMemo, useState, type ComponentType, type Dispatch, type ReactNode, type SetStateAction } from 'react'; +import { usePublishPageCommand } from '../chrome/paletteCommands.js'; import { cn, Popover, PopoverContent, PopoverTrigger } from '@object-ui/components'; import type { ViewTabItem } from '@object-ui/plugin-view'; import { resolveViewId } from '@object-ui/core'; @@ -141,7 +142,14 @@ export function ObjectViewTitleSwitcher({ create, t, }: ObjectViewTitleSwitcherProps) { - const [open, setOpen] = useState(false); + const [open, setOpenState] = useState(false); + // The ⌘K palette's 「Add view」 opens the dropdown on its create card; any + // other open shows the views. + const [startOnCreate, setStartOnCreate] = useState(false); + const setOpen = (next: boolean) => { + setOpenState(next); + if (!next) setStartOnCreate(false); + }; const listState = useContext(ListRecordCountContext); const displayLocale = useDisplayLocale(); @@ -173,10 +181,26 @@ export function ObjectViewTitleSwitcher({ onAddView={onAddView} phone={phone} footerEnd={footerEnd} + startOnCreate={startOnCreate} t={t} /> ); + // objectstack#36286 — 「Add view」 in the ⌘K palette's Current page group, + // offered exactly where the dropdown offers it, running what it runs: the + // create card in the dropdown, or the host's Create View dialog. + usePublishPageCommand(create || onAddView ? { + id: 'add-view', + run: () => { + if (create) { + setStartOnCreate(true); + setOpenState(true); + } else { + onAddView?.(); + } + }, + } : null); + // objectstack#35883 / #35884 — in the list's phone toolbar the switcher is // its first pill (the view's name, its count, the caret) and opens the // same menu in the list's bottom sheet; a view chosen there opens at once diff --git a/ui/packages/app-shell/src/views/recordPaletteEdit.tsx b/ui/packages/app-shell/src/views/recordPaletteEdit.tsx new file mode 100644 index 00000000000..282bf9e872a --- /dev/null +++ b/ui/packages/app-shell/src/views/recordPaletteEdit.tsx @@ -0,0 +1,35 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The record page's 「Edit」 in the ⌘K palette's Current page group + * (objectstack#36286): the header's own Edit entry, published while the page + * draws it, pressable exactly when the header's button is. + * + * Mounted inside the page's `InlineEditProvider`, because the header greys + * Edit while an inline draft is live (`disableDuringInlineEdit`) and that + * session is read there. + * + * @module + */ + +import { useInlineEdit } from '@object-ui/react'; +import { usePublishPageCommand } from '../chrome/paletteCommands.js'; + +/** The keys of the header's `sys_edit` entry this reads. */ +export interface RecordHeaderEditEntry { + onClick: () => void; + disabled?: boolean; + disabledReason?: string; + disableDuringInlineEdit?: boolean; +} + +export function PublishRecordEditCommand({ edit }: { edit: RecordHeaderEditEntry | undefined }) { + const inlineEditing = !!useInlineEdit()?.editing; + usePublishPageCommand(edit ? { + id: 'edit-record', + run: () => edit.onClick(), + disabled: !!edit.disabled || (inlineEditing && edit.disableDuringInlineEdit === true), + disabledReason: edit.disabledReason, + } : null); + return null; +} From 7c7dd955442079d21fdf6e62eef744714261d349 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 12:17:50 +0000 Subject: [PATCH 2/4] test(app-shell): pin the palette's Add view and Edit rows; changeset and README (#36286) Claude-Session: https://claude.ai/code/session_01JQwxbXBGc8PQRp6Q7TM7EU Co-authored-by: Claude --- .changeset/36286-palette-add-view-edit.md | 15 ++ ui/packages/app-shell/README.md | 8 + ...ommandPalette.previewCreate-36286.test.tsx | 192 +++++++++++++++++- .../views/RecordDetailView.harness.test.tsx | 138 +++++++++++++ 4 files changed, 351 insertions(+), 2 deletions(-) create mode 100644 .changeset/36286-palette-add-view-edit.md diff --git a/.changeset/36286-palette-add-view-edit.md b/.changeset/36286-palette-add-view-edit.md new file mode 100644 index 00000000000..e7c63d95269 --- /dev/null +++ b/.changeset/36286-palette-add-view-edit.md @@ -0,0 +1,15 @@ +--- +'@object-ui/app-shell': patch +--- + +feat(console): the ⌘K palette's "Current page" group offers the list's "Add view" and the record's "Edit" + +Clause-②: no +Metadata-protocol: none + +Opened with nothing typed, the command palette's "Current page" group now carries the page's own main entry beside its favorites row: + +- **On an object's list**: "Add view", listed exactly where the view switcher offers "Add view". Enter opens the switcher on its in-place create card, or, for a host that offers only the Create View dialog, opens that dialog. +- **On a record page**: "Edit", the header's own Edit. It runs what the header button runs (the record form, or the page's edit state), and it is off exactly when the button is off: a `userActions.edit.disabledWhen` that holds, the state lock, or a live inline draft the header greys Edit for, with the header's reason under it. A record an approval locks, a record already in its edit state and a record shown in a drawer or pane over a list offer no Edit row. + +The footer names what Enter does ("Add view ↵", "Edit ↵"), in the controls' own words. Nothing is recomputed in the palette: the list and the record page publish the command beside the control while they draw it. No locale keys, props or package exports change. diff --git a/ui/packages/app-shell/README.md b/ui/packages/app-shell/README.md index 6e2ffa9d077..bb3758b486f 100644 --- a/ui/packages/app-shell/README.md +++ b/ui/packages/app-shell/README.md @@ -1436,6 +1436,14 @@ opens the object's create page (`/apps/APP/OBJECT/new`), the second with the words in its title field. An object is offered exactly where its list offers New. A footer names what Enter does to the selected entry. +With nothing typed, the palette leads with a "Current page" group: on an +object's list, the list's favorites entry and "Add view"; on a record page, the +record's star and "Edit". Each row runs the page's own control and is listed +only while the page draws that control. "Add view" and "Edit" are published by +the page beside the control (`usePublishPageCommand`, `chrome/paletteCommands.ts`) +with the control's own handler and verdict, so an Edit the header draws off is +listed off, with the header's reason. + ```tsx import { useCommandPalette } from '@object-ui/app-shell'; diff --git a/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx b/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx index f5df22f1e91..959156a012f 100644 --- a/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx +++ b/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx @@ -19,9 +19,9 @@ import * as React from 'react'; import { describe, it, expect, vi, afterEach } from 'vitest'; -import { render, fireEvent, waitFor, cleanup, screen, act } from '@testing-library/react'; +import { render, fireEvent, waitFor, cleanup, screen, act, within } from '@testing-library/react'; import { MemoryRouter, useLocation } from 'react-router-dom'; -import { MetadataCtx } from '@object-ui/react'; +import { InlineEditProvider, MetadataCtx, useInlineEdit } from '@object-ui/react'; vi.mock('@object-ui/auth', async (importOriginal) => ({ ...(await importOriginal>()), @@ -64,6 +64,8 @@ import { RecentItemsProvider, useRecentItems } from '../context/RecentItemsProvi import { useFavorites } from '../hooks/useFavorites'; import { scopedKey } from '../context/UserStateAdapters'; import { useObjectListFavorite } from '../layout/SidebarItemMenu'; +import { ObjectViewTitleSwitcher } from '../views/objectViewTitleSwitcher'; +import { PublishRecordEditCommand } from '../views/recordPaletteEdit'; const CUSTOMER = 'customer_36286'; const CONTACT = 'contact_36286'; @@ -481,3 +483,189 @@ describe('objectstack#36286 — the empty palette leads with the current page\'s expect(paletteEnterAction(`favorite-remove current page record ${CUSTOMER}`)).toBe('removeFavorite'); }); }); + +describe('objectstack#36286 — the current page\'s Add view and Edit, run by the page\'s own control', () => { + const t = ((key: string, options?: { defaultValue?: string }) => options?.defaultValue ?? key) as never; + const SWITCHER_VIEWS = [{ id: 'all', label: 'All Customers', type: 'grid', authored: true }]; + + /** The list's own view switcher, as `ObjectView` mounts it. */ + function ListSwitcher(props: { create?: boolean; onAddView?: () => void }) { + return ( + {}} + onAddView={props.onAddView} + create={props.create + ? { objectDef: OBJECTS[0] as never, canCreatePersonal: true, canCreateShared: false, hasUnsavedConditions: false, onCreate: vi.fn().mockResolvedValue(true) } + : undefined} + t={t} + /> + ); + } + + /** Starts an inline draft, as a field's double-click does on the record page. */ + function StartInlineDraft() { + const session = useInlineEdit(); + React.useEffect(() => { + session?.enter(); + }, [session]); + return null; + } + + function tree(path: string, page: React.ReactNode) { + const metadata = { ...metadataValue(), apps: [CRM] }; + const ds = { find: vi.fn(async () => ({ data: [] })), findOne: vi.fn(async () => null) }; + return ( + + + + + + + {page} + {}} dataSource={ds} /> + + + + + + ); + } + const LIST = `/apps/crm/${CUSTOMER}`; + const RECORD = `/apps/crm/${CUSTOMER}/record/C1`; + const input = () => document.querySelector('[cmdk-input]') as HTMLInputElement | null; + const addView = () => screen.queryByTestId('palette-current-page-add-view'); + const edit = () => screen.queryByTestId('palette-current-page-edit'); + const groupRows = () => + Array.from(document.querySelectorAll('[cmdk-item][data-value*=" current page "]')).map((el) => el.getAttribute('data-value')); + + afterEach(() => localStorage.clear()); + + it('on a list whose switcher offers the create card: listed after the favorites row; Enter opens the switcher on that card', async () => { + render(tree(LIST, )); + await waitFor(() => expect(addView()).not.toBeNull()); + expect(addView()).toHaveTextContent('Add view'); + expect(groupRows()).toEqual([`favorite-add current page list ${CUSTOMER}`, `view-add current page ${CUSTOMER}`]); + + press(input()!, 'ArrowDown'); + await waitFor(() => expect(selected()).toBe(`view-add current page ${CUSTOMER}`)); + expect(hint()).toBe('addView'); + expect(screen.getByTestId('palette-enter-hint')).toHaveTextContent('Add view'); + + press(input()!, 'Enter'); + await waitFor(() => expect(input()).toBeNull()); + const menu = await screen.findByTestId('list-view-switcher-menu'); + expect(await within(menu).findByTestId('create-view-card')).toBeInTheDocument(); + expect(location()).toBe(LIST); + }); + + it('opened the switcher\'s own way afterwards, it shows the views again', async () => { + render(tree(LIST, )); + await waitFor(() => expect(addView()).not.toBeNull()); + fireEvent.click(addView()!); + const menu = await screen.findByTestId('list-view-switcher-menu'); + fireEvent.click(await within(menu).findByTestId('create-view-card-back')); + expect(screen.getByTestId('list-view-switcher-body')).toBeInTheDocument(); + }); + + it('a switcher that offers only the Create View dialog: Enter runs that dialog\'s door', async () => { + const onAddView = vi.fn(); + render(tree(LIST, )); + await waitFor(() => expect(addView()).not.toBeNull()); + fireEvent.click(addView()!); + expect(onAddView).toHaveBeenCalledTimes(1); + expect(screen.queryByTestId('list-view-switcher-menu')).toBeNull(); + }); + + it('CONTROL: a switcher that offers no 「Add view」 (a reader who may create no view) lists none; the favorites row stays', async () => { + render(tree(LIST, )); + await waitFor(() => expect(screen.queryByTestId('palette-current-page-favorite')).not.toBeNull()); + await act(async () => {}); + expect(addView()).toBeNull(); + }); + + it('on a record page: Edit runs the header entry\'s own handler', async () => { + const onClick = vi.fn(); + render(tree(RECORD, ( + + + + ))); + await waitFor(() => expect(edit()).not.toBeNull()); + expect(edit()).toHaveTextContent('Edit'); + expect(groupRows()).toEqual([`favorite-add current page record ${CUSTOMER}`, `record-edit current page ${CUSTOMER}`]); + press(input()!, 'ArrowDown'); + await waitFor(() => expect(hint()).toBe('editRecord')); + press(input()!, 'Enter'); + expect(onClick).toHaveBeenCalledTimes(1); + await waitFor(() => expect(input()).toBeNull()); + }); + + it('an Edit the header draws off is listed off, with the header\'s reason, and does nothing', async () => { + const onClick = vi.fn(); + render(tree(RECORD, ( + + + + ))); + await waitFor(() => expect(edit()).not.toBeNull()); + expect(edit()?.getAttribute('aria-disabled')).toBe('true'); + expect(screen.getByTestId('palette-current-page-edit-reason')).toHaveTextContent('Closed deals cannot be edited'); + fireEvent.click(edit()!); + expect(onClick).not.toHaveBeenCalled(); + expect(input()).not.toBeNull(); + }); + + it('off while an inline draft is live, as the header greys its Edit (disableDuringInlineEdit)', async () => { + const onClick = vi.fn(); + render(tree(RECORD, ( + + + + + ))); + await waitFor(() => expect(edit()?.getAttribute('aria-disabled')).toBe('true')); + }); + + it('CONTROL: a live draft leaves Edit pressable where the header keeps it pressable (the edit state\'s page)', async () => { + render(tree(RECORD, ( + + + {}, disableDuringInlineEdit: false }} /> + + ))); + await waitFor(() => expect(edit()).not.toBeNull()); + await act(async () => {}); + expect(edit()?.getAttribute('aria-disabled')).not.toBe('true'); + }); + + it('withdrawn when the page stops drawing it, and listed only on its own kind of page', async () => { + const view = render(tree(RECORD, ( + + {} }} /> + + ))); + await waitFor(() => expect(edit()).not.toBeNull()); + view.rerender(tree(RECORD, )); + await waitFor(() => expect(edit()).toBeNull()); + cleanup(); + + // A record drawer's Edit (were one published) is no row on the list behind it. + render(tree(LIST, ( + + {} }} /> + + ))); + await waitFor(() => expect(screen.queryByTestId('palette-current-page-favorite')).not.toBeNull()); + await act(async () => {}); + expect(edit()).toBeNull(); + }); + + it('the footer reads the two rows\' kind', () => { + expect(paletteEnterAction(`view-add current page ${CUSTOMER}`)).toBe('addView'); + expect(paletteEnterAction(`record-edit current page ${CUSTOMER}`)).toBe('editRecord'); + }); +}); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx index 7a689405533..2b71010e06b 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx @@ -61,6 +61,7 @@ import { recentItemObject } from '../console/home/recentItemTypeLabel'; import { NavigationProvider, useNavigationContext } from '../context/NavigationContext'; import { RecentItemsProvider, useRecentItems, type RecentItem } from '../context/RecentItemsProvider'; import { RecordDetailView } from './RecordDetailView'; +import { usePageCommands, type PublishedPageCommand } from '../chrome/paletteCommands'; vi.mock('@object-ui/auth', async (importOriginal) => ({ ...(await importOriginal>()), @@ -3579,3 +3580,140 @@ describe('RecordDetailView.embeddedStageReread-36309', () => { await waitFor(() => expect(document.querySelector('[data-page-refresh]')).toBeTruthy()); }); }); + +describe('RecordDetailView.paletteEdit-36286', () => { + restoreAfterBlock(); + + const OBJECT = 'crm_deal_36286'; + const ID = 'd1'; + const defWith = (extra: Record = {}) => ({ + name: OBJECT, + label: 'Deal', + nameField: 'name', + fields: { + id: { label: 'Id', type: 'text' }, + name: { label: 'Name', type: 'text' }, + status: { label: 'Status', type: 'text' }, + }, + ...extra, + }); + + /** What the ⌘K palette reads: the commands the page publishes. */ + let published: readonly PublishedPageCommand[] = []; + function CommandsProbe() { + const commands = usePageCommands(); + React.useEffect(() => { + published = commands; + }); + return null; + } + + function renderDeal({ embedded = false, def = defWith() }: { embedded?: boolean; def?: ReturnType } = {}) { + const pages: any[] = []; + const metadata = { + objects: [def], pages, loading: false, error: null, + refresh: async () => {}, invalidate: () => {}, + ensureType: async () => pages, getItem: async () => null, + getItemsByType: () => pages, + } as any; + const ds = { + find: vi.fn(async () => ({ data: [], total: 0, hasMore: false, pageSize: 50 })), + findOne: vi.fn(async () => ({ id: ID, name: 'Wayne deal', status: 'new' })), + create: vi.fn(async (_o: string, r: any) => r), + update: vi.fn(async () => ({})), + delete: vi.fn(async () => ({})), + getObjectSchema: async () => def, + } as Record; + const onEdit = vi.fn(); + render( + + + + + + + + , + ); + return { ds, onEdit }; + } + + /** The header row's Edit, as the page draws it. */ + async function headerEdit(): Promise { + return waitFor( + () => { + const header = document.querySelector('[data-record-top-bar-actions]') as HTMLElement | null; + expect(header).toBeTruthy(); + const edit = within(header!).getAllByRole('button').find((b) => b.textContent?.trim() === 'Edit'); + expect(edit).toBeTruthy(); + return edit as HTMLButtonElement; + }, + { timeout: 5000 }, + ); + } + const editCommand = () => published.find((command) => command.id === 'edit-record'); + + beforeAll(() => { + Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1440 }); + }); + + beforeEach(() => { + published = []; + vi.stubGlobal('fetch', vi.fn(async () => ({ + ok: true, + status: 200, + json: async () => ({ allowed: true, data: [] }), + text: async () => '{}', + })) as never); + }); + + afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + }); + + it('the record page publishes the header\'s Edit, and running it runs what the button runs', async () => { + const { onEdit } = renderDeal(); + const button = await headerEdit(); + await waitFor(() => expect(editCommand()).toBeTruthy()); + expect(editCommand()?.disabled).toBe(false); + expect(button.disabled).toBe(false); + + act(() => editCommand()!.run()); + expect(onEdit).toHaveBeenCalledTimes(1); + expect(onEdit).toHaveBeenLastCalledWith({ id: ID }, OBJECT); + fireEvent.click(button); + expect(onEdit).toHaveBeenCalledTimes(2); + expect(onEdit.mock.calls[1]).toEqual(onEdit.mock.calls[0]); + }); + + it('off exactly when the header\'s Edit is off (edit.disabledWhen holds on the record)', async () => { + renderDeal({ def: defWith({ userActions: { edit: { disabledWhen: "record.status == 'new'" } } }) }); + const button = await headerEdit(); + await waitFor(() => expect(button.disabled).toBe(true)); + await waitFor(() => expect(editCommand()?.disabled).toBe(true)); + }); + + it('CONTROL: a disabledWhen that does not hold leaves both pressable', async () => { + renderDeal({ def: defWith({ userActions: { edit: { disabledWhen: "record.status == 'closed'" } } }) }); + const button = await headerEdit(); + await waitFor(() => expect(editCommand()).toBeTruthy()); + expect(button.disabled).toBe(false); + expect(editCommand()?.disabled).toBe(false); + }); + + it('CONTROL: a record in a drawer or pane publishes nothing (the page behind it is the list)', async () => { + const { ds } = renderDeal({ embedded: true }); + await waitFor(() => expect(ds.findOne).toHaveBeenCalled()); + await waitFor(() => expect(screen.getAllByText('Wayne deal').length).toBeGreaterThan(0), { timeout: 5000 }); + await act(async () => {}); + expect(editCommand()).toBeUndefined(); + }); +}); From 27f53476dd6e58983430861cbd54e82008c83b5b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 12:30:05 +0000 Subject: [PATCH 3/4] test(app-shell): answer the create card's dataset read without a network (#36286) Claude-Session: https://claude.ai/code/session_01JQwxbXBGc8PQRp6Q7TM7EU Co-authored-by: Claude --- .../CommandPalette.previewCreate-36286.test.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx b/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx index 959156a012f..84db0dc90d6 100644 --- a/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx +++ b/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx @@ -50,6 +50,17 @@ vi.mock('@object-ui/permissions', async (importOriginal) => ({ usePermissions: () => PERMS, })); +// The switcher's create card reads the dataset catalog (a chart view's +// source): answered empty here, with no network. +vi.mock('../views/metadata-admin/useMetadata', async (importOriginal) => { + const { MetadataClient } = await import('@object-ui/data-objectstack'); + const client = new MetadataClient({ + baseUrl: 'http://localhost', + fetch: (async () => new Response('[]', { status: 200, headers: { 'content-type': 'application/json' } })) as unknown as typeof fetch, + }); + return { ...(await importOriginal>()), useMetadataClient: () => client }; +}); + // The preview's key fields draw through `lazy()`: load the detail entry at // module scope, so its cost is paid at import (ui/AGENTS.md, lazy boundaries). import '@object-ui/plugin-detail'; From d8c8135beea9e2d4c5fec01efc07d597b4b0b9e5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 13:02:40 +0000 Subject: [PATCH 4/4] test(app-shell): pay the palette harness's lint and metadata-client loads at import Claude-Session: https://claude.ai/code/session_01JQwxbXBGc8PQRp6Q7TM7EU Co-authored-by: Claude --- ...ommandPalette.previewCreate-36286.test.tsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx b/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx index 84db0dc90d6..cdd0b5d6193 100644 --- a/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx +++ b/ui/packages/app-shell/src/chrome/CommandPalette.previewCreate-36286.test.tsx @@ -22,6 +22,7 @@ import { describe, it, expect, vi, afterEach } from 'vitest'; import { render, fireEvent, waitFor, cleanup, screen, act, within } from '@testing-library/react'; import { MemoryRouter, useLocation } from 'react-router-dom'; import { InlineEditProvider, MetadataCtx, useInlineEdit } from '@object-ui/react'; +import { MetadataClient } from '@object-ui/data-objectstack'; vi.mock('@object-ui/auth', async (importOriginal) => ({ ...(await importOriginal>()), @@ -52,15 +53,19 @@ vi.mock('@object-ui/permissions', async (importOriginal) => ({ // The switcher's create card reads the dataset catalog (a chart view's // source): answered empty here, with no network. -vi.mock('../views/metadata-admin/useMetadata', async (importOriginal) => { - const { MetadataClient } = await import('@object-ui/data-objectstack'); - const client = new MetadataClient({ - baseUrl: 'http://localhost', - fetch: (async () => new Response('[]', { status: 200, headers: { 'content-type': 'application/json' } })) as unknown as typeof fetch, - }); - return { ...(await importOriginal>()), useMetadataClient: () => client }; -}); +let metadataClient: MetadataClient | undefined; +vi.mock('../views/metadata-admin/useMetadata', async (importOriginal) => ({ + ...(await importOriginal>()), + useMetadataClient: () => + (metadataClient ??= new MetadataClient({ + baseUrl: 'http://localhost', + fetch: (async () => new Response('[]', { status: 200, headers: { 'content-type': 'application/json' } })) as unknown as typeof fetch, + })), +})); +// The view switcher's module reaches the draft-publish lint, which the source +// loads lazily: pay that load at import, not inside a test's window. +import '@objectstack/lint'; // The preview's key fields draw through `lazy()`: load the detail entry at // module scope, so its cost is paid at import (ui/AGENTS.md, lazy boundaries). import '@object-ui/plugin-detail';