Skip to content

Commit 355c73c

Browse files
feat(studio): ⌘K on every Studio design page lists the package's menu and items (#37108)
Fixes #36900 Part of #36890 Clause-②: no Metadata-protocol: none repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H ## 维护者速读 - 在 Studio 的任何设计页面(包括「全部元数据」跨包页)按 ⌘K / Ctrl+K,都能打开搜索面板:按左侧菜单的六组列出当前包的全部类型和每一项,选中即打开它的详情或设计器;页面上有没保存的修改时,会先问一句再走。 - 属于「Studio 重构」专题:去掉设计器左侧那一列后,作者靠 ×、‹ › 和 ⌘K 换到别的项;同时补回上一步左侧菜单改造时临时丢掉的跨包页 ⌘K。 - 出错时作者只是搜不到或打不开某一项,左侧菜单和列表照常可用;不动任何数据,直接撤回这次改动即可。 - 无。 ## What changes Head `7bbe1c54b`: 15 files, +1,679 / −92 against `main`, one PR for the card. REWORK round 1 (L1 7144125191) and its delta L1 ACCEPT (7147006586) are folded in below. `main` was merged in that round. **The command palette is mounted on every Studio design page.** `StudioDesignSurface` mounts it in its shell under its own `CommandPaletteProvider`, on a package's pillars and "All metadata" area, `~org` and `~all`. After #36985 only the `/studio` landing had one, so `~all` had lost ⌘K (the hand-off's stated temporary regression); this restores it. A host that already mounts a palette above the surface keeps its own (`useCommandPaletteProviderMounted()`): the surface then mounts neither provider nor palette. - **What it lists on a package.** The left menu, group by group (`buildStudioMenu`, decision 11: Data, UI, Automation, Platform, Access, AI, under the menu's names). Each group holds the menu's own entries: each type's list, plus Organization flows, Default sharing, Diagnostics and Positions and permissions. Then come the items of every type the group lists, from the package and its `.custom` pair (ADR-0146 D3). - **Types.** The menu's own data, read once per page: `StudioMenuDataProvider` in the surface feeds both the menu and the palette (new `studioMenuData.ts`: the data hook, the context, the group icons and the entry names). The palette and the menu cannot disagree, and opening the palette re-reads neither types nor the diagnostics sweep. - **Items.** Each listed type's served list, read only while the palette is open, as its list page reads it (`include: listInclude`). The rows are kept by the list page's own rule (`scopeListRows`: the package, its pair, the type's list predicate) and named by the type's primary key. - **Customizations.** A customization item reads "Customization of PACKAGE NAME", never the pair's raw id. - **Other scopes.** On a package the palette no longer lists every package's objects and flows, because the package's own items replace them. The packages stay listed. `~org` and `~all` keep those lists and add their own menu entries. - **Where a pick opens.** Every address comes from `studioAddress.ts` (#36895). An object, flow or permission set goes through `studioItemPath`, so it opens its designer today and follows each designer card's `STUDIO_ITEM_PILLAR` switch with no edit here. Any other item opens `studioMetadataItemAddress(…, ?package=OWNER)`, the address its list row links to (ADR-0048). A menu entry goes to the menu entry's own `to`. - **How it leaves (decision 12): through the shell's unsaved-edits seam (M1).** `openStudioPaletteAddress` handles another page through `confirmUnsavedLeave`. That seam holds the surface's own work and every editor that registered its own, the "All metadata" item page (`ResourceEditPage`) among them; the surface's own bit never saw that page's edits. The page already open on another query (Default sharing from the Access pillar) goes through `reenterPillar`. It asks, then remounts the pillar once the router shows the requested query (S5): the palette's own `?palette=` change comes first and no longer triggers it. The page already shown, palette keys aside, just closes the palette. - The surface's `confirmLeavePillar` now goes through the same seam, so its own header departures ask about the item page's edits too: Back to app, the retired-Interfaces notice, the other-pillar `requestSurface` and the Access opener. They had the same blind spot; it is closed here, and no defect card is owed. - **The palette stays free of Studio reads.** `CommandPalette`'s `studio` scope takes an optional `surface` (`packageScope`, `renderGroups`, `open`), documented in the app-shell README. The page draws its own groups (`StudioPaletteGroups`), so the Studio modules load with the Studio chunk, never with the console's eager closure. `@object-ui/app-shell` is private, so the new optional prop and exported types widen no published surface: `Clause-②: no`. - **N4.** `ResourceEditPage`'s fullscreen Escape now ignores an Escape a dialog above it already took (`defaultPrevented`, which Radix sets), so closing the palette over a fullscreen editor no longer also leaves fullscreen. - **Card item 1 (`advertisedShortcuts.ts`)** needs no edit. `CommandPaletteProvider` already advertises ⌘K (`useAdvertiseShortcut(OPEN_COMMAND_PALETTE_SHORTCUT)`), and it now runs on every design page. - **Card item 4 (#35308)**: the studio scope searches no record, so it has no record title. Items are titled by their served metadata label, as their lists show them, and no second title rule exists. Files: - New: `studio-design/studioPaletteModel.ts` (pure: pair, items, addresses, groups, departure, `openStudioPaletteAddress`), `studio-design/StudioPaletteGroups.tsx` (reads and draws) and `studio-design/studioMenuData.ts` (the menu's shared data and vocabulary). - `StudioMenu.tsx`: it gains `StudioMenuDataProvider`, draws the shared data when a provider above holds it, and otherwise reads its own. - `StudioDesignSurface.tsx`: changes are in its shell region only: the providers, the palette mount, `confirmLeavePillar`, `reenterPillar` and `openFromPalette`. - `StudioRoute.tsx` is unchanged. No i18n key is added. - `e2e/studio-left-menu-36899.spec.ts` stubs the menu's reads where they now live. Read first, by risk: 1. `ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx`: `confirmLeavePillar` (now the seam), the `reenterPillar` latch, `openFromPalette` / `paletteSurface`, and the provider wrap. It is the only edit to a shared file beyond `StudioMenu.tsx`. 2. `ui/packages/app-shell/src/views/studio-design/studioPaletteModel.ts`: `openStudioPaletteAddress` and `studioPaletteItemsOf` over `scopeListRows`. 3. `ui/packages/app-shell/src/views/studio-design/studioMenuData.ts` with `StudioMenu.tsx`: the shared data and the menu's own-read fallback. ## Tests - `studioPaletteModel-36900.test.ts` (15 cases). It pins: - the pair; - items through `scopeListRows`: unwrapped, scoped, deduped and named by the primary key, with the list predicate applied; - pillar types following `studioItemPath` for every `STUDIO_ITEM_PILLAR` row, and other types on their area page with `?package=OWNER`; - the menu's six groups; - the leave / re-enter / stay decision; - M1 at the unit: with an editor registered, a leave asks its question (Cancel stays, OK goes), with a CONTROL that nothing registered asks nothing; re-entry hands the host the query to wait for. - `StudioPaletteGroups.surfaceScope-36900.test.tsx` (11 cases): the real `CommandPalette` + `CommandPaletteProvider` + `StudioMenuDataProvider` + `StudioPaletteGroups`, with the metadata reads doubled at the menu's own seam. It pins: - group headings and order, menu entries, and the package's and pair's items; - the list read's `include` and list predicate; - "Customization of" the package's name, with no `.custom` text shown; - no cross-package object or flow on a package; - addresses handed to `surface.open`, and matching; - "Searching…" then "No results", and a query typed before the lists answer: the arriving row is selected and Enter opens it; - no item list read until open, with its CONTROL; - `~all`. - `StudioDesignSurface.metadataArea-28561.test.tsx`: 7 new cases on the real surface. - Ctrl+K on a pillar, on `~all` and on a missing package. - **M1**: with the "All metadata" item page holding registered edits, a palette pick asks the page's question (Cancel keeps the page, OK leaves), and Back to app asks too. CONTROL: a clean page leaves at once. - **S5**: Default sharing picked on the real Access pillar shows the overview at `?surface=owd%3Aoverview`. - `ResourceEditPage.leaveGuard-13231.test.tsx` (2 new cases): **M1 on the real `ResourceEditPage`** with a dirty draft and the real palette leaving through `openStudioPaletteAddress`. Cancel keeps the page and the draft, OK leaves, and a CONTROL clean page leaves without asking. - `ResourceEditPage.detailTabs-36901.test.tsx` (1 new case): **N4**, an Escape a dialog took leaves the fullscreen and the page alone, with its CONTROL. <details><summary>Local readings, head 5e181ef / 7bbe1c5</summary> - Touched and related files at 5e181ef (new pins, StudioMenu, studioMenuModel, the address guard, all 16 `CommandPalette.*`, every console `StudioRoute*`): `Test Files 31 passed (31)`, `Tests 249 passed (249)`, lock `VERDICT command-exit 0`. 7bbe1c5 changes the e2e spec only. - All 83 `StudioDesignSurface.*.test.tsx` (at cf95fe5; later commits change no surface file): `Test Files 43 passed (43)`, `Tests 236 passed (236)` and `Test Files 40 passed (40)`, `Tests 217 passed (217)`. - `@object-ui/app-shell` `type-check` (both programs) and `type-check:e2e`: exit 0. `e2e/studio-left-menu-36899.spec.ts`, local: `3 passed`. - `pnpm --dir ui exec vitest run scripts/`: `Test Files 172 passed | 2 skipped (174)`. - Derived gate families (`dispatch-gates.mjs --commands`, 39): all exit 0 on the final tree; `--ran`: `39 derived, 39 run, 0 NOT-MEASURED, 0 UNRUN`. `check:new-line-citations` (ui): `0 new citation(s)`. eslint on the changed ui files: 0 errors, none in the new modules. - `overlap-check.mjs` before every push of the round: `VERDICT clean exit 0`. - CI at 7bbe1c5: 38 success, 13 expected skips, 0 failed. </details> <details><summary>Ablations (scripts/ablation-replace.mjs, each restored to HEAD: blob == HEAD, git diff HEAD empty)</summary> - A1, the seam dropped from the palette's leave (`confirmUnsavedLeave(() => act.navigate(to))` → `act.navigate(to)`): `Tests 3 failed | 33 passed`. The three M1 pins (real `ResourceEditPage`, surface, unit) go red. - A2, the seam dropped from `confirmLeavePillar`: `Tests 1 failed | 13 passed` (Back to app). - A3, the re-entry latch back to "the next query change": stays green (`14 passed`). Under test the palette's close and the navigation land in one render, so no pin tells the latch from the old trigger. The latch guards the ordering the code's own comment warns about: the router applying a navigation in a later render. - A4, a first-row selection added during the round: green in happy-dom and no effect live (a live probe with it removed). It was taken out again, so it is not on this head. - Round 0: the package-scope cross-package guard (`Tests 1 failed | 9 passed`) and the surface's palette mount (`Tests 3 failed | 7 passed`). </details> ## Acceptance notes - **Live walk-through, showcase leg: passed** (PR comment 7145761753). A real build, backend `--fresh`, and the Console dev server serving app-shell from `src` at this head, driven by headless Chromium as a person would. - One non-first item each of object, flow, permission set, hook and dashboard, found by label and opened at its list-row address with its label on the page. The object pick re-enters the Data page. - Ctrl+K on the cross-package catalog. - **M1** on a real item page with an unsaved edit: the pick asks once, Cancel keeps the page and the edit, Back to app asks, OK leaves. - **S5**: Default sharing from the Access page shows the overview. - **HotCRM leg: carried by #36910** (the joint walk-through card); this container has no HotCRM stack. - N1: `MetadataQuickFind` on ⌘⇧M (`DirectoryPage`) is a second item finder beside ⌘K; a follow-up retires or routes it. - N2: each open of the palette on a package reads one item list per listed type (the menu's types and counts are shared and not re-read). The client shares only in-flight reads. Draft-only items are not listed. - N5: nothing inside Studio advertises ⌘K. Studio's own header draws no search trigger, and the help dialog that lists advertised shortcuts is mounted only inside apps. - N6: `useStudioMenuTypes` no longer memoizes `types`, and the provider value is a new object each render. The palette's reads key on the type names, so this costs re-renders only. - N7: while the package entry loads, the customization label briefly names the base package by its id. - N8: the changeset's English body carries the six group names in Chinese too, beside the English. - Walk observation: with zero delay between Escape and the next Ctrl+K (automated), a query typed before the lists answered left no row highlighted. With no earlier close, or with a 1 s gap, it worked every time measured. This is synthetic timing, not filed. - #36784 (paused, pre-split) conflicts in `StudioDesignSurface.tsx` against `main` itself; this branch merges cleanly with `main` and #37089. ## Verification Two minutes: open any package in Studio (`/studio/PKG/data`), press ⌘K (Ctrl+K), type part of a dashboard's or hook's name, and press Enter. The palette lists the six menu groups and the item; Enter opens `/studio/PKG/metadata/TYPE/NAME?package=OWNER`. Edit a field on that item page without saving, then pick another entry: the leave prompt appears first, and Cancel keeps the edit. <details><summary>Where to look in code</summary> - Leave path: `openStudioPaletteAddress` (model) and `confirmLeavePillar` / `reenterPillar` / `openFromPalette` (surface). - Groups: `StudioPaletteGroups` (reads) over `useStudioMenuData` and `buildStudioPaletteGroups` / `studioPaletteItemAddress` (pure). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYkkwuF6UuFtu85Yd5H)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6f3a8da commit 355c73c

