From 0420faf6f0494b970eb9dfd8f0ead820d8de67d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 17:24:16 +0000 Subject: [PATCH 1/5] =?UTF-8?q?feat(studio):=20the=20left=20menu=20reads?= =?UTF-8?q?=20the=20placement=20table=20=E2=80=94=20=E5=B8=B8=E7=94=A8=20g?= =?UTF-8?q?roups=20and=20one=20=E3=80=8C=E9=AB=98=E7=BA=A7=E3=80=8D=20fold?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit buildStudioMenu orders each group by STUDIO_MENU_PLACEMENT and stamps each entry's tier; the four entries that are not a type are 高级; the 常用 types are always listed on a package; an empty 常用 type means the settled sweep counted none. StudioMenu draws muted group labels with no count, and folds the 高级 entries under one button remembered in the studio_menu_advanced cookie. Claude-Session: https://claude.ai/code/session_01QSeKYniqTW93usTV1hShjE Co-authored-by: Claude --- ui/e2e/studio-left-menu-36899.spec.ts | 44 ++- .../views/studio-design/StudioMenu.test.tsx | 251 ++++++++++++++++-- .../src/views/studio-design/StudioMenu.tsx | 201 +++++++++----- .../src/views/studio-design/studioMenuData.ts | 14 +- .../studio-design/studioMenuModel.test.ts | 170 +++++++++++- .../views/studio-design/studioMenuModel.ts | 125 +++++++-- .../studio-design/studioMenuPlacement.ts | 27 +- ui/packages/i18n/src/namespaces/studio/en.ts | 3 + ui/packages/i18n/src/namespaces/studio/zh.ts | 3 + 9 files changed, 713 insertions(+), 125 deletions(-) diff --git a/ui/e2e/studio-left-menu-36899.spec.ts b/ui/e2e/studio-left-menu-36899.spec.ts index 9ac183bfa73..f8084cadb9d 100644 --- a/ui/e2e/studio-left-menu-36899.spec.ts +++ b/ui/e2e/studio-left-menu-36899.spec.ts @@ -18,6 +18,10 @@ import { uiRoot } from '../scripts/ui-root.mjs'; * full width, still collapsed after a reload (Studio's own cookie, on a real * http origin), and a drawer over the page at phone width. * + * objectstack#37201 — the 「高级」 fold laid out: closed by default with its + * groups out of sight, opened by a click, and still open after a reload under + * its own cookie (`studio_menu_advanced`), the collapse cookie untouched. + * * REAL: `StudioMenuProvider`, `StudioMenuTrigger`, `StudioMenu` and everything * they import (the sidebar primitive, the menu model, the i18n), bundled by * Vite from source, and the real Tailwind theme compiled for the classes on @@ -65,7 +69,7 @@ const ENTRIES = [ ]; export const useMetadataClient = () => ({}); export const useMetadataTypes = () => ({ loading: false, error: null, entries: ENTRIES }); -export const useGlobalDiagnostics = () => ({ countsByType: { object: 12 }, packagesByType: {}, reload: () => {} }); +export const useGlobalDiagnostics = () => ({ loading: false, error: null, countsByType: { object: 12 }, packagesByType: {}, reload: () => {} }); `; }, }; @@ -175,8 +179,11 @@ test.beforeAll(async ({ browser }) => { )).forEach((c) => c && seen.add(c)); await open(page, 1280); await collect(); + await page.getByTestId('studio-menu-advanced-toggle').click(); + await collect(); await page.getByTestId('studio-menu-toggle').click(); await collect(); + await page.context().clearCookies(); await open(page, 390); await page.getByTestId('studio-menu-toggle').click(); await page.waitForSelector('[role="dialog"]'); @@ -186,7 +193,7 @@ test.beforeAll(async ({ browser }) => { }); test.describe('Studio left menu (objectstack#36899)', () => { - test('wide: docked at the left, six groups, the content beside it', async ({ page }, testInfo) => { + test('wide: docked at the left, the 常用 groups shown, the content beside it', async ({ page }, testInfo) => { await open(page, 1280); const panel = await rect(page, PANEL); const content = await rect(page, '#content'); @@ -195,12 +202,43 @@ test.describe('Studio left menu (objectstack#36899)', () => { expect(panel.width).toBeGreaterThanOrEqual(255); expect(panel.width).toBeLessThanOrEqual(256); expect(content.left).toBeGreaterThanOrEqual(panel.right - 1); - for (const g of ['data', 'ui', 'automation', 'system', 'security', 'ai']) { + // objectstack#37201 — the served 常用 types' groups; 平台 Platform holds only 高级 entries. + for (const g of ['data', 'automation', 'security']) { await expect(page.getByTestId(`studio-menu-group-${g}`)).toBeVisible(); } + await expect(page.getByTestId('studio-menu-group-system')).toHaveCount(0); await testInfo.attach('wide', { body: await page.screenshot(), contentType: 'image/png' }); }); + test('the 高级 fold: closed, then opened by a click, and a reload keeps it open (objectstack#37201)', async ({ page }, testInfo) => { + await open(page, 1280); + const fold = page.getByTestId('studio-menu-advanced-toggle'); + await expect(fold).toBeVisible(); + await expect(fold).toHaveAttribute('aria-expanded', 'false'); + await expect(page.getByTestId('studio-menu-advanced-group-system')).toBeHidden(); + await expect(page.getByTestId('studio-menu-entry-diagnostics')).toBeHidden(); + await testInfo.attach('advanced-closed', { body: await page.screenshot(), contentType: 'image/png' }); + + await fold.click(); + await expect(fold).toHaveAttribute('aria-expanded', 'true'); + for (const g of ['automation', 'system', 'security']) { + await expect(page.getByTestId(`studio-menu-advanced-group-${g}`)).toBeVisible(); + } + await expect(page.getByTestId('studio-menu-entry-diagnostics')).toBeVisible(); + // Below the 常用 entries, inside the docked panel. + const below = await page.getByTestId('studio-menu-entry-diagnostics').evaluate((el) => el.getBoundingClientRect().top); + const above = await page.getByTestId('studio-menu-entry-type:permission').evaluate((el) => el.getBoundingClientRect().top); + expect(below).toBeGreaterThan(above); + const cookies = await page.context().cookies(ORIGIN); + expect(cookies.find((c) => c.name === 'studio_menu_advanced')?.value).toBe('true'); + expect(cookies.find((c) => c.name === 'studio_menu_state')).toBeUndefined(); + await testInfo.attach('advanced-open', { body: await page.screenshot(), contentType: 'image/png' }); + + await page.reload(); + await page.waitForSelector('[data-testid="studio-menu-advanced-toggle"]'); + await expect(page.getByTestId('studio-menu-advanced-toggle')).toHaveAttribute('aria-expanded', 'true'); + }); + test('collapsed: off the canvas, the content takes the full width, and a reload keeps it', async ({ page }, testInfo) => { await open(page, 1280); await page.getByTestId('studio-menu-toggle').click(); diff --git a/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx b/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx index 051d3c440b5..f3c7469120b 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx @@ -13,6 +13,16 @@ * 4. The search narrows the entries by name, and says so when none match. * 5. Focus order: the toggle, then the search, then the entries. * + * objectstack#37201 — the two tiers (ADR-0084, amended 2026-11-25): + * 6. Group labels are muted, with no count and no link; an entry's muted + * number is its items; an empty 常用 type is dimmed, numberless, a link. + * 7. The 「高级」 fold: closed by default, remembered under + * `studio_menu_advanced`, open by itself on one of its pages without + * writing the cookie, ignored by the search, a button with + * `aria-expanded` / `aria-controls`. + * 8. The 常用 types are listed on a package that holds none of them. + * 9. `~org` and `~all` draw no fold. + * * The provider, the sidebar primitive and the router are real; only the * metadata reads are doubled. */ @@ -22,26 +32,34 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'; +/** What the doubled reads answer; each test may change it before rendering. */ +const reads = vi.hoisted(() => ({ + entries: [] as Array<{ type: string; domain: string }>, + sweep: {} as { loading?: boolean; error?: string | null; countsByType: Record; packagesByType: Record }, +})); + +const SERVED = [ + { type: 'hook', domain: 'data' }, + { type: 'object', domain: 'data' }, + { type: 'app', domain: 'ui' }, + { type: 'page', domain: 'ui' }, + { type: 'flow', domain: 'automation' }, + { type: 'permission', domain: 'security' }, + { type: 'position', domain: 'security' }, +]; + vi.mock('../metadata-admin/useMetadata', async (importOriginal) => { const actual = await importOriginal>(); return { ...actual, useMetadataClient: () => ({}), - useMetadataTypes: () => ({ - loading: false, - error: null, - entries: [ - { type: 'object', domain: 'data' }, - { type: 'flow', domain: 'automation' }, - { type: 'permission', domain: 'security' }, - ], - }), - useGlobalDiagnostics: () => ({ countsByType: { object: 3 }, packagesByType: {}, reload: () => {} }), + useMetadataTypes: () => ({ loading: false, error: null, entries: reads.entries }), + useGlobalDiagnostics: () => ({ loading: false, error: null, ...reads.sweep, reload: () => {} }), }; }); import { StudioMenu, StudioMenuProvider, StudioMenuTrigger } from './StudioMenu'; -import { STUDIO_MENU_COOKIE } from './studioMenuModel'; +import { STUDIO_MENU_ADVANCED_COOKIE, STUDIO_MENU_COOKIE } from './studioMenuModel'; const PKG = 'com.acme.app'; @@ -77,22 +95,22 @@ function Where() { return {`${pathname}${search}`}; } -function Shell() { +function Shell({ segment }: { segment: string }) { return (
- +
); } -function renderAt(path: string) { +function renderAt(path: string, segment = PKG) { return render( - } /> + } /> , @@ -100,6 +118,8 @@ function renderAt(path: string) { } const toggle = () => screen.getByTestId('studio-menu-toggle'); +const fold = () => screen.getByTestId('studio-menu-advanced-toggle'); +const foldRegion = () => screen.getByTestId('studio-menu-advanced'); const entry = (key: string) => screen.getByTestId(`studio-menu-entry-${key}`); /** The docked menu's open state, as the sidebar primitive draws it. */ const docked = () => document.querySelector('[data-side="left"][data-state]')?.getAttribute('data-state'); @@ -107,6 +127,12 @@ const docked = () => document.querySelector('[data-side="left"][data-state]')?.g beforeEach(() => { clearCookies(); setWidth(1280); + reads.entries = SERVED; + // The package holds objects, flows, permission sets and hooks; no app, page or position. + reads.sweep = { + countsByType: { object: 3, flow: 2, permission: 1, hook: 27 }, + packagesByType: { object: [PKG], flow: [PKG], permission: [PKG], hook: [PKG] }, + }; }); afterEach(() => { @@ -166,10 +192,13 @@ describe('the current entry and the search', () => { for (const a of others) expect(a).not.toHaveAttribute('aria-current'); }); - it('draws each group\'s type count and an entry\'s item count', () => { + // objectstack#37201 — the group's type count is gone; a number is an entry's items. + it('draws no count on a group label and a muted item count on an entry', () => { renderAt(`/studio/${PKG}/data`); - expect(screen.getByTestId('studio-menu-group-count-data')).toHaveTextContent('1'); + expect(screen.queryByTestId('studio-menu-group-count-data')).toBeNull(); expect(entry('type:object')).toHaveTextContent(/3$/); + expect(screen.getByTestId('studio-menu-count-type:object')).toHaveClass('text-muted-foreground'); + expect(screen.getByTestId('studio-menu-count-type:object')).toHaveAttribute('title', '3 items'); }); it('narrows the entries by name, and says so when none match', () => { @@ -179,7 +208,7 @@ describe('the current entry and the search', () => { fireEvent.change(search, { target: { value: 'flow' } }); const links = within(screen.getByTestId('studio-menu')).getAllByRole('link'); - // "flow" names the flow type and the organization's flows. + // "flow" names the flow type and the organization's flows (a 高级 entry: the search ignores the fold). expect(links.map((a) => a.getAttribute('data-testid'))).toEqual(['studio-menu-entry-type:flow', 'studio-menu-entry-orgFlows']); fireEvent.change(search, { target: { value: 'zzz-nothing' } }); @@ -187,9 +216,10 @@ describe('the current entry and the search', () => { expect(screen.getByTestId('studio-menu-no-matches')).toHaveAttribute('role', 'status'); }); - it('focus order: the toggle, then the search, then the entries', () => { + it('focus order: the toggle, then the search, then the 常用 entries, the 高级 button, and its entries', () => { renderAt(`/studio/${PKG}/data`); - const order = [toggle(), screen.getByTestId('studio-menu-search'), entry('type:object')]; + fireEvent.click(fold()); + const order = [toggle(), screen.getByTestId('studio-menu-search'), entry('type:object'), entry('type:permission'), fold(), entry('type:hook')]; for (let i = 1; i < order.length; i += 1) { expect(order[i - 1].compareDocumentPosition(order[i]) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); } @@ -197,3 +227,184 @@ describe('the current entry and the search', () => { expect(screen.getByRole('navigation', { name: 'Studio menu' })).toBe(screen.getByTestId('studio-menu')); }); }); + +describe('the group labels (objectstack#37201)', () => { + it('are muted headings: no count, no link, not focusable', () => { + renderAt(`/studio/${PKG}/data`); + const group = screen.getByTestId('studio-menu-group-data'); + const label = group.querySelector('[data-sidebar="group-label"]')!; + expect(label).toHaveTextContent(/^Data$/); + expect(label).toHaveClass('text-muted-foreground'); + expect(label.querySelector('a, button, [tabindex]')).toBeNull(); + expect(label.closest('a')).toBeNull(); + }); + + it('a group is labelled in a tier only where it holds an entry of that tier', () => { + renderAt(`/studio/${PKG}/data`); + const menu = screen.getByTestId('studio-menu'); + // 常用: data, ui, automation, security. 平台 Platform holds only 高级 entries; AI is not served here. + expect([...menu.querySelectorAll('[data-testid^="studio-menu-group-"]')].map((g) => g.getAttribute('data-testid'))).toEqual([ + 'studio-menu-group-data', + 'studio-menu-group-ui', + 'studio-menu-group-automation', + 'studio-menu-group-security', + ]); + expect([...foldRegion().querySelectorAll('[data-testid^="studio-menu-advanced-group-"]')].map((g) => g.getAttribute('data-testid'))).toEqual([ + 'studio-menu-advanced-group-data', + 'studio-menu-advanced-group-automation', + 'studio-menu-advanced-group-system', + 'studio-menu-advanced-group-security', + ]); + expect(within(screen.getByTestId('studio-menu-advanced-group-security')).getAllByRole('link').map((a) => a.getAttribute('data-testid'))).toEqual([ + 'studio-menu-entry-owd', + 'studio-menu-entry-environment', + ]); + }); +}); + +describe('an empty 常用 type (objectstack#37201)', () => { + it('the package holds none: dimmed, no number, still a link to its list', () => { + renderAt(`/studio/${PKG}/data`); + const app = entry('type:app'); + expect(app).toHaveAttribute('data-empty', 'true'); + expect(app).toHaveAttribute('href', `/studio/${PKG}/metadata/app?package=${PKG}`); + expect(app).toHaveAttribute('title', 'None yet: open the list to make the first'); + expect(app.querySelector('span')).toHaveClass('text-muted-foreground'); + expect(screen.queryByTestId('studio-menu-count-type:app')).toBeNull(); + expect(app).toHaveTextContent(/^App/); + expect(app).not.toHaveTextContent(/\d/); + // One it holds is neither dimmed nor numberless. + expect(entry('type:object')).not.toHaveAttribute('data-empty'); + expect(entry('type:object').querySelector('span')).not.toHaveClass('text-muted-foreground'); + }); + + it('while the sweep has not answered, nothing is empty', () => { + reads.sweep = { loading: true, countsByType: {}, packagesByType: {} }; + renderAt(`/studio/${PKG}/data`); + expect(entry('type:app')).not.toHaveAttribute('data-empty'); + expect(entry('type:object')).not.toHaveAttribute('data-empty'); + }); + + it('a sweep that failed answered nothing: nothing is empty', () => { + reads.sweep = { error: 'not found', countsByType: {}, packagesByType: {} }; + renderAt(`/studio/${PKG}/data`); + expect(entry('type:app')).not.toHaveAttribute('data-empty'); + }); +}); + +describe('a package that holds nothing yet (objectstack#37201)', () => { + it('lists every served 常用 type, holding one or not; a 高级 type only when held', () => { + reads.entries = [ + ...SERVED, + { type: 'dashboard', domain: 'ui' }, + { type: 'report', domain: 'ui' }, + { type: 'agent', domain: 'ai' }, + { type: 'tool', domain: 'ai' }, + { type: 'skill', domain: 'ai' }, + ]; + reads.sweep = { countsByType: {}, packagesByType: {} }; + renderAt(`/studio/${PKG}/data`); + const links = (root: HTMLElement) => within(root).queryAllByRole('link').map((a) => a.getAttribute('data-testid')!.replace('studio-menu-entry-', '')); + const common = links(screen.getByTestId('studio-menu')).filter((k) => !links(foldRegion()).includes(k)); + expect(common).toEqual([ + 'type:object', + 'type:app', + 'type:page', + 'type:dashboard', + 'type:report', + 'type:flow', + 'type:permission', + 'type:agent', + 'type:tool', + 'type:skill', + ]); + for (const k of common) expect(entry(k)).toHaveAttribute('data-empty', 'true'); + expect(screen.queryByTestId('studio-menu-entry-type:hook')).toBeNull(); + expect(screen.queryByTestId('studio-menu-entry-type:position')).toBeNull(); + }); +}); + +describe('the 「高级」 fold (objectstack#37201)', () => { + it('closed by default: a button that names the region it controls, which is hidden', () => { + renderAt(`/studio/${PKG}/data`); + expect(fold().tagName).toBe('BUTTON'); + expect(fold()).toHaveAccessibleName('Advanced'); + expect(fold()).toHaveAttribute('aria-expanded', 'false'); + expect(fold().getAttribute('aria-controls')).toBe(foldRegion().id); + expect(foldRegion().id).not.toBe(''); + expect(foldRegion()).not.toBeVisible(); + expect(entry('type:hook')).not.toBeVisible(); + expect(entry('type:object')).toBeVisible(); + }); + + it('a click opens it and remembers it under studio_menu_advanced, apart from the collapse cookie; a remount keeps it', () => { + const first = renderAt(`/studio/${PKG}/data`); + fireEvent.click(fold()); + expect(fold()).toHaveAttribute('aria-expanded', 'true'); + expect(foldRegion()).toBeVisible(); + expect(entry('type:hook')).toBeVisible(); + expect(cookie(STUDIO_MENU_ADVANCED_COOKIE)).toBe('true'); + expect(cookie(STUDIO_MENU_COOKIE)).toBeUndefined(); + + first.unmount(); + const second = renderAt(`/studio/${PKG}/data`); + expect(fold()).toHaveAttribute('aria-expanded', 'true'); + + fireEvent.click(fold()); + expect(fold()).toHaveAttribute('aria-expanded', 'false'); + expect(cookie(STUDIO_MENU_ADVANCED_COOKIE)).toBe('false'); + second.unmount(); + renderAt(`/studio/${PKG}/data`); + expect(fold()).toHaveAttribute('aria-expanded', 'false'); + }); + + it('a bookmark to the hook list opens it by itself, marks the hook entry current, and writes no cookie', () => { + renderAt(`/studio/${PKG}/metadata/hook?package=${PKG}`); + expect(fold()).toHaveAttribute('aria-expanded', 'true'); + expect(entry('type:hook')).toBeVisible(); + expect(entry('type:hook')).toHaveAttribute('aria-current', 'page'); + expect(cookie(STUDIO_MENU_ADVANCED_COOKIE)).toBeUndefined(); + }); + + it('CONTROL: on a 常用 page it stays closed', () => { + renderAt(`/studio/${PKG}/metadata/object?package=${PKG}`); + expect(fold()).toHaveAttribute('aria-expanded', 'false'); + }); + + it('the author can still close it on a 高级 page', () => { + renderAt(`/studio/${PKG}/owd`); + expect(fold()).toHaveAttribute('aria-expanded', 'true'); + fireEvent.click(fold()); + expect(fold()).toHaveAttribute('aria-expanded', 'false'); + expect(cookie(STUDIO_MENU_ADVANCED_COOKIE)).toBe('false'); + }); + + it('the search ignores it: a 高级 entry matches while the fold is closed, and no fold is drawn', () => { + renderAt(`/studio/${PKG}/data`); + fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: 'hook' } }); + expect(entry('type:hook')).toBeVisible(); + expect(screen.queryByTestId('studio-menu-advanced-toggle')).toBeNull(); + fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: '' } }); + expect(fold()).toHaveAttribute('aria-expanded', 'false'); + }); +}); + +describe('~org and ~all draw no fold (objectstack#37201)', () => { + it.each([ + ['~org', '/studio/~org/metadata/flow?source=runtime'], + ['~all', '/studio/~all/metadata'], + ])('%s: its entries flat, in the table\'s order, under muted labels', (segment, path) => { + renderAt(path, segment); + expect(screen.queryByTestId('studio-menu-advanced-toggle')).toBeNull(); + expect(screen.queryByTestId('studio-menu-advanced')).toBeNull(); + const security = screen.getByTestId('studio-menu-group-security'); + expect(within(security).getAllByRole('link').map((a) => a.getAttribute('data-testid'))).toEqual([ + 'studio-menu-entry-type:permission', + 'studio-menu-entry-type:position', + 'studio-menu-entry-environment', + ]); + for (const a of within(security).getAllByRole('link')) expect(a).toBeVisible(); + expect(security.querySelector('[data-sidebar="group-label"]')).toHaveClass('text-muted-foreground'); + expect(screen.getByTestId('studio-menu-entry-orgFlows')).toBeVisible(); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx b/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx index bac969b96da..90509e715b7 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx @@ -16,11 +16,24 @@ * Every entry is a plain link: a page holding unsaved work is registered with * the shell's leave guard (`useRegisterUnsavedEdits`), whose capture-phase * link guard asks before any of them leaves. + * + * ## Two tiers on a package (ADR-0084, amended 2026-11-25; objectstack#37201) + * + * A group's label is a small muted heading: no count, not a link, not + * focusable. Only entries look clickable, and an entry's muted number means + * one thing, its items. The 常用 Common groups come first; below a divider, + * one 「高级」 button folds every 高级 Advanced entry under the same labels. + * - The fold is closed by default and remembered per browser under its own + * cookie, {@link STUDIO_MENU_ADVANCED_COOKIE}; only a click writes it. + * - It opens itself while the open page is one of its entries (a bookmark to + * the hook list), without writing the cookie. + * - A search ignores it: the matches of both tiers are listed flat. + * - `~org` and `~all` draw no fold: their entries are listed flat. */ import * as React from 'react'; import { Link, useLocation } from 'react-router-dom'; -import { PanelLeft } from 'lucide-react'; +import { ChevronRight, PanelLeft } from 'lucide-react'; import { cn, Sidebar, @@ -33,6 +46,7 @@ import { SidebarMenuButton, SidebarMenuItem, SidebarProvider, + SidebarSeparator, useSidebar, } from '@object-ui/components'; import { @@ -47,14 +61,30 @@ import { t, tFormat, translateMetadataType } from '../metadata-admin/i18n.js'; import { studioMenuGroupLabel } from './studioMenuGroupLabel.js'; import { STUDIO_HEADER_ICON_BUTTON } from './studio-tokens.js'; import { + STUDIO_MENU_ADVANCED_COOKIE, STUDIO_MENU_COOKIE, buildStudioMenu, + readStudioMenuAdvancedCookie, studioMenuCurrentKey, studioMenuEntryMatches, studioMenuScope, + studioMenuTiers, type StudioMenuEntry, + type StudioMenuGroupModel, + type StudioMenuTier, } from './studioMenuModel.js'; +/** The fold's cookie lives as long as the menu's own collapse cookie (the sidebar primitive's 7 days). */ +const ADVANCED_COOKIE_MAX_AGE = 60 * 60 * 24 * 7; + +function readAdvancedCookie(): boolean { + return typeof document === 'undefined' ? false : readStudioMenuAdvancedCookie(document.cookie); +} + +function writeAdvancedCookie(open: boolean): void { + document.cookie = `${STUDIO_MENU_ADVANCED_COOKIE}=${open}; path=/; max-age=${ADVANCED_COOKIE_MAX_AGE}`; +} + /** * objectui#12795 — every `SidebarGroupLabel` call site hides its label from @@ -161,15 +191,95 @@ function StudioMenuBody({ const { isMobile, setOpenMobile } = useSidebar(); const [query, setQuery] = React.useState(''); const searchId = React.useId(); + const advancedId = `${searchId}-advanced`; const labels = new Map(types.map((e) => [e.type, translateMetadataType(e.type, locale, (e as { label?: string }).label)])); const labelOf = (entry: StudioMenuEntry) => entry.kind === 'type' ? (labels.get(entry.type ?? '') ?? entry.type ?? '') : t(STUDIO_MENU_ENTRY_LABEL_KEYS[entry.kind], locale); const current = studioMenuCurrentKey({ segment, pathname, search }); - const groups = buildStudioMenu({ scope, types, counts }) + const menu = buildStudioMenu({ scope, types, counts, settled: data.countsAnswered }); + const searching = query.trim().length > 0; + const matching = menu .map((g) => ({ ...g, entries: g.entries.filter((e) => studioMenuEntryMatches(e, labelOf(e), query)) })) - .filter((g) => !query.trim() || g.entries.length > 0); + .filter((g) => g.entries.length > 0); + // The fold is a package's: a search, `~org` and `~all` list their entries flat. + const folded = scope.kind === 'package' && !searching; + const tiers = studioMenuTiers(menu); + + // The fold: the browser's remembered state, opened besides while the open + // page is one of its entries — until the author closes it on that page. + const [remembered, setRemembered] = React.useState(readAdvancedCookie); + const [closedOn, setClosedOn] = React.useState(null); + const currentIsAdvanced = tiers.advanced.some((g) => g.entries.some((e) => e.key === current)); + const advancedOpen = remembered || (currentIsAdvanced && closedOn !== current); + const toggleAdvanced = () => { + const next = !advancedOpen; + setRemembered(next); + setClosedOn(next ? null : current); + writeAdvancedCookie(next); + }; + + const renderEntry = (entry: StudioMenuEntry) => { + const label = labelOf(entry); + const isCurrent = entry.key === current; + return ( + + + { + if (e.defaultPrevented) return; + const [to, query = ''] = entry.to.split('?'); + const reenters = to === pathname && `?${query}` !== search; + if (reenters && onReenterPillar && !onReenterPillar(query ? `?${query}` : '')) { + e.preventDefault(); + return; + } + if (isMobile) setOpenMobile(false); + }} + > + {label} + {entry.count !== undefined && !entry.empty && ( + + {entry.count} + + )} + + + + ); + }; + + const renderGroups = (groups: readonly StudioMenuGroupModel[], tier: StudioMenuTier | 'flat') => + groups.map(({ group, entries }) => { + const Icon = STUDIO_MENU_GROUP_ICONS[group]; + const labelId = `${searchId}-${tier}-${group}`; + return ( + + + + {entries.map(renderEntry)} + + ); + }); return ( diff --git a/ui/packages/app-shell/src/views/studio-design/studioMenuData.ts b/ui/packages/app-shell/src/views/studio-design/studioMenuData.ts index 10fc1b1d116..a1cc515e2e4 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioMenuData.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioMenuData.ts @@ -18,7 +18,7 @@ import { import { scopeDirectoryEntries } from '../metadata-admin/directoryScope.js'; import { useMetadataRefreshNonce } from './useMetadataRefreshNonce.js'; import { - STUDIO_MENU_DESIGNER_TYPES, + STUDIO_MENU_ALWAYS_TYPES, studioMenuScope, type StudioMenuEntry, type StudioMenuGroup, @@ -52,6 +52,12 @@ export interface StudioMenuData { counts: Readonly>; /** Both reads have answered: the registry's types and the diagnostics sweep. */ settled: boolean; + /** + * The diagnostics sweep answered with its counts (objectstack#37201): a type + * it counts nothing of holds none. False while it reads, and when it failed + * (a server without the sweep answers no counts, not "none of each"). + */ + countsAnswered: boolean; } /** @@ -69,6 +75,7 @@ export function useStudioMenuTypes(segment: string): StudioMenuData { countsByType, packagesByType, loading: sweepLoading, + error: sweepError, reload, } = useGlobalDiagnostics(client, 'error', packageId ?? undefined); const refresh = useMetadataRefreshNonce(); @@ -83,9 +90,10 @@ export function useStudioMenuTypes(segment: string): StudioMenuData { environment: scope.kind !== 'package', packageId, packagesByType, - always: STUDIO_MENU_DESIGNER_TYPES, + always: STUDIO_MENU_ALWAYS_TYPES, }); - return { segment, types, counts: countsByType, settled: !typesLoading && !sweepLoading }; + const settled = !typesLoading && !sweepLoading; + return { segment, types, counts: countsByType, settled, countsAnswered: settled && !sweepError }; } /** diff --git a/ui/packages/app-shell/src/views/studio-design/studioMenuModel.test.ts b/ui/packages/app-shell/src/views/studio-design/studioMenuModel.test.ts index 59886dd2708..f9535a4a7d0 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioMenuModel.test.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioMenuModel.test.ts @@ -5,16 +5,26 @@ * groups in the amendment's order, a type in the group of its served domain, * the four entries that open no type's list in the groups of what they hold, * and the entry each Studio page marks current. + * + * objectstack#37201 — the menu reads the placement table (ADR-0084, amended + * 2026-11-25): each group's entries in the table's order, each stamped with + * its tier, the four entries that are not a type in 高级, a 常用 type the + * settled sweep counts none of marked empty, and the 常用 types always listed. */ import { describe, expect, it } from 'vitest'; import { + STUDIO_MENU_ADVANCED_COOKIE, + STUDIO_MENU_ALWAYS_TYPES, STUDIO_MENU_GROUPS, buildStudioMenu, + readStudioMenuAdvancedCookie, studioMenuCurrentKey, studioMenuEntryMatches, studioMenuScope, + studioMenuTiers, } from './studioMenuModel'; +import { STUDIO_MENU_PLACEMENT } from './studioMenuPlacement'; import { studioMenuGroupLabel } from './studioMenuGroupLabel'; import { translateMetadataDomain } from '../metadata-admin/i18n'; // The zh rows of the menu's own names live in `@object-ui/i18n`'s lazily loaded `studio` namespace. @@ -62,10 +72,15 @@ describe('the menu groups (objectstack#36899, ADR-0084 amended)', () => { expect(entry('environment').to).toBe('/studio/~all/metadata'); }); - it('a package draws all six groups, an empty one included', () => { + // objectstack#37201 — rewritten on purpose: a group is drawn only where it holds an entry + // (ADR-0084, amended 2026-11-25, §3.3). It was "a package draws all six groups, an empty one included". + it('a package draws a group only where it holds an entry: with no type served, the groups of the entries that are not a type', () => { const menu = buildStudioMenu({ scope: studioMenuScope(PKG), types: [], counts: {} }); - expect(menu.map((g) => g.group)).toEqual(STUDIO_MENU_GROUPS); - expect(keysOf(menu).data).toEqual([]); + expect(keysOf(menu)).toEqual({ + automation: ['orgFlows'], + system: ['diagnostics'], + security: ['owd', 'environment'], + }); }); it.each(['~org', '~all'])('%s: the environment\'s menu, only the groups that hold an entry', (segment) => { @@ -74,9 +89,10 @@ describe('the menu groups (objectstack#36899, ADR-0084 amended)', () => { { type: 'permission', domain: 'security' }, ]; const menu = buildStudioMenu({ scope: studioMenuScope(segment), types, counts: {} }); + // objectstack#37201 — the table's order, not the served one: permission set (常用) before position (高级). expect(keysOf(menu)).toEqual({ automation: ['orgFlows'], - security: ['type:position', 'type:permission', 'environment'], + security: ['type:permission', 'type:position', 'environment'], }); expect(menu.flatMap((g) => g.entries).find((e) => e.key === 'type:position')!.to).toBe( '/studio/~all/metadata/position?scope=environment', @@ -84,6 +100,152 @@ describe('the menu groups (objectstack#36899, ADR-0084 amended)', () => { }); }); +/** A package's served types in the server's order: by domain, then alphabetically by type. */ +const SERVED = [ + { type: 'hook', domain: 'data' }, + { type: 'mapping', domain: 'data' }, + { type: 'object', domain: 'data' }, + { type: 'picklist', domain: 'data' }, + { type: 'zz_unplaced', domain: 'data' }, + { type: 'action', domain: 'ui' }, + { type: 'app', domain: 'ui' }, + { type: 'dashboard', domain: 'ui' }, + { type: 'page', domain: 'ui' }, + { type: 'report', domain: 'ui' }, + { type: 'view', domain: 'ui' }, + { type: 'flow', domain: 'automation' }, + { type: 'job', domain: 'automation' }, + { type: 'book', domain: 'system' }, + { type: 'doc', domain: 'system' }, + { type: 'email_template', domain: 'system' }, + { type: 'assignment_rule', domain: 'security' }, + { type: 'permission', domain: 'security' }, + { type: 'position', domain: 'security' }, + { type: 'agent', domain: 'ai' }, + { type: 'skill', domain: 'ai' }, + { type: 'tool', domain: 'ai' }, +]; + +describe('the menu reads the placement table (objectstack#37201, ADR-0084 amended 2026-11-25)', () => { + const menu = buildStudioMenu({ scope: studioMenuScope(PKG), types: SERVED, counts: {} }); + const entries = menu.flatMap((g) => g.entries); + + it("orders each group by the table, an unplaced type after the placed ones, then the entries that are not a type", () => { + expect(keysOf(menu)).toEqual({ + data: ['type:object', 'type:picklist', 'type:hook', 'type:mapping', 'type:zz_unplaced'], + ui: ['type:app', 'type:page', 'type:dashboard', 'type:report', 'type:view', 'type:action'], + automation: ['type:flow', 'type:job', 'orgFlows'], + system: ['type:doc', 'type:book', 'type:email_template', 'diagnostics'], + security: ['type:permission', 'type:position', 'type:assignment_rule', 'owd', 'environment'], + ai: ['type:agent', 'type:tool', 'type:skill'], + }); + }); + + it("stamps each type with its row's tier, and 高级 on a type with no row", () => { + const tierOf = new Map(STUDIO_MENU_PLACEMENT.map((row) => [row.type, row.tier])); + for (const e of entries.filter((x) => x.kind === 'type')) { + expect(e.tier, e.key).toBe(e.type === 'zz_unplaced' ? 'advanced' : tierOf.get(e.type!)); + } + expect(entries.find((e) => e.key === 'type:object')!.tier).toBe('common'); + expect(entries.find((e) => e.key === 'type:picklist')!.tier).toBe('advanced'); + }); + + it('the four entries that are not a type are 高级 on a package', () => { + for (const key of ['orgFlows', 'diagnostics', 'owd', 'environment']) { + expect(entries.find((e) => e.key === key)!.tier, key).toBe('advanced'); + } + }); + + it('splits into the 常用 groups and the 高级 fold, a group in a tier only where it holds an entry of that tier', () => { + const tiers = studioMenuTiers(menu); + expect(Object.fromEntries(tiers.common.map((g) => [g.group, g.entries.map((e) => e.key)]))).toEqual({ + data: ['type:object'], + ui: ['type:app', 'type:page', 'type:dashboard', 'type:report'], + automation: ['type:flow'], + security: ['type:permission'], + ai: ['type:agent', 'type:tool', 'type:skill'], + }); + // 平台 Platform holds no 常用 entry: its label is drawn inside the fold alone; AI holds no 高级 one here. + expect(tiers.common.map((g) => g.group)).not.toContain('system'); + expect(tiers.advanced.map((g) => g.group)).toEqual(['data', 'ui', 'automation', 'system', 'security']); + expect(tiers.advanced.find((g) => g.group === 'security')!.entries.map((e) => e.key)).toEqual([ + 'type:position', + 'type:assignment_rule', + 'owd', + 'environment', + ]); + }); + + it('keeps every address and entry key: only the order and the tier are new', () => { + for (const e of entries.filter((x) => x.kind === 'type' && x.type !== 'datasource')) { + expect(e.key).toBe(`type:${e.type}`); + expect(e.to).toBe(`/studio/${PKG}/metadata/${e.type}?package=${PKG}`); + } + }); +}); + +describe('the 常用 types are always listed on a package (objectstack#37201)', () => { + it('the list the directory rule keeps regardless of the sweep is the table\'s 常用 rows, in order', () => { + expect(STUDIO_MENU_ALWAYS_TYPES).toEqual(STUDIO_MENU_PLACEMENT.filter((r) => r.tier === 'common').map((r) => r.type)); + expect(STUDIO_MENU_ALWAYS_TYPES).toEqual(['object', 'app', 'page', 'dashboard', 'report', 'flow', 'permission', 'agent', 'tool', 'skill']); + }); + + it("a new package's directory rule lists them though the sweep has none of them", async () => { + const { scopeDirectoryEntries } = await import('../metadata-admin/directoryScope'); + const listed = scopeDirectoryEntries(SERVED, { + environment: false, + packageId: PKG, + packagesByType: {}, + always: STUDIO_MENU_ALWAYS_TYPES, + }).map((e) => e.type); + expect(listed.sort()).toEqual(['agent', 'app', 'dashboard', 'flow', 'object', 'page', 'permission', 'report', 'skill', 'tool']); + }); +}); + +describe('an empty 常用 type means the sweep answered none, not "not answered yet" (objectstack#37201)', () => { + const types = [ + { type: 'object', domain: 'data' }, + { type: 'app', domain: 'ui' }, + { type: 'hook', domain: 'data' }, + ]; + const empty = (opts: { settled?: boolean; counts?: Record; segment?: string }) => + buildStudioMenu({ scope: studioMenuScope(opts.segment ?? PKG), types, counts: opts.counts ?? {}, settled: opts.settled }) + .flatMap((g) => g.entries) + .filter((e) => e.empty) + .map((e) => e.key); + + it('settled: a 常用 type with no count, or a count of 0, is empty; one with items is not', () => { + expect(empty({ settled: true, counts: { object: 2, app: 0 } })).toEqual(['type:app']); + expect(empty({ settled: true, counts: {} })).toEqual(['type:object', 'type:app']); + }); + + it('not settled: nothing is empty', () => { + expect(empty({ settled: false, counts: {} })).toEqual([]); + expect(empty({ counts: {} })).toEqual([]); + }); + + it('a 高级 type is never marked empty, nor anything on ~org or ~all', () => { + expect(empty({ settled: true })).not.toContain('type:hook'); + expect(empty({ settled: true, segment: '~all' })).toEqual([]); + expect(empty({ settled: true, segment: '~org' })).toEqual([]); + }); +}); + +describe('the 高级 fold\'s cookie (objectstack#37201)', () => { + it('is its own name, apart from the menu\'s collapse cookie', () => { + expect(STUDIO_MENU_ADVANCED_COOKIE).toBe('studio_menu_advanced'); + }); + + it('reads open only from the literal the menu writes; closed by default', () => { + expect(readStudioMenuAdvancedCookie('')).toBe(false); + expect(readStudioMenuAdvancedCookie('studio_menu_state=true')).toBe(false); + expect(readStudioMenuAdvancedCookie('a=1; studio_menu_advanced=true')).toBe(true); + expect(readStudioMenuAdvancedCookie('studio_menu_advanced=false')).toBe(false); + expect(readStudioMenuAdvancedCookie('studio_menu_advanced=1')).toBe(false); + expect(readStudioMenuAdvancedCookie('xstudio_menu_advanced=true')).toBe(false); + }); +}); + describe('the current entry (aria-current)', () => { const current = (segment: string, path: string) => { const [pathname, query = ''] = path.split('?'); diff --git a/ui/packages/app-shell/src/views/studio-design/studioMenuModel.ts b/ui/packages/app-shell/src/views/studio-design/studioMenuModel.ts index 8cb276d7aca..ae4086dd66e 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioMenuModel.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioMenuModel.ts @@ -17,12 +17,13 @@ * ## Entries * * A type entry for each type the package's directory lists (the same rule, - * `scopeDirectoryEntries`), plus the types a designer creates in - * ({@link STUDIO_MENU_DESIGNER_TYPES}), so a package without an object, a flow - * or a permission set can still make its first. Each opens the type's list in - * the "All metadata" area; an item opened there that a pillar designs still - * opens its pillar until the pillars become full-screen pages - * (`areaItemPillarPath`). objectstack#36905 — a permission set already has. + * `scopeDirectoryEntries`), plus every 常用 Common type + * ({@link STUDIO_MENU_ALWAYS_TYPES}), so a package that holds no app, page, + * dashboard, report, flow, permission set or agent still shows where the + * first is made. Each opens the type's list in the "All metadata" area; an + * item opened there that a pillar designs still opens its pillar until the + * pillars become full-screen pages (`areaItemPillarPath`). objectstack#36905 + * — a permission set already has. * * And four entries that open no type's list, each in the group of what it * holds (the amendment's "Entries that are not a type"): @@ -32,13 +33,26 @@ * - diagnostics, under Platform; * - the cross-package environment catalog (`~all`), under Access. * + * ## Order and tier (ADR-0084, amended 2026-11-25; objectstack#37201) + * + * Inside a group the type entries follow the placement table + * (`STUDIO_MENU_PLACEMENT`, `studioMenuPlacement.ts`), and each entry carries + * its row's tier. A type with no row is 高级 Advanced and is drawn after the + * placed types of its group, in served order. The four entries that are not a + * type are 高级 and follow the types of their group, in the order above. + * + * A 常用 entry the diagnostics sweep has answered for, holding no item, is + * `empty`: drawn dimmed, with no number, and still a link. Before the sweep + * answers (`settled`), nothing is empty: "not counted yet" is not "none". + * * ## Scopes * - * On a package, all six groups are drawn, an empty one included, so the menu - * reads the same on every package. The package-less scope (`~org`) and the - * cross-package leg (`~all`) name no package: their menu is the environment's - * — the organization's flows and the environment catalog's types — and only - * the groups that hold an entry are drawn. + * On a package, a group is drawn in a tier only where it holds an entry of + * that tier: the 常用 groups first, then one 高级 fold (`StudioMenu.tsx`). + * The package-less scope (`~org`) and the cross-package leg (`~all`) name no + * package: their menu is the environment's — the organization's flows and the + * environment catalog's types — drawn flat, in the same order, with no fold; + * only the groups that hold an entry are drawn. */ import { ENVIRONMENT_SCOPE_QUERY } from '../metadata-admin/catalog-scope.js'; @@ -54,21 +68,46 @@ import { studioPackagePath, } from './studioAddress.js'; import { isStudioOrgScope, studioOrgScopePath } from './studioScope.js'; +import { STUDIO_MENU_PLACEMENT, type StudioMenuTier } from './studioMenuPlacement.js'; + +export type { StudioMenuTier } from './studioMenuPlacement.js'; /** The menu's collapse state, kept apart from the app sidebar's `sidebar_state`. */ export const STUDIO_MENU_COOKIE = 'studio_menu_state'; +/** + * The 高级 Advanced fold's open state, per browser (objectstack#37201). Its own + * cookie: opening the fold never touches the menu's collapse state. + */ +export const STUDIO_MENU_ADVANCED_COOKIE = 'studio_menu_advanced'; + +/** + * The fold's remembered state from a cookie jar (`document.cookie`): `true` + * or `false` as the menu writes it, else `false` — closed by default. Only + * the two literals the menu writes are read; any other value is no + * preference. + */ +export function readStudioMenuAdvancedCookie(jar: string): boolean { + for (const part of jar.split(';')) { + const at = part.indexOf('='); + if (at === -1 || part.slice(0, at).trim() !== STUDIO_MENU_ADVANCED_COOKIE) continue; + return part.slice(at + 1).trim() === 'true'; + } + return false; +} + /** The six groups, in the amendment's order: each is a registered `domain`. */ export const STUDIO_MENU_GROUPS = ['data', 'ui', 'automation', 'system', 'security', 'ai'] as const; export type StudioMenuGroup = (typeof STUDIO_MENU_GROUPS)[number]; /** - * The types a designer creates in: listed on every package, holding one or - * not. Named, not read off the pillar map: a type keeps its entry when its - * designer leaves its pillar for the metadata address (objectstack#36903, the - * flow; objectstack#36905, the permission set). + * The types a package's menu always lists, holding one or not: the 常用 Common + * types of the placement table, in its order (ADR-0084, amended 2026-11-25). + * Read off the table, so a type moved between the tiers there moves here. */ -export const STUDIO_MENU_DESIGNER_TYPES: readonly string[] = Object.freeze(['object', 'flow', 'permission']); +export const STUDIO_MENU_ALWAYS_TYPES: readonly string[] = Object.freeze( + STUDIO_MENU_PLACEMENT.filter((row) => row.tier === 'common').map((row) => row.type), +); export type StudioMenuEntryKind = 'type' | 'orgFlows' | 'owd' | 'diagnostics' | 'environment'; @@ -81,6 +120,13 @@ export interface StudioMenuEntry { to: string; /** A `type` entry's served item count; absent when the sweep did not say. */ count?: number; + /** 常用 Common or 高级 Advanced: the placement table's row, else Advanced. */ + tier: StudioMenuTier; + /** + * A 常用 type the settled sweep counts no item of, on a package: drawn + * dimmed, with no number, and still a link (where the first is made). + */ + empty?: boolean; } export interface StudioMenuGroupModel { @@ -108,44 +154,73 @@ function typeEntryPath(scope: StudioMenuScope, type: string): string { }); } +/** Each placed type's row index: its order inside its group. */ +const PLACEMENT_INDEX: ReadonlyMap = new Map(STUDIO_MENU_PLACEMENT.map((row, i) => [row.type, i])); +const PLACEMENT_TIER: ReadonlyMap = new Map(STUDIO_MENU_PLACEMENT.map((row) => [row.type, row.tier])); + /** * The menu's groups and entries. `types` are the served type entries the - * directory rule already scoped to this menu (`scopeDirectoryEntries`), in - * served order; a type whose domain is none of the six is not drawn. + * directory rule already scoped to this menu (`scopeDirectoryEntries`); a type + * whose domain is none of the six is not drawn. Inside a group the types + * follow the placement table, an unplaced type after the placed ones in + * served order, then the entries that are not a type. `settled` says the + * diagnostics sweep has answered, so a missing count means none. */ export function buildStudioMenu(input: { scope: StudioMenuScope; types: ReadonlyArray<{ type: string; domain?: string }>; counts: Readonly>; + settled?: boolean; }): StudioMenuGroupModel[] { - const { scope, types, counts } = input; + const { scope, types, counts, settled = false } = input; const groups = new Map(STUDIO_MENU_GROUPS.map((g) => [g, []])); - for (const t of types) { + // An unplaced type ranks after every row; the sort is stable, so those keep served order. + const rank = (type: string) => PLACEMENT_INDEX.get(type) ?? STUDIO_MENU_PLACEMENT.length; + const placed = [...types].sort((a, b) => rank(a.type) - rank(b.type)); + for (const t of placed) { const entries = groups.get(t.domain as StudioMenuGroup); if (!entries) continue; - entries.push({ key: `type:${t.type}`, kind: 'type', type: t.type, to: typeEntryPath(scope, t.type), count: counts[t.type] }); + const tier = PLACEMENT_TIER.get(t.type) ?? 'advanced'; + const count = counts[t.type]; + const entry: StudioMenuEntry = { key: `type:${t.type}`, kind: 'type', type: t.type, to: typeEntryPath(scope, t.type), count, tier }; + if (scope.kind === 'package' && tier === 'common' && settled && !((count ?? 0) > 0)) entry.empty = true; + entries.push(entry); } - groups.get('automation')!.push({ key: 'orgFlows', kind: 'orgFlows', to: studioOrgScopePath() }); + groups.get('automation')!.push({ key: 'orgFlows', kind: 'orgFlows', to: studioOrgScopePath(), tier: 'advanced' }); if (scope.kind === 'package') { groups.get('system')!.push({ key: 'diagnostics', kind: 'diagnostics', to: studioMetadataAreaAddress(scope.packageId, '_diagnostics'), + tier: 'advanced', }); groups.get('security')!.push({ key: 'owd', kind: 'owd', to: studioOwdOverviewPath(scope.packageId), + tier: 'advanced', }); } groups.get('security')!.push({ key: 'environment', kind: 'environment', to: studioMetadataAreaRoot(STUDIO_ALL_PACKAGES_SEGMENT), + tier: 'advanced', }); - return STUDIO_MENU_GROUPS.map((group) => ({ group, entries: groups.get(group)! })).filter( - (g) => scope.kind === 'package' || g.entries.length > 0, - ); + return STUDIO_MENU_GROUPS.map((group) => ({ group, entries: groups.get(group)! })).filter((g) => g.entries.length > 0); +} + +/** + * The menu split into its two tiers on a package: the 常用 groups and the + * 高级 fold's groups, each holding only that tier's entries, and a group only + * where it holds one (ADR-0084, amended 2026-11-25, §3.3). + */ +export function studioMenuTiers(menu: readonly StudioMenuGroupModel[]): Record { + const of = (tier: StudioMenuTier) => + menu + .map(({ group, entries }) => ({ group, entries: entries.filter((e) => e.tier === tier) })) + .filter((g) => g.entries.length > 0); + return { common: of('common'), advanced: of('advanced') }; } /** The entry keys of the type each pillar designs (the transition's pillar pages). */ diff --git a/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts b/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts index fb9c3b6a864..a4a471023d2 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioMenuPlacement.ts @@ -18,21 +18,30 @@ * includes picklist (选项列表) and email template. * * A type with no row here is drawn in `advanced`, at the end of its group. It - * is never invisible; the menu applies that rule when it reads this list. + * is never invisible: `buildStudioMenu` (`studioMenuModel.ts`) applies that + * rule when it reads this list (objectstack#37201). * * ## Order * - * A consumer sorts the entries of one group, within one tier, by the row's - * index in {@link STUDIO_MENU_PLACEMENT}. The common rows come first, in the - * ruled order; the advanced rows follow in the proposal's order, group by - * group. + * `buildStudioMenu` sorts the entries of one group by the row's index in + * {@link STUDIO_MENU_PLACEMENT} and stamps each entry with the row's tier; + * the menu then draws each tier's entries in that order. The common rows come + * first, in the ruled order; the advanced rows follow in the proposal's order, + * group by group. * * ## Pins * - * `studioMenuPlacement.test.ts` holds this list against - * `DEFAULT_METADATA_TYPE_REGISTRY`: every type the directory can list has - * exactly one row, and every row names a registered type. Nothing reads the - * list yet; the menu reads it once `buildStudioMenu` orders by it. + * Three pins hold this list, all in `studioMenuPlacement.test.ts`: + * - the registry: against `DEFAULT_METADATA_TYPE_REGISTRY`, every type the + * directory can list has exactly one row, and every row names a + * registered, listable type; + * - the ruled order: the rows, in order, with their tiers, as literals + * (ruling on #37192), so a reordered or re-tiered row fails there; + * - ADR-0084: its type-to-group table's Order and Tier columns equal this + * list, group by group. + * + * The menu's reading of the list is pinned in `studioMenuModel.test.ts` and + * `StudioMenu.test.tsx`. */ /** A type's tier in Studio's left menu. */ diff --git a/ui/packages/i18n/src/namespaces/studio/en.ts b/ui/packages/i18n/src/namespaces/studio/en.ts index 7f561b3ae78..7287d1e2030 100644 --- a/ui/packages/i18n/src/namespaces/studio/en.ts +++ b/ui/packages/i18n/src/namespaces/studio/en.ts @@ -3536,6 +3536,9 @@ const STUDIO_EN: Record = { 'engine.studio.menu.owd': 'Default sharing', 'engine.studio.menu.diagnostics': 'Diagnostics', 'engine.studio.menu.environment': 'Positions and permissions', + // objectstack#37201 — the 「高级」 fold (ADR-0084, amended 2026-11-25), and a 常用 type with no item yet. + 'engine.studio.menu.advanced': 'Advanced', + 'engine.studio.menu.emptyType': 'None yet: open the list to make the first', // objectstack#36502 — the notice on a retired Interfaces link's landing. 'engine.studio.interfacesRetired.sentence': 'Interface edits have moved into the app.', 'engine.studio.interfacesRetired.backToApp': 'Back to the app', diff --git a/ui/packages/i18n/src/namespaces/studio/zh.ts b/ui/packages/i18n/src/namespaces/studio/zh.ts index 6341462150f..1ec5c367f29 100644 --- a/ui/packages/i18n/src/namespaces/studio/zh.ts +++ b/ui/packages/i18n/src/namespaces/studio/zh.ts @@ -3123,6 +3123,9 @@ const STUDIO_ZH: Record = { 'engine.studio.menu.owd': '默认共享', 'engine.studio.menu.diagnostics': '诊断', 'engine.studio.menu.environment': '岗位与权限', + // objectstack#37201 — the 「高级」 fold (ADR-0084, amended 2026-11-25), and a 常用 type with no item yet. + 'engine.studio.menu.advanced': '高级', + 'engine.studio.menu.emptyType': '还没有:打开列表新建第一项', // objectstack#36502 — 旧「界面」链接落地时的提示。 'engine.studio.interfacesRetired.sentence': '界面的修改已经搬到应用里', 'engine.studio.interfacesRetired.backToApp': '回到应用', From 44d6d96b455e5c1195f393c569fbe02a95b73561 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 17:38:18 +0000 Subject: [PATCH 2/5] test(studio): pin the menu tiers; the palette lists the always-listed AI group; changeset Claude-Session: https://claude.ai/code/session_01QSeKYniqTW93usTV1hShjE Co-authored-by: Claude --- .changeset/37201-studio-menu-tiers.md | 20 ++++++++++++++++++ .../views/studio-design/StudioMenu.test.tsx | 3 ++- .../src/views/studio-design/StudioMenu.tsx | 3 +-- ...oPaletteGroups.surfaceScope-36900.test.tsx | 21 ++++++++++++++----- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 .changeset/37201-studio-menu-tiers.md diff --git a/.changeset/37201-studio-menu-tiers.md b/.changeset/37201-studio-menu-tiers.md new file mode 100644 index 00000000000..f66d8238257 --- /dev/null +++ b/.changeset/37201-studio-menu-tiers.md @@ -0,0 +1,20 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +feat(studio): the left menu shows the 常用 Common types first and folds everything else under one 「高级」 Advanced section + +Clause-②: no +Metadata-protocol: none + +Studio's left menu on a package now lists the ten Common types first, in building order: Objects · Apps, Pages, Dashboards, Reports · Flows · Permission sets · Agents, Tools, Skills. Every other type, and the four entries that are not a type (Organization flows, Diagnostics, Default sharing, Positions and permissions), sit under one **Advanced** (高级) button below a divider, still under their group names. + +- The Advanced section is closed by default. Opening or closing it is remembered per browser in the `studio_menu_advanced` cookie, apart from the menu's own collapse cookie. +- Opening a page that is one of its entries (a bookmark to the hooks list, the default sharing overview) shows the section open, with that entry marked current; this does not change the remembered state. +- The menu search lists matches from both tiers, whether the section is open or not. +- Group names are small muted headings with no number. The muted number beside an entry is its item count. +- A Common type the package holds nothing of is listed anyway, dimmed and with no number, and still opens its list, so a new package shows where to make its first app, page, dashboard or report. Before the item counts have loaded, no type is dimmed. +- The organization's flows (`~org`) and the cross-package catalog (`~all`) have no Advanced section: their entries are listed flat, in the same order. + +No address changes: every entry opens the same page as before, bookmarks keep working, and the ⌘K palette lists the same entries in the new order. Two new strings: "Advanced" (高级) and the dimmed entry's tooltip. diff --git a/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx b/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx index f3c7469120b..bb36a2c63d5 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx @@ -255,7 +255,8 @@ describe('the group labels (objectstack#37201)', () => { 'studio-menu-advanced-group-system', 'studio-menu-advanced-group-security', ]); - expect(within(screen.getByTestId('studio-menu-advanced-group-security')).getAllByRole('link').map((a) => a.getAttribute('data-testid'))).toEqual([ + // Inside the closed fold: out of the accessibility tree until it opens. + expect(within(screen.getByTestId('studio-menu-advanced-group-security')).getAllByRole('link', { hidden: true }).map((a) => a.getAttribute('data-testid'))).toEqual([ 'studio-menu-entry-owd', 'studio-menu-entry-environment', ]); diff --git a/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx b/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx index 90509e715b7..fc4179bfa17 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx @@ -46,7 +46,6 @@ import { SidebarMenuButton, SidebarMenuItem, SidebarProvider, - SidebarSeparator, useSidebar, } from '@object-ui/components'; import { @@ -312,7 +311,7 @@ function StudioMenuBody({ {folded && renderGroups(tiers.common, 'common')} {folded && tiers.advanced.length > 0 && ( <> - +