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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/36900-studio-cmdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

feat(studio): ⌘K on every Studio design page lists the package's whole menu and its items

Clause-②: no
Metadata-protocol: none

Studio redesign: an author switches between items with ×, ‹ › and ⌘K · #36900, part of #36890.

- **⌘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.
- **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.
- **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.
- **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.
- 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.
- Pressing Escape to close a dialog over a full-screen item editor (the palette, for one) no longer also leaves full screen.
5 changes: 4 additions & 1 deletion ui/e2e/studio-left-menu-36899.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ function workspaceSources(): Plugin {
name: 'studio-left-menu-workspace-src',
enforce: 'pre',
async resolveId(id, importer) {
if (id.endsWith('/useMetadata.js') && importer?.endsWith('StudioMenu.tsx')) return METADATA_STUB;
// objectstack#36900 — the menu's reads live in `studioMenuData.ts`, beside the menu.
if (id.endsWith('/useMetadata.js') && (importer?.endsWith('StudioMenu.tsx') || importer?.endsWith('studioMenuData.ts'))) {
return METADATA_STUB;
}
const m = /^@object-ui\/([a-z0-9-]+)(?:\/(.+))?$/.exec(id);
if (!m) return null;
const [, pkg, sub] = m;
Expand Down
31 changes: 26 additions & 5 deletions ui/packages/app-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1424,11 +1424,32 @@ record search. Its open state and the command that opens it are provided by

`CommandPalette` has two scopes. Inside an app it takes `apps`, `activeApp`,
`objects`, `onAppChange` and an optional `dataSource`, and searches that app.
`<CommandPalette scope="studio" />` takes no other prop: it is the palette of the
`/studio` landing, a frame outside every app, which the console mounts under its
own `CommandPaletteProvider`. It leaves out every app-scoped group and the
full-search command (their links start with `/apps/APP`), and lists the Studio's
packages, their objects and their flows, each opening its Studio page. The
`<CommandPalette scope="studio" />` is the palette of Studio, outside every app.
It leaves out every app-scoped group and the full-search command (their links
start with `/apps/APP`), and lists the Studio's packages, their objects and their
flows, each opening its Studio page. On the `/studio` landing the console mounts
it with no other prop, under its own `CommandPaletteProvider`.

On a Studio design page, `StudioDesignSurface` mounts it itself, with an optional
`surface` prop (a `StudioPaletteSurface`; objectstack#36900). The surface mounts
its own `CommandPaletteProvider` unless a host above it already mounts one.

- `renderGroups({ query, open, onLoadingChange })` returns the page's own groups:
`StudioPaletteGroups`, which draws the left menu's six groups (the menu's data
shared through `StudioMenuDataProvider`, read once per page). On a package each
group also holds every item of its types, read from the type's list as its
list page reads it. They are drawn above the packages and mounted only while
the palette is open. `open` closes the palette and opens a Studio address;
`onLoadingChange` keeps the empty result on "Searching…" while a list is read.
- `packageScope: true` (a package's page) drops every package's objects and
flows: the page's groups list that package's items instead.
- `open(to)` is the page's departure (`openStudioPaletteAddress`). It asks the
shell's unsaved-edits seam (`confirmUnsavedLeave`), so every registered editor
is asked about, the "All metadata" item page included, then navigates. A pick
of the page already open on another query re-enters it once the router shows
that query; a pick of the page already shown only closes the palette.

The
header's search trigger is drawn wherever a provider is mounted, so `AppHeader`
with `variant="studio"` shows it there. Inside an app, on every route
(`system/*` included) from the `lg` breakpoint up, `AppHeader` draws it as the
Expand Down
75 changes: 66 additions & 9 deletions ui/packages/app-shell/src/chrome/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
* app. On `/studio` (`scope="studio"`), a frame outside every app, it has no
* app-scoped group and no full-search command, whose links all start with
* `/apps/APP`; it lists the Studio's packages, objects and flows instead, each
* opening its Studio page.
* opening its Studio page. On a Studio design page (objectstack#36900) the page
* hands the palette its own groups (`surface`): on a package, every type and
* item of that package by the left menu's groups, in place of every package's
* objects and flows.
*
* A failure inside the palette closes it and leaves the console mounted; the
* next open draws a fresh palette (objectui#13387).
Expand Down Expand Up @@ -123,6 +126,45 @@ interface AppCommandPaletteProps {
*/
interface StudioCommandPaletteProps {
scope: 'studio';
/**
* The Studio design page the palette is open on (objectstack#36900), which
* hands it that page's own groups; omitted on the `/studio` landing.
*/
surface?: StudioPaletteSurface;
}

/** What a scope's own groups are handed while the palette is open (objectstack#36900). */
export interface StudioPaletteGroupsProps {
/** The typed query, matched with `matchesPaletteQuery`. */
query: string;
/** Closes the palette and opens a Studio address, through the page's {@link StudioPaletteSurface.open}. */
open: (to: string) => void;
/** Whether a read the groups wait on is still in flight: the empty palette says "Searching…" meanwhile. */
onLoadingChange: (loading: boolean) => void;
}

/**
* A Studio design page's half of the palette (objectstack#36900): the page
* knows its scope, its unsaved work and how it re-enters itself, so it draws
* its own groups and opens what is picked. The palette stays free of the
* page's reads: they load with the page, never with the console.
*/
export interface StudioPaletteSurface {
/**
* Whether the page is one package's. Its groups then list that package's
* items, so the palette does not also list every package's objects and
* flows; the package-less scope and the cross-package leg keep them.
*/
packageScope: boolean;
/** The page's groups for the query, drawn above the packages; mounted only while the palette is open. */
renderGroups: (props: StudioPaletteGroupsProps) => ReactNode;
/**
* Opens a Studio address the palette picked, after it closes: the page asks
* the shell's unsaved-edits seam (every editor that registered edits, not
* only the page's own), and re-enters itself when the address is the page
* already open on another query (`openStudioPaletteAddress`).
*/
open: (to: string) => void;
}

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

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

{/* objectstack#36900 — a Studio design page's own groups, first. */}
{open && surface?.renderGroups({ query: inputValue, open: openStudio, onLoadingChange: setSurfaceLoading })}

{/* Studio (objectui#11863): packages, objects and flows, `studio` scope only */}
{studioPackages.length > 0 && (
<CommandGroup heading={t('console.commandPalette.packages')}>
Expand All @@ -775,7 +827,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
kind="studio-package"
entry={entry}
Icon={Boxes}
onOpen={() => leaveTo(entry.href)}
onOpen={() => openStudio(entry.href)}
/>
))}
</CommandGroup>
Expand All @@ -788,7 +840,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
kind="studio-object"
entry={entry}
Icon={Database}
onOpen={() => leaveTo(entry.href)}
onOpen={() => openStudio(entry.href)}
/>
))}
</CommandGroup>
Expand All @@ -801,7 +853,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
kind="studio-flow"
entry={entry}
Icon={Workflow}
onOpen={() => leaveTo(entry.href)}
onOpen={() => openStudio(entry.href)}
/>
))}
</CommandGroup>
Expand Down Expand Up @@ -1056,8 +1108,12 @@ const NO_STUDIO_ENTRIES: StudioPaletteEntries = { packages: [], objects: [], flo
* cache list. Until the package list answers nothing is listed, so no entry
* is drawn without its package. If that read fails, the packaged entries are
* left out; the landing behind the palette shows the same read's error.
*
* `crossPackageItems` false (a package's design page, objectstack#36900)
* lists the packages alone: the page lists its own package's items, and the
* objects and flows of every package are neither read nor listed.
*/
function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries {
function useStudioPaletteEntries(enabled: boolean, crossPackageItems = true): StudioPaletteEntries {
const metadata = useMetadata();
const { t } = useObjectTranslation();
const [packages, setPackages] = useState<PkgEntry[] | null>(null);
Expand All @@ -1082,9 +1138,10 @@ function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries {

// Read only while open: each read starts that type's fetch when it has not
// been loaded yet, and the provider re-renders this palette when it answers.
const objectItems: StudioServedItem[] = metadata.objects;
const flowItems: StudioServedItem[] = metadata.getItemsByType('flow');
const objectItems: StudioServedItem[] = crossPackageItems ? metadata.objects : [];
const flowItems: StudioServedItem[] = crossPackageItems ? metadata.getItemsByType('flow') : [];
const typeLoading = (type: string) => {
if (!crossPackageItems) return false;
const status = metadata.getTypeStatus?.(type);
return status === 'idle' || status === 'loading';
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,28 @@ describe('carry-forward N2 — Esc reaches the non-Radix fullscreen first', () =
expect(await screen.findByTestId('list-page')).toBeInTheDocument();
expect(where()).toBe('/studio/com.acme.app/metadata/canvas_36901?package=com.acme.app');
});

it('objectstack#36900 — an Esc a dialog above already took (the command palette closing) leaves the fullscreen and the page alone', async () => {
open('canvas_36901', '?package=com.acme.app');
await screen.findByTestId('canvas-stub');
fireEvent.click(screen.getByTitle(t('engine.edit.fullscreen', 'en-US')));
expect(screen.getByTitle(t('engine.edit.exitFullscreen', 'en-US'))).toBeInTheDocument();

// A Radix layer takes its Escape in the capture phase and marks it handled.
const takenByDialog = (e: KeyboardEvent) => {
if (e.key === 'Escape') e.preventDefault();
};
document.addEventListener('keydown', takenByDialog, true);
try {
fireEvent.keyDown(document.body, { key: 'Escape' });
} finally {
document.removeEventListener('keydown', takenByDialog, true);
}
expect(screen.getByTitle(t('engine.edit.exitFullscreen', 'en-US'))).toBeInTheDocument();
expect(where()).toBe('/studio/com.acme.app/metadata/canvas_36901/w1?package=com.acme.app');

// CONTROL: the next Esc nobody took leaves the fullscreen.
fireEvent.keyDown(document.body, { key: 'Escape' });
await waitFor(() => expect(screen.getByTitle(t('engine.edit.fullscreen', 'en-US'))).toBeInTheDocument());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
*/

import '@testing-library/jest-dom/vitest';
// 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`).
import '@objectstack/lint';
import * as React from 'react';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
import { Link, MemoryRouter, Route, Routes } from 'react-router-dom';
import { Link, MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import { CommandItem } from '@object-ui/components';
import { z } from 'zod';
import { ComponentRegistry } from '@object-ui/core';
import { DocSchema } from '@objectstack/spec/system';
Expand Down Expand Up @@ -89,6 +92,9 @@ import { registerDefaultMetadataSchemas } from './default-schemas';
import { registerBuiltinPreviews } from './previews';
import { t } from './i18n';
import { confirmUnsavedLeave } from '../../chrome/unsavedEdits';
import { CommandPalette, type StudioPaletteSurface } from '../../chrome/CommandPalette';
import { CommandPaletteProvider } from '../../context/CommandPaletteProvider';
import { openStudioPaletteAddress } from '../studio-design/studioPaletteModel';

const DOC_JSON_SCHEMA = z.toJSONSchema(DocSchema as unknown as z.ZodType) as Record<string, unknown>;
client.current = new MetadataClient({ baseUrl: '', fetch: vi.fn(serve) as unknown as typeof fetch });
Expand Down Expand Up @@ -220,3 +226,82 @@ describe('MetadataResourceEditPage registers its unsaved draft with the shell se
expect(confirmSpy).not.toHaveBeenCalled();
});
});

/**
* objectstack#36900 (L1 M1) — a Studio palette pick leaves this page the way
* the Studio surface opens it (`openStudioPaletteAddress`): through the seam,
* so the page's own registered draft is asked about, though the surface's own
* unsaved bit never saw it. The real page and the real palette; the surface's
* groups are one entry.
*/
describe('a Studio palette pick asks before it drops this page\'s unsaved draft (objectstack#36900)', () => {
function StudioPalette() {
const navigate = useNavigate();
const { pathname, search } = useLocation();
const surface: StudioPaletteSurface = {
packageScope: true,
renderGroups: ({ open }) => (
<CommandItem value="studio-entry docs" onSelect={() => open('/metadata/doc')}>
All docs
</CommandItem>
),
open: (to) => openStudioPaletteAddress(to, { pathname, search }, { navigate, reenter: () => true }),
};
return <CommandPalette scope="studio" surface={surface} />;
}

// The studio palette reads the package list when it opens: an empty one.
beforeEach(() => {
vi.stubGlobal('fetch', vi.fn(async () => json(200, { data: [] })));
});
afterEach(() => {
vi.unstubAllGlobals();
});

async function openGuideWithPalette() {
active.set('doc/guide', { name: 'guide', label: 'Guide', content: '# Live', group: 'reference' });
render(
<MemoryRouter initialEntries={['/metadata/doc/guide']}>
<CommandPaletteProvider>
<StudioPalette />
<Routes>
<Route path="/metadata/doc/:name" element={<MetadataResourceEditPage type="doc" name="guide" />} />
<Route path="/metadata/doc" element={<div>Docs list</div>} />
</Routes>
</CommandPaletteProvider>
</MemoryRouter>,
);
expect(await source()).toHaveValue('# Live');
await settle();
}

async function pickAllDocs() {
fireEvent.keyDown(document, { key: 'k', ctrlKey: true });
const item = await screen.findByText('All docs');
fireEvent.click(item);
await settle();
}

it("Cancel keeps the page and the draft; OK leaves", async () => {
await openGuideWithPalette();
await editSource();

await pickAllDocs();
expect(confirmSpy).toHaveBeenCalledTimes(1);
expect(confirmSpy).toHaveBeenCalledWith(QUESTION);
expect(screen.queryByText('Docs list')).toBeNull();
expect(await source()).toHaveValue('# Live, edited');

confirmSpy.mockReturnValue(true);
await pickAllDocs();
expect(confirmSpy).toHaveBeenCalledTimes(2);
expect(await screen.findByText('Docs list')).toBeTruthy();
});

it('CONTROL: a clean page leaves at once, asking nothing', async () => {
await openGuideWithPalette();
await pickAllDocs();
expect(await screen.findByText('Docs list')).toBeTruthy();
expect(confirmSpy).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1717,11 +1717,13 @@ function MetadataResourceEditPageImpl({
document.body.style.overflow = prev;
};
}, [isFullscreen]);
// Escape exits fullscreen.
// Escape exits fullscreen. objectstack#36900 — not an Escape a dialog over
// the page (the command palette, a confirm) already took to close itself:
// Radix's dismissable layer marks the one it acts on `defaultPrevented`.
React.useEffect(() => {
if (typeof window === 'undefined' || !isFullscreen) return;
function onKey(e: KeyboardEvent) {
if (e.key === 'Escape') {
if (e.key === 'Escape' && !e.defaultPrevented) {
e.preventDefault();
setIsFullscreen(false);
}
Expand Down
Loading
Loading