15 files changed

Lines changed: 1679 additions & 92 deletions

‎.changeset/36900-studio-cmdk.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
feat(studio): ⌘K on every Studio design page lists the package's whole menu and its items
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Studio redesign: an author switches between items with ×, ‹ › and ⌘K · #36900, part of #36890.
12+
13+
- **⌘K / Ctrl+K opens the command palette on every Studio design page.** That covers a package's pages and its "All metadata" area, the organization's own flows, and the cross-package positions-and-permissions catalog. Until now only the Studio start page had a palette, and the cross-package catalog had lost the one it used to have.
14+
- **On a package it lists the left menu, group by group**: Data, UI, Automation, Platform, Access, AI (数据、界面、自动化、平台、访问、AI), in the menu's order and under the menu's names. Each group holds the menu's own entries (each type's list, Organization flows, Default sharing, Diagnostics, Positions and permissions), then every item of the types it lists, the package's customizations included. Each item shows its type on the right; a customization is marked "Customization of" the package's name. The packages stay listed, so another package is one pick away. On a package the palette no longer lists every package's objects and flows: the package's own items replace them. The organization's flows and the cross-package catalog keep those lists and add their own menu entries.
15+
- **A pick opens what the menu and the lists open**: an object, a flow or a permission set in its designer, any other item on its own page in "All metadata", exactly where its list row leads. A menu entry goes where the menu entry goes.
16+
- **It never drops unsaved work silently.** A pick, like Studio's Back to app, asks first whenever the page holds unsaved edits, the "All metadata" item page's included. A pick of the page already open on another view (Default sharing, from the Access page) reopens that page on it; a pick of the page already shown just closes the palette.
17+
- The query matches an item by its label, its name or its type, and a menu entry by its label, its type or its group. While the package's lists are still loading, an empty result says "Searching…". The item lists are read only once the palette opens.
18+
- Pressing Escape to close a dialog over a full-screen item editor (the palette, for one) no longer also leaves full screen.

