diff --git a/.changeset/37452-studio-menu-front-end-style.md b/.changeset/37452-studio-menu-front-end-style.md new file mode 100644 index 00000000000..8f26a1f355b --- /dev/null +++ b/.changeset/37452-studio-menu-front-end-style.md @@ -0,0 +1,14 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/layout': patch +--- + +feat(studio): the Studio left menu is drawn as the app's menu, in Studio's own graphite + +Clause-②: yes (widening) +Metadata-protocol: none + +- **Groups collapse the way the app menu's do.** Each of the menu's groups is the app menu's collapsible group: its label is a disclosure button with a chevron, open by default; a search opens every group it lists, chevron included, and holds it open; in the phone drawer the label is the app menu's 44 px tap target. A group still carries no count: a number in the Studio menu is an entry's items. +- **An entry is the app menu's row.** It draws a bare line icon (no tile) before its name, at the app menu's row size; the open page's entry is the app menu's inset pill with a bar on its left edge. +- **Studio's own accent.** The pill and the bar are graphite, light and dark, whatever the app's theme colour is (`STUDIO_ACCENT` in the Studio tokens); the app's `accentColor` no longer reaches anything under that class either: its hover tint is a faint graphite. Only the app's logo keeps the app's colour. +- **New exports: `NavigationGroupSection` and its props type `NavigationGroupSectionProps`** (`@object-ui/layout`), the collapsible sidebar group the app menu draws every `group` entry with. The app menu renders exactly as before. diff --git a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.accessSegment-12452.test.tsx b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.accessSegment-12452.test.tsx index ca7a60bb009..5e6f806d431 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.accessSegment-12452.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.accessSegment-12452.test.tsx @@ -12,8 +12,9 @@ * read on the menu: * * 1. The menu's Access group holds the permission-set entry, a real router - * link, with no "More" trigger anywhere; the group carries the shield glyph, - * the Data group's is not it. + * link, with no "More" trigger anywhere; that entry carries the shield + * glyph, the Data group's object entry does not (objectstack#37452: a + * group's label draws no glyph, each entry draws its own line icon). * 2. With the Access pillar's address open (under any package id) — which * lands on the list of sets since objectstack#36905 — that entry is the * current page and carries the active state; with Data open it carries @@ -30,7 +31,7 @@ import * as React from 'react'; import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { render, screen, cleanup, within } from '@testing-library/react'; import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'; -import { ShieldCheck } from 'lucide-react'; +import { Shield } from 'lucide-react'; const PKG = 'com.acme.app'; @@ -208,9 +209,9 @@ function renderAt(path: string) { const menu = () => screen.getByTestId('studio-menu'); const entry = (testId: string) => within(menu()).getByTestId(testId); -/** The markup of lucide's own `ShieldCheck`, the Access group's glyph. */ +/** The markup of lucide's own `Shield`, the permission-set entry's glyph. */ function shieldMarkup(): string { - const { container, unmount } = render(); + const { container, unmount } = render(); const markup = container.querySelector('svg')!.innerHTML; unmount(); return markup; @@ -230,8 +231,8 @@ describe('Studio menu: Access is a group of its own, and More is gone (objectui# expect(screen.queryByTestId('studio-nav-more')).toBeNull(); expect(screen.queryByTestId('studio-pillar-nav')).toBeNull(); const shield = shieldMarkup(); - expect(group.querySelector('svg')!.innerHTML).toBe(shield); - expect(within(menu()).getByTestId('studio-menu-group-data').querySelector('svg')!.innerHTML).not.toBe(shield); + expect(within(group).getByTestId(PERMISSION_ENTRY).querySelector('svg')!.innerHTML).toBe(shield); + expect(entry(OBJECT_ENTRY).querySelector('svg')!.innerHTML).not.toBe(shield); }); it.each(['app.objectstack.hotcrm', PKG])('with Access open in %s, the permission-set entry is the current page', async (pkg) => { 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 31da8145ae3..e64f38b81d3 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 @@ -14,8 +14,8 @@ * 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. + * 6. Group labels carry 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 @@ -28,11 +28,23 @@ * opens the area's type directory and is current there. CONTROL: a 高级 * type the package holds none of is still not in the fold. * + * objectstack#37452 — drawn as the app's menu: + * 11. A group is the app menu's collapsible group: its label is a disclosure + * button, open by default; closing it hides its entries; a search opens + * every group it lists, chevron included, and holds it open; in the phone + * drawer the label is the app menu's 44 px tap target. + * 12. An entry draws a bare line icon before its name; the current entry is + * the primitive's active row (the pill and left bar). + * 13. The selected entry is tinted by Studio's graphite accent whatever the + * app's theme colours are: every theme token the app's branding writes + * (primary and accent) is rebound over it. + * * The provider, the sidebar primitive and the router are real; only the * metadata reads are doubled. */ import '@testing-library/jest-dom/vitest'; +import type { ReactNode } from 'react'; 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'; @@ -63,8 +75,10 @@ vi.mock('../metadata-admin/useMetadata', async (importOriginal) => { }; }); +import { useAppShellBranding } from '@object-ui/layout'; import { StudioMenu, StudioMenuProvider, StudioMenuTrigger } from './StudioMenu'; import { STUDIO_MENU_ADVANCED_COOKIE, STUDIO_MENU_COOKIE } from './studioMenuModel'; +import { STUDIO_ACCENT, STUDIO_ACCENT_HSL } from './studio-tokens'; const PKG = 'com.acme.app'; @@ -234,13 +248,12 @@ describe('the current entry and the search', () => { }); describe('the group labels (objectstack#37201)', () => { - it('are muted headings: no count, no link, not focusable', () => { + it('carry no count and no link: the label is the group\'s name', () => { 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.querySelector('a')).toBeNull(); expect(label.closest('a')).toBeNull(); }); @@ -407,7 +420,7 @@ 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) => { + ])('%s: its entries flat, in the table\'s order, under their groups\' labels', (segment, path) => { renderAt(path, segment); expect(screen.queryByTestId('studio-menu-advanced-toggle')).toBeNull(); expect(screen.queryByTestId('studio-menu-advanced')).toBeNull(); @@ -418,7 +431,7 @@ describe('~org and ~all draw no fold (objectstack#37201)', () => { '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(security.querySelector('[data-sidebar="group-label"]')).toHaveTextContent(/^Access$/); expect(screen.getByTestId('studio-menu-entry-orgFlows')).toBeVisible(); // objectstack#37211 — no count above Organization flows (it read "0 types" over the group's one entry). const automation = screen.getByTestId('studio-menu-group-automation'); @@ -486,3 +499,169 @@ describe('全部类型 All types (objectstack#37360, ADR-0084 amended 2026-11-25 expect(screen.queryByTestId('studio-menu-all-types')).toBeNull(); }); }); + +describe('drawn as the app\'s menu (objectstack#37452)', () => { + const groupLabel = (testId: string) => + screen.getByTestId(testId).querySelector('[data-sidebar="group-label"]')!; + + it('a group\'s label is the app menu\'s disclosure button: open by default, closing it hides its entries', () => { + renderAt(`/studio/${PKG}/data`); + const label = groupLabel('studio-menu-group-data'); + expect(label.tagName).toBe('BUTTON'); + expect(label).toHaveAccessibleName('Data'); + expect(label).toHaveAttribute('aria-expanded', 'true'); + // The group's list is named by its label. + expect(entry('type:object').closest('ul')).toHaveAttribute('aria-labelledby', label.id); + expect(entry('type:object')).toBeVisible(); + + fireEvent.click(label); + expect(label).toHaveAttribute('aria-expanded', 'false'); + expect(screen.queryByTestId('studio-menu-entry-type:object')).toBeNull(); + // CONTROL: the other groups stay open. + expect(entry('type:flow')).toBeVisible(); + // No count is drawn on a closed group: a number in this menu is an entry's items. + expect(label).toHaveTextContent(/^Data$/); + + fireEvent.click(label); + expect(entry('type:object')).toBeVisible(); + }); + + // On ~all the groups are drawn flat with and without a search, so the + // group the author closed is the same group the search lists into. + it('a search lists its matches in a group the author closed', () => { + renderAt('/studio/~all/metadata', '~all'); + const label = groupLabel('studio-menu-group-security'); + fireEvent.click(label); + expect(label).toHaveAttribute('aria-expanded', 'false'); + expect(screen.queryByTestId('studio-menu-entry-type:position')).toBeNull(); + fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: 'position' } }); + expect(entry('type:position')).toBeVisible(); + expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true'); + // Drawn open, chevron included: the chevron is turned down as on any open group. + const chevron = () => groupLabel('studio-menu-group-security').querySelector('svg')!; + expect(chevron()).toHaveClass('rotate-90'); + // A click while the search holds it open changes nothing. + fireEvent.click(groupLabel('studio-menu-group-security')); + expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true'); + expect(chevron()).toHaveClass('rotate-90'); + expect(entry('type:position')).toBeVisible(); + // The author's choice is kept: clearing the search closes it again. + fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: '' } }); + expect(screen.queryByTestId('studio-menu-entry-type:position')).toBeNull(); + expect(chevron()).not.toHaveClass('rotate-90'); + }); + + it('a click on an open group\'s label during a search is not taken: the group is still open once the search is cleared', () => { + renderAt('/studio/~all/metadata', '~all'); + fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: 'position' } }); + fireEvent.click(groupLabel('studio-menu-group-security')); + expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true'); + fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: '' } }); + expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true'); + expect(entry('type:position')).toBeVisible(); + }); + + it('in the phone drawer a group\'s label is the app menu\'s 44 px tap target; CONTROL: docked it is not', async () => { + setWidth(390); + renderAt(`/studio/${PKG}/data`); + fireEvent.click(toggle()); + const drawer = await screen.findByRole('dialog'); + const label = within(drawer).getByTestId('studio-menu-group-data').querySelector('[data-sidebar="group-label"]')!; + expect(label).toHaveClass('min-h-[44px]'); + cleanup(); + setWidth(1280); + renderAt(`/studio/${PKG}/data`); + expect(groupLabel('studio-menu-group-data')).not.toHaveClass('min-h-[44px]'); + }); + + it('an entry draws a bare line icon before its name, on the app menu\'s row', () => { + renderAt(`/studio/${PKG}/data`); + for (const key of ['type:object', 'type:flow', 'type:permission']) { + const icon = screen.getByTestId(`studio-menu-icon-${key}`); + expect(icon.tagName.toLowerCase()).toBe('svg'); + expect(icon).toHaveAttribute('aria-hidden', 'true'); + // No tile: the icon is the row's own child, the first one. + expect(icon.parentElement).toBe(entry(key)); + expect(entry(key).firstElementChild).toBe(icon); + expect(entry(key)).toHaveAttribute('data-sidebar', 'menu-button'); + } + // A type and an entry that is not one each draw an icon, the fold's too. + fireEvent.click(fold()); + expect(screen.getByTestId('studio-menu-icon-type:hook').tagName.toLowerCase()).toBe('svg'); + expect(screen.getByTestId('studio-menu-icon-owd').tagName.toLowerCase()).toBe('svg'); + }); + + it('the current entry is the primitive\'s active row (the pill and its left bar), and only it', () => { + renderAt(`/studio/${PKG}/metadata/flow?package=${PKG}`); + expect(entry('type:flow')).toHaveAttribute('data-active', 'true'); + expect(entry('type:object')).toHaveAttribute('data-active', 'false'); + // Its count is not muted: it reads with the selected name. + expect(screen.getByTestId('studio-menu-count-type:flow')).not.toHaveClass('text-muted-foreground'); + }); + + describe('the selected entry is tinted by Studio\'s graphite whatever the app\'s theme colour is', () => { + const ROOT_TOKENS = ['--primary', '--primary-foreground', '--ring', '--sidebar-primary', '--sidebar-ring', '--accent', '--accent-foreground']; + + function Branded({ children }: { children: ReactNode }) { + // A non-default app theme: a rose primary and an amber accent, written on the page root by the app shell's own hook. + useAppShellBranding({ primaryColor: '#e11d48', accentColor: '#f59e0b' }); + return <>{children}; + } + + afterEach(() => { + for (const token of ROOT_TOKENS) document.documentElement.style.removeProperty(token); + for (const token of ['--brand-primary', '--brand-primary-hsl', '--brand-accent', '--brand-accent-hsl']) document.documentElement.style.removeProperty(token); + }); + + /** The declarations a class string makes: `[--x:a_b]` and `dark:[--x:a_b]`, underscores read as spaces. */ + function declarations(classes: string, dark: boolean): Map { + const out = new Map(); + for (const cls of classes.split(/\s+/)) { + const m = /^(dark:)?\[(--[\w-]+):(.+)\]$/.exec(cls); + if (m && !!m[1] === dark) out.set(m[2], m[3].replace(/_/g, ' ')); + } + return out; + } + + it('every theme token the app\'s branding writes on the page root is rebound to graphite over the selected entry, light and dark', () => { + render( + + + + } /> + + + , + ); + // CONTROL: the app's theme is not the default — its colour is on the page root. + const root = document.documentElement.style; + const written = [...Array.from({ length: root.length }, (_, i) => root.item(i))].filter( + // `--brand-*` are the hook's hex aliases; no sidebar or menu class reads them. + (token) => token.startsWith('--') && !token.startsWith('--brand-'), + ); + expect(written).toContain('--primary'); + expect(written).toContain('--accent'); + expect(root.getPropertyValue('--primary').trim()).not.toBe(STUDIO_ACCENT_HSL.light); + + // The selected entry is the active row, and it sits inside Studio's accent scope. + const selected = entry('type:flow'); + expect(selected).toHaveAttribute('data-active', 'true'); + const scope = selected.closest('[data-studio-accent]'); + expect(scope).not.toBeNull(); + for (const cls of STUDIO_ACCENT.split(/\s+/)) expect(scope).toHaveClass(cls); + // Nothing between the scope and the entry writes a theme token back. + for (let el: HTMLElement | null = selected; el && el !== scope; el = el.parentElement) { + for (const token of written) expect(el.style.getPropertyValue(token), `${token} on ${el.tagName}`).toBe(''); + } + + const light = declarations(STUDIO_ACCENT, false); + const dark = declarations(STUDIO_ACCENT, true); + for (const token of written) { + expect(light.has(token), `${token} rebound in the light theme`).toBe(true); + expect(dark.has(token), `${token} rebound in the dark theme`).toBe(true); + } + expect(light.get('--primary')).toBe(STUDIO_ACCENT_HSL.light); + expect(dark.get('--primary')).toBe(STUDIO_ACCENT_HSL.dark); + }); + }); +}); 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 bc5cf651a78..e16b7cc4e34 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx @@ -17,12 +17,21 @@ * the shell's leave guard (`useRegisterUnsavedEdits`), whose capture-phase * link guard asks before any of them leaves. * + * ## Drawn as the app's menu (objectstack#37452) + * + * A group is the app menu's collapsible group (`NavigationGroupSection` from + * `@object-ui/layout`): its label is a disclosure button with a chevron, open + * by default and while a search lists matches, and it carries no count. An + * entry is the app menu's row: a line icon with no tile, its name, and its + * muted item count; the open page's entry is the app menu's inset pill with a + * bar on its left edge. Studio's own accent, graphite ({@link STUDIO_ACCENT}), + * tints the pill and the bar, never the app's theme colour. + * * ## 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. + * 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 @@ -39,13 +48,52 @@ import * as React from 'react'; import { Link, useLocation } from 'react-router-dom'; -import { ChevronRight, PanelLeft } from 'lucide-react'; +import { + Activity, + AppWindow, + BarChart3, + BookOpen, + Bot, + Boxes, + Brain, + Building2, + CalendarClock, + ChevronRight, + Database, + File, + FileText, + Gauge, + Globe, + Inbox, + KeyRound, + Languages, + LayoutGrid, + ListChecks, + ListTree, + Mail, + MousePointerClick, + PanelLeft, + Puzzle, + Rows3, + Share2, + Shield, + Sparkles, + Sprout, + Table2, + Unplug, + UserCog, + Users, + Webhook, + Workflow, + Wrench, + ArrowLeftRight, + ShieldCheck, + type LucideIcon, +} from 'lucide-react'; import { cn, Sidebar, SidebarContent, - SidebarGroup, - SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarMenu, @@ -54,6 +102,7 @@ import { SidebarProvider, useSidebar, } from '@object-ui/components'; +import { NavigationGroupSection } from '@object-ui/layout'; import { STUDIO_MENU_ENTRY_LABEL_KEYS, STUDIO_MENU_GROUP_ICONS, @@ -64,7 +113,7 @@ import { } from './studioMenuData.js'; 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_ACCENT, STUDIO_HEADER_ICON_BUTTON } from './studio-tokens.js'; import { STUDIO_MENU_ADVANCED_COOKIE, STUDIO_MENU_COOKIE, @@ -76,6 +125,7 @@ import { studioMenuScope, studioMenuTiers, type StudioMenuEntry, + type StudioMenuGroup, type StudioMenuGroupModel, type StudioMenuTier, } from './studioMenuModel.js'; @@ -91,16 +141,97 @@ function writeAdvancedCookie(open: boolean): void { document.cookie = `${STUDIO_MENU_ADVANCED_COOKIE}=${open}; path=/; max-age=${ADVANCED_COOKIE_MAX_AGE}`; } +/** + * Each listed type's line icon, drawn bare (no tile) before its name, as the + * app menu draws an entry's. A type with no row here draws its group's icon. + */ +const STUDIO_MENU_TYPE_ICONS: Readonly> = { + object: Table2, + app: LayoutGrid, + page: File, + dashboard: Gauge, + report: BarChart3, + flow: Workflow, + permission: Shield, + agent: Bot, + tool: Wrench, + skill: Sparkles, + picklist: ListChecks, + hook: Webhook, + mapping: ArrowLeftRight, + object_extension: Puzzle, + seed: Sprout, + view: Rows3, + action: MousePointerClick, + dataset: Boxes, + job: CalendarClock, + doc: FileText, + book: BookOpen, + email_template: Mail, + translation: Languages, + api: Globe, + datasource: Database, + external_catalog: Unplug, + position: Users, + assignment_rule: UserCog, + sharing_rule: Share2, + queue: Inbox, + capability: ListTree, + ai_context: Brain, +}; + +/** The icon of each entry that is not a type: the page it opens. */ +const STUDIO_MENU_KIND_ICONS: Readonly, LucideIcon>> = { + orgFlows: Building2, + owd: ShieldCheck, + diagnostics: Activity, + environment: KeyRound, + allTypes: AppWindow, +}; + +function studioMenuEntryIcon(entry: StudioMenuEntry, group: StudioMenuGroup | null): LucideIcon { + if (entry.kind !== 'type') return STUDIO_MENU_KIND_ICONS[entry.kind]; + return STUDIO_MENU_TYPE_ICONS[entry.type ?? ''] ?? (group ? STUDIO_MENU_GROUP_ICONS[group] : LayoutGrid); +} /** - * objectui#12795 — every `SidebarGroupLabel` call site hides its label from - * focus and the accessibility tree in the icon sidebar (the primitive's own - * `opacity-0` leaves it reachable). This menu is `offcanvas`, never `icon`, so - * the classes never apply here; it carries them as every call site does. + * One group of the menu: the app menu's collapsible group, open until the + * author closes it. While a search lists matches the group is drawn open, + * chevron included, and a click on its label changes nothing: the author's + * own choice comes back when the search is cleared. In the phone drawer its + * label is the app menu's 44 px tap target. */ -const HIDDEN_ICON_LABEL_NOT_FOCUSABLE = - 'group-data-[state=collapsed]:group-data-[collapsible=icon]:invisible ' + - 'group-data-[state=collapsed]:group-data-[collapsible=icon]:transition-[margin,opacity,visibility]'; +function ignoreOpenChange(): void {} + +function StudioMenuGroupSection({ + label, + labelId, + searching, + isMobile, + testId, + children, +}: { + label: string; + labelId: string; + searching: boolean; + isMobile: boolean; + testId: string; + children: React.ReactNode; +}): React.ReactElement { + const [open, setOpen] = React.useState(true); + return ( + + {children} + + ); +} /** @@ -230,12 +361,13 @@ function StudioMenuBody({ writeAdvancedCookie(next); }; - const renderEntry = (entry: StudioMenuEntry) => { + const renderEntry = (entry: StudioMenuEntry, group: StudioMenuGroup | null) => { const label = labelOf(entry); const isCurrent = entry.key === current; + const Icon = studioMenuEntryIcon(entry, group); return ( - + +