‎ui/e2e/studio-left-menu-36899.spec.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ function workspaceSources(): Plugin {
4040
name: 'studio-left-menu-workspace-src',
4141
enforce: 'pre',
4242
async resolveId(id, importer) {
43-
if (id.endsWith('/useMetadata.js') && importer?.endsWith('StudioMenu.tsx')) return METADATA_STUB;
43+
// objectstack#36900 — the menu's reads live in `studioMenuData.ts`, beside the menu.
44+
if (id.endsWith('/useMetadata.js') && (importer?.endsWith('StudioMenu.tsx') || importer?.endsWith('studioMenuData.ts'))) {
45+
return METADATA_STUB;
46+
}
4447
const m = /^@object-ui\/([a-z0-9-]+)(?:\/(.+))?$/.exec(id);
4548
if (!m) return null;
4649
const [, pkg, sub] = m;

‎ui/packages/app-shell/README.md‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,11 +1424,32 @@ record search. Its open state and the command that opens it are provided by
14241424

14251425
`CommandPalette` has two scopes. Inside an app it takes `apps`, `activeApp`,
14261426
`objects`, `onAppChange` and an optional `dataSource`, and searches that app.
1427-
`<CommandPalette scope="studio" />` takes no other prop: it is the palette of the
1428-
`/studio` landing, a frame outside every app, which the console mounts under its
1429-
own `CommandPaletteProvider`. It leaves out every app-scoped group and the
1430-
full-search command (their links start with `/apps/APP`), and lists the Studio's
1431-
packages, their objects and their flows, each opening its Studio page. The
1427+
`<CommandPalette scope="studio" />` is the palette of Studio, outside every app.
1428+
It leaves out every app-scoped group and the full-search command (their links
1429+
start with `/apps/APP`), and lists the Studio's packages, their objects and their
1430+
flows, each opening its Studio page. On the `/studio` landing the console mounts
1431+
it with no other prop, under its own `CommandPaletteProvider`.
1432+
1433+
On a Studio design page, `StudioDesignSurface` mounts it itself, with an optional
1434+
`surface` prop (a `StudioPaletteSurface`; objectstack#36900). The surface mounts
1435+
its own `CommandPaletteProvider` unless a host above it already mounts one.
1436+
1437+
- `renderGroups({ query, open, onLoadingChange })` returns the page's own groups:
1438+
`StudioPaletteGroups`, which draws the left menu's six groups (the menu's data
1439+
shared through `StudioMenuDataProvider`, read once per page). On a package each
1440+
group also holds every item of its types, read from the type's list as its
1441+
list page reads it. They are drawn above the packages and mounted only while
1442+
the palette is open. `open` closes the palette and opens a Studio address;
1443+
`onLoadingChange` keeps the empty result on "Searching…" while a list is read.
1444+
- `packageScope: true` (a package's page) drops every package's objects and
1445+
flows: the page's groups list that package's items instead.
1446+
- `open(to)` is the page's departure (`openStudioPaletteAddress`). It asks the
1447+
shell's unsaved-edits seam (`confirmUnsavedLeave`), so every registered editor
1448+
is asked about, the "All metadata" item page included, then navigates. A pick
1449+
of the page already open on another query re-enters it once the router shows
1450+
that query; a pick of the page already shown only closes the palette.
1451+
1452+
The
14321453
header's search trigger is drawn wherever a provider is mounted, so `AppHeader`
14331454
with `variant="studio"` shows it there. Inside an app, on every route
14341455
(`system/*` included) from the `lg` breakpoint up, `AppHeader` draws it as the

‎ui/packages/app-shell/src/chrome/CommandPalette.tsx‎

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
* app. On `/studio` (`scope="studio"`), a frame outside every app, it has no
1616
* app-scoped group and no full-search command, whose links all start with
1717
* `/apps/APP`; it lists the Studio's packages, objects and flows instead, each
18-
* opening its Studio page.
18+
* opening its Studio page. On a Studio design page (objectstack#36900) the page
19+
* hands the palette its own groups (`surface`): on a package, every type and
20+
* item of that package by the left menu's groups, in place of every package's
21+
* objects and flows.
1922
*
2023
* A failure inside the palette closes it and leaves the console mounted; the
2124
* next open draws a fresh palette (objectui#13387).
@@ -123,6 +126,45 @@ interface AppCommandPaletteProps {
123126
*/
124127
interface StudioCommandPaletteProps {
125128
scope: 'studio';
129+
/**
130+
* The Studio design page the palette is open on (objectstack#36900), which
131+
* hands it that page's own groups; omitted on the `/studio` landing.
132+
*/
133+
surface?: StudioPaletteSurface;
134+
}
135+
136+
/** What a scope's own groups are handed while the palette is open (objectstack#36900). */
137+
export interface StudioPaletteGroupsProps {
138+
/** The typed query, matched with `matchesPaletteQuery`. */
139+
query: string;
140+
/** Closes the palette and opens a Studio address, through the page's {@link StudioPaletteSurface.open}. */
141+
open: (to: string) => void;
142+
/** Whether a read the groups wait on is still in flight: the empty palette says "Searching…" meanwhile. */
143+
onLoadingChange: (loading: boolean) => void;
144+
}
145+
146+
/**
147+
* A Studio design page's half of the palette (objectstack#36900): the page
148+
* knows its scope, its unsaved work and how it re-enters itself, so it draws
149+
* its own groups and opens what is picked. The palette stays free of the
150+
* page's reads: they load with the page, never with the console.
151+
*/
152+
export interface StudioPaletteSurface {
153+
/**
154+
* Whether the page is one package's. Its groups then list that package's
155+
* items, so the palette does not also list every package's objects and
156+
* flows; the package-less scope and the cross-package leg keep them.
157+
*/
158+
packageScope: boolean;
159+
/** The page's groups for the query, drawn above the packages; mounted only while the palette is open. */
160+
renderGroups: (props: StudioPaletteGroupsProps) => ReactNode;
161+
/**
162+
* Opens a Studio address the palette picked, after it closes: the page asks
163+
* the shell's unsaved-edits seam (every editor that registered edits, not
164+
* only the page's own), and re-enters itself when the address is the page
165+
* already open on another query (`openStudioPaletteAddress`).
166+
*/
167+
open: (to: string) => void;
126168
}
127169

128170
type CommandPaletteProps = AppCommandPaletteProps | StudioCommandPaletteProps;
@@ -372,8 +414,15 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
372414

373415
// objectui#11863 — the Studio's packages, objects and flows, read only while
374416
// the palette is open in the `studio` scope, matched like the entries above.
375-
const studio = useStudioPaletteEntries(open && inStudio);
417+
//
418+
// objectstack#36900 — on a design page the page draws its own groups, and
419+
// on a package those list its items in place of every package's objects
420+
// and flows. What the palette picks there opens through the page.
421+
const surface = inStudio ? props.surface : undefined;
422+
const studio = useStudioPaletteEntries(open && inStudio, !surface?.packageScope);
376423
const studioMatches = (entry: StudioPaletteEntry) => matches(entry.label, entry.name);
424+
const openStudio = (to: string) => (surface ? runCommand(() => surface.open(to)) : leaveTo(to));
425+
const [surfaceLoading, setSurfaceLoading] = useState(false);
377426
const studioPackages = studio.packages.filter(studioMatches);
378427
const studioObjects = studio.objects.filter(studioMatches);
379428
const studioFlows = studio.flows.filter(studioMatches);
@@ -585,7 +634,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
585634
/>
586635
<CommandList className="min-w-0">
587636
<CommandEmpty>
588-
{isSearching || studio.loading ? (
637+
{isSearching || studio.loading || surfaceLoading ? (
589638
<span className="inline-flex items-center gap-2 text-muted-foreground">
590639
<span
591640
aria-hidden
@@ -766,6 +815,9 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
766815
</CommandGroup>
767816
)}
768817

818+
{/* objectstack#36900 — a Studio design page's own groups, first. */}
819+
{open && surface?.renderGroups({ query: inputValue, open: openStudio, onLoadingChange: setSurfaceLoading })}
820+
769821
{/* Studio (objectui#11863): packages, objects and flows, `studio` scope only */}
770822
{studioPackages.length > 0 && (
771823
<CommandGroup heading={t('console.commandPalette.packages')}>
@@ -775,7 +827,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
775827
kind="studio-package"
776828
entry={entry}
777829
Icon={Boxes}
778-
onOpen={() => leaveTo(entry.href)}
830+
onOpen={() => openStudio(entry.href)}
779831
/>
780832
))}
781833
</CommandGroup>
@@ -788,7 +840,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
788840
kind="studio-object"
789841
entry={entry}
790842
Icon={Database}
791-
onOpen={() => leaveTo(entry.href)}
843+
onOpen={() => openStudio(entry.href)}
792844
/>
793845
))}
794846
</CommandGroup>
@@ -801,7 +853,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
801853
kind="studio-flow"
802854
entry={entry}
803855
Icon={Workflow}
804-
onOpen={() => leaveTo(entry.href)}
856+
onOpen={() => openStudio(entry.href)}
805857
/>
806858
))}
807859
</CommandGroup>
@@ -1056,8 +1108,12 @@ const NO_STUDIO_ENTRIES: StudioPaletteEntries = { packages: [], objects: [], flo
10561108
* cache list. Until the package list answers nothing is listed, so no entry
10571109
* is drawn without its package. If that read fails, the packaged entries are
10581110
* left out; the landing behind the palette shows the same read's error.
1111+
*
1112+
* `crossPackageItems` false (a package's design page, objectstack#36900)
1113+
* lists the packages alone: the page lists its own package's items, and the
1114+
* objects and flows of every package are neither read nor listed.
10591115
*/
1060-
function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries {
1116+
function useStudioPaletteEntries(enabled: boolean, crossPackageItems = true): StudioPaletteEntries {
10611117
const metadata = useMetadata();
10621118
const { t } = useObjectTranslation();
10631119
const [packages, setPackages] = useState<PkgEntry[] | null>(null);
@@ -1082,9 +1138,10 @@ function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries {
10821138

10831139
// Read only while open: each read starts that type's fetch when it has not
10841140
// been loaded yet, and the provider re-renders this palette when it answers.
1085-
const objectItems: StudioServedItem[] = metadata.objects;
1086-
const flowItems: StudioServedItem[] = metadata.getItemsByType('flow');
1141+
const objectItems: StudioServedItem[] = crossPackageItems ? metadata.objects : [];
1142+
const flowItems: StudioServedItem[] = crossPackageItems ? metadata.getItemsByType('flow') : [];
10871143
const typeLoading = (type: string) => {
1144+
if (!crossPackageItems) return false;
10881145
const status = metadata.getTypeStatus?.(type);
10891146
return status === 'idle' || status === 'loading';
10901147
};

‎ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.detailTabs-36901.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,28 @@ describe('carry-forward N2 — Esc reaches the non-Radix fullscreen first', () =
201201
expect(await screen.findByTestId('list-page')).toBeInTheDocument();
202202
expect(where()).toBe('/studio/com.acme.app/metadata/canvas_36901?package=com.acme.app');
203203
});
204+
205+
it('objectstack#36900 — an Esc a dialog above already took (the command palette closing) leaves the fullscreen and the page alone', async () => {
206+
open('canvas_36901', '?package=com.acme.app');
207+
await screen.findByTestId('canvas-stub');
208+
fireEvent.click(screen.getByTitle(t('engine.edit.fullscreen', 'en-US')));
209+
expect(screen.getByTitle(t('engine.edit.exitFullscreen', 'en-US'))).toBeInTheDocument();
210+
211+
// A Radix layer takes its Escape in the capture phase and marks it handled.
212+
const takenByDialog = (e: KeyboardEvent) => {
213+
if (e.key === 'Escape') e.preventDefault();
214+
};
215+
document.addEventListener('keydown', takenByDialog, true);
216+
try {
217+
fireEvent.keyDown(document.body, { key: 'Escape' });
218+
} finally {
219+
document.removeEventListener('keydown', takenByDialog, true);
220+
}
221+
expect(screen.getByTitle(t('engine.edit.exitFullscreen', 'en-US'))).toBeInTheDocument();
222+
expect(where()).toBe('/studio/com.acme.app/metadata/canvas_36901/w1?package=com.acme.app');
223+
224+
// CONTROL: the next Esc nobody took leaves the fullscreen.
225+
fireEvent.keyDown(document.body, { key: 'Escape' });
226+
await waitFor(() => expect(screen.getByTitle(t('engine.edit.fullscreen', 'en-US'))).toBeInTheDocument());
227+
});
204228
});

‎ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.leaveGuard-13231.test.tsx‎

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
*/
2121

2222
import '@testing-library/jest-dom/vitest';
23+
// The source under test reaches a dynamic import of this module: its first load is paid here, at collection, never inside a case's clock (`check:test-source-alias`).
24+
import '@objectstack/lint';
2325
import * as React from 'react';
2426
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
2527
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
26-
import { Link, MemoryRouter, Route, Routes } from 'react-router-dom';
28+
import { Link, MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
29+
import { CommandItem } from '@object-ui/components';
2730
import { z } from 'zod';
2831
import { ComponentRegistry } from '@object-ui/core';
2932
import { DocSchema } from '@objectstack/spec/system';
@@ -89,6 +92,9 @@ import { registerDefaultMetadataSchemas } from './default-schemas';
8992
import { registerBuiltinPreviews } from './previews';
9093
import { t } from './i18n';
9194
import { confirmUnsavedLeave } from '../../chrome/unsavedEdits';
95+
import { CommandPalette, type StudioPaletteSurface } from '../../chrome/CommandPalette';
96+
import { CommandPaletteProvider } from '../../context/CommandPaletteProvider';
97+
import { openStudioPaletteAddress } from '../studio-design/studioPaletteModel';
9298

9399
const DOC_JSON_SCHEMA = z.toJSONSchema(DocSchema as unknown as z.ZodType) as Record<string, unknown>;
94100
client.current = new MetadataClient({ baseUrl: '', fetch: vi.fn(serve) as unknown as typeof fetch });
@@ -220,3 +226,82 @@ describe('MetadataResourceEditPage registers its unsaved draft with the shell se
220226
expect(confirmSpy).not.toHaveBeenCalled();
221227
});
222228
});
229+
230+
/**
231+
* objectstack#36900 (L1 M1) — a Studio palette pick leaves this page the way
232+
* the Studio surface opens it (`openStudioPaletteAddress`): through the seam,
233+
* so the page's own registered draft is asked about, though the surface's own
234+
* unsaved bit never saw it. The real page and the real palette; the surface's
235+
* groups are one entry.
236+
*/
237+
describe('a Studio palette pick asks before it drops this page\'s unsaved draft (objectstack#36900)', () => {
238+
function StudioPalette() {
239+
const navigate = useNavigate();
240+
const { pathname, search } = useLocation();
241+
const surface: StudioPaletteSurface = {
242+
packageScope: true,
243+
renderGroups: ({ open }) => (
244+
<CommandItem value="studio-entry docs" onSelect={() => open('/metadata/doc')}>
245+
All docs
246+
</CommandItem>
247+
),
248+
open: (to) => openStudioPaletteAddress(to, { pathname, search }, { navigate, reenter: () => true }),
249+
};
250+
return <CommandPalette scope="studio" surface={surface} />;
251+
}
252+
253+
// The studio palette reads the package list when it opens: an empty one.
254+
beforeEach(() => {
255+
vi.stubGlobal('fetch', vi.fn(async () => json(200, { data: [] })));
256+
});
257+
afterEach(() => {
258+
vi.unstubAllGlobals();
259+
});
260+
261+
async function openGuideWithPalette() {
262+
active.set('doc/guide', { name: 'guide', label: 'Guide', content: '# Live', group: 'reference' });
263+
render(
264+
<MemoryRouter initialEntries={['/metadata/doc/guide']}>
265+
<CommandPaletteProvider>
266+
<StudioPalette />
267+
<Routes>
268+
<Route path="/metadata/doc/:name" element={<MetadataResourceEditPage type="doc" name="guide" />} />
269+
<Route path="/metadata/doc" element={<div>Docs list</div>} />
270+
</Routes>
271+
</CommandPaletteProvider>
272+
</MemoryRouter>,
273+
);
274+
expect(await source()).toHaveValue('# Live');
275+
await settle();
276+
}
277+
278+
async function pickAllDocs() {
279+
fireEvent.keyDown(document, { key: 'k', ctrlKey: true });
280+
const item = await screen.findByText('All docs');
281+
fireEvent.click(item);
282+
await settle();
283+
}
284+
285+
it("Cancel keeps the page and the draft; OK leaves", async () => {
286+
await openGuideWithPalette();
287+
await editSource();
288+
289+
await pickAllDocs();
290+
expect(confirmSpy).toHaveBeenCalledTimes(1);
291+
expect(confirmSpy).toHaveBeenCalledWith(QUESTION);
292+
expect(screen.queryByText('Docs list')).toBeNull();
293+
expect(await source()).toHaveValue('# Live, edited');
294+
295+
confirmSpy.mockReturnValue(true);
296+
await pickAllDocs();
297+
expect(confirmSpy).toHaveBeenCalledTimes(2);
298+
expect(await screen.findByText('Docs list')).toBeTruthy();
299+
});
300+
301+
it('CONTROL: a clean page leaves at once, asking nothing', async () => {
302+
await openGuideWithPalette();
303+
await pickAllDocs();
304+
expect(await screen.findByText('Docs list')).toBeTruthy();
305+
expect(confirmSpy).not.toHaveBeenCalled();
306+
});
307+
});

‎ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,11 +1717,13 @@ function MetadataResourceEditPageImpl({
17171717
document.body.style.overflow = prev;
17181718
};
17191719
}, [isFullscreen]);
1720-
// Escape exits fullscreen.
1720+
// Escape exits fullscreen. objectstack#36900 — not an Escape a dialog over
1721+
// the page (the command palette, a confirm) already took to close itself:
1722+
// Radix's dismissable layer marks the one it acts on `defaultPrevented`.
17211723
React.useEffect(() => {
17221724
if (typeof window === 'undefined' || !isFullscreen) return;
17231725
function onKey(e: KeyboardEvent) {
1724-
if (e.key === 'Escape') {
1726+
if (e.key === 'Escape' && !e.defaultPrevented) {
17251727
e.preventDefault();
17261728
setIsFullscreen(false);
17271729
}

0 commit comments

Comments
 (0)