Skip to content

Commit da5fbb7

Browse files
committed
wip(studio): left menu drawn as the app menu, graphite accent
Claude-Session: https://claude.ai/code/session_01Utp6CbL6Nn3scsU8yvLyU4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent a46efa8 commit da5fbb7

3 files changed

Lines changed: 348 additions & 133 deletions

File tree

‎ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx‎

Lines changed: 210 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@
1717
* the shell's leave guard (`useRegisterUnsavedEdits`), whose capture-phase
1818
* link guard asks before any of them leaves.
1919
*
20+
* ## Drawn as the app's menu (objectstack#37452)
21+
*
22+
* A group is the app menu's collapsible group (`NavigationGroupSection` from
23+
* `@object-ui/layout`): its label is a disclosure button with a chevron, open
24+
* by default and while a search lists matches, and it carries no count. An
25+
* entry is the app menu's row: a line icon with no tile, its name, and its
26+
* muted item count; the open page's entry is the app menu's inset pill with a
27+
* bar on its left edge. Studio's own accent, graphite ({@link STUDIO_ACCENT}),
28+
* tints the pill and the bar, never the app's theme colour.
29+
*
2030
* ## Two tiers on a package (ADR-0084, amended 2026-11-25; objectstack#37201)
2131
*
22-
* A group's label is a small muted heading: no count, not a link, not
23-
* focusable. Only entries look clickable, and an entry's muted number means
24-
* one thing, its items. The 常用 Common groups come first; below a divider,
25-
* one 「高级」 button folds every 高级 Advanced entry under the same labels.
32+
* An entry's muted number means one thing, its items. The 常用 Common groups
33+
* come first; below a divider, one 「高级」 button folds every 高级 Advanced
34+
* entry under the same labels.
2635
* - The fold is closed by default and remembered per browser under its own
2736
* cookie, {@link STUDIO_MENU_ADVANCED_COOKIE}; only a click writes it.
2837
* - It opens itself while the open page is one of its entries (a bookmark to
@@ -39,13 +48,52 @@
3948

4049
import * as React from 'react';
4150
import { Link, useLocation } from 'react-router-dom';
42-
import { ChevronRight, PanelLeft } from 'lucide-react';
51+
import {
52+
Activity,
53+
AppWindow,
54+
BarChart3,
55+
BookOpen,
56+
Bot,
57+
Boxes,
58+
Brain,
59+
Building2,
60+
CalendarClock,
61+
ChevronRight,
62+
Database,
63+
File,
64+
FileText,
65+
Gauge,
66+
Globe,
67+
Inbox,
68+
KeyRound,
69+
Languages,
70+
LayoutGrid,
71+
ListChecks,
72+
ListTree,
73+
Mail,
74+
MousePointerClick,
75+
PanelLeft,
76+
Puzzle,
77+
Rows3,
78+
Share2,
79+
Shield,
80+
Sparkles,
81+
Sprout,
82+
Table2,
83+
Unplug,
84+
UserCog,
85+
Users,
86+
Webhook,
87+
Workflow,
88+
Wrench,
89+
ArrowLeftRight,
90+
ShieldCheck,
91+
type LucideIcon,
92+
} from 'lucide-react';
4393
import {
4494
cn,
4595
Sidebar,
4696
SidebarContent,
47-
SidebarGroup,
48-
SidebarGroupLabel,
4997
SidebarHeader,
5098
SidebarInput,
5199
SidebarMenu,
@@ -54,6 +102,7 @@ import {
54102
SidebarProvider,
55103
useSidebar,
56104
} from '@object-ui/components';
105+
import { NavigationGroupSection } from '@object-ui/layout';
57106
import {
58107
STUDIO_MENU_ENTRY_LABEL_KEYS,
59108
STUDIO_MENU_GROUP_ICONS,
@@ -64,7 +113,7 @@ import {
64113
} from './studioMenuData.js';
65114
import { t, tFormat, translateMetadataType } from '../metadata-admin/i18n.js';
66115
import { studioMenuGroupLabel } from './studioMenuGroupLabel.js';
67-
import { STUDIO_HEADER_ICON_BUTTON } from './studio-tokens.js';
116+
import { STUDIO_ACCENT, STUDIO_HEADER_ICON_BUTTON } from './studio-tokens.js';
68117
import {
69118
STUDIO_MENU_ADVANCED_COOKIE,
70119
STUDIO_MENU_COOKIE,
@@ -76,6 +125,7 @@ import {
76125
studioMenuScope,
77126
studioMenuTiers,
78127
type StudioMenuEntry,
128+
type StudioMenuGroup,
79129
type StudioMenuGroupModel,
80130
type StudioMenuTier,
81131
} from './studioMenuModel.js';
@@ -91,16 +141,90 @@ function writeAdvancedCookie(open: boolean): void {
91141
document.cookie = `${STUDIO_MENU_ADVANCED_COOKIE}=${open}; path=/; max-age=${ADVANCED_COOKIE_MAX_AGE}`;
92142
}
93143

144+
/**
145+
* Each listed type's line icon, drawn bare (no tile) before its name, as the
146+
* app menu draws an entry's. A type with no row here draws its group's icon.
147+
*/
148+
export const STUDIO_MENU_TYPE_ICONS: Readonly<Record<string, LucideIcon>> = {
149+
object: Table2,
150+
app: LayoutGrid,
151+
page: File,
152+
dashboard: Gauge,
153+
report: BarChart3,
154+
flow: Workflow,
155+
permission: Shield,
156+
agent: Bot,
157+
tool: Wrench,
158+
skill: Sparkles,
159+
picklist: ListChecks,
160+
hook: Webhook,
161+
mapping: ArrowLeftRight,
162+
object_extension: Puzzle,
163+
seed: Sprout,
164+
view: Rows3,
165+
action: MousePointerClick,
166+
dataset: Boxes,
167+
job: CalendarClock,
168+
doc: FileText,
169+
book: BookOpen,
170+
email_template: Mail,
171+
translation: Languages,
172+
api: Globe,
173+
datasource: Database,
174+
external_catalog: Unplug,
175+
position: Users,
176+
assignment_rule: UserCog,
177+
sharing_rule: Share2,
178+
queue: Inbox,
179+
capability: ListTree,
180+
ai_context: Brain,
181+
};
182+
183+
/** The icon of each entry that is not a type: the page it opens. */
184+
const STUDIO_MENU_KIND_ICONS: Readonly<Record<Exclude<StudioMenuEntry['kind'], 'type'>, LucideIcon>> = {
185+
orgFlows: Building2,
186+
owd: ShieldCheck,
187+
diagnostics: Activity,
188+
environment: KeyRound,
189+
allTypes: AppWindow,
190+
};
191+
192+
function studioMenuEntryIcon(entry: StudioMenuEntry, group: StudioMenuGroup | null): LucideIcon {
193+
if (entry.kind !== 'type') return STUDIO_MENU_KIND_ICONS[entry.kind];
194+
return STUDIO_MENU_TYPE_ICONS[entry.type ?? ''] ?? (group ? STUDIO_MENU_GROUP_ICONS[group] : LayoutGrid);
195+
}
94196

95197
/**
96-
* objectui#12795 — every `SidebarGroupLabel` call site hides its label from
97-
* focus and the accessibility tree in the icon sidebar (the primitive's own
98-
* `opacity-0` leaves it reachable). This menu is `offcanvas`, never `icon`, so
99-
* the classes never apply here; it carries them as every call site does.
198+
* One group of the menu: the app menu's collapsible group, open until the
199+
* author closes it, and open whatever its state while a search lists matches.
100200
*/
101-
const HIDDEN_ICON_LABEL_NOT_FOCUSABLE =
102-
'group-data-[state=collapsed]:group-data-[collapsible=icon]:invisible ' +
103-
'group-data-[state=collapsed]:group-data-[collapsible=icon]:transition-[margin,opacity,visibility]';
201+
function StudioMenuGroupSection({
202+
label,
203+
labelId,
204+
searching,
205+
testId,
206+
children,
207+
}: {
208+
label: string;
209+
labelId: string;
210+
searching: boolean;
211+
testId: string;
212+
children: React.ReactNode;
213+
}): React.ReactElement {
214+
const [open, setOpen] = React.useState(true);
215+
return (
216+
<NavigationGroupSection
217+
label={label}
218+
labelId={labelId}
219+
open={open}
220+
onOpenChange={setOpen}
221+
forceOpen={searching}
222+
data-testid={testId}
223+
>
224+
{children}
225+
</NavigationGroupSection>
226+
);
227+
}
104228

105229

106230
/**
@@ -230,12 +354,13 @@ function StudioMenuBody({
230354
writeAdvancedCookie(next);
231355
};
232356

233-
const renderEntry = (entry: StudioMenuEntry) => {
357+
const renderEntry = (entry: StudioMenuEntry, group: StudioMenuGroup | null) => {
234358
const label = labelOf(entry);
235359
const isCurrent = entry.key === current;
360+
const Icon = studioMenuEntryIcon(entry, group);
236361
return (
237362
<SidebarMenuItem key={entry.key}>
238-
<SidebarMenuButton asChild isActive={isCurrent} size="sm">
363+
<SidebarMenuButton asChild isActive={isCurrent}>
239364
<Link
240365
to={entry.to}
241366
aria-current={isCurrent ? 'page' : undefined}
@@ -253,10 +378,11 @@ function StudioMenuBody({
253378
if (isMobile) setOpenMobile(false);
254379
}}
255380
>
381+
<Icon aria-hidden="true" data-testid={`studio-menu-icon-${entry.key}`} />
256382
<span className={cn('min-w-0 flex-1 truncate', entry.empty && !isCurrent && 'text-muted-foreground')}>{label}</span>
257383
{entry.count !== undefined && !entry.empty && (
258384
<span
259-
className="tabular-nums text-[11px] text-muted-foreground"
385+
className={cn('tabular-nums text-xs', !isCurrent && 'text-muted-foreground')}
260386
title={tFormat('engine.studio.menu.itemCount', locale, { count: entry.count })}
261387
data-testid={`studio-menu-count-${entry.key}`}
262388
>
@@ -270,31 +396,22 @@ function StudioMenuBody({
270396
};
271397

272398
const renderGroups = (groups: readonly StudioMenuGroupModel[], tier: StudioMenuTier | 'flat') =>
273-
groups.map(({ group, entries }) => {
274-
const Icon = STUDIO_MENU_GROUP_ICONS[group];
275-
const labelId = `${searchId}-${tier}-${group}`;
276-
return (
277-
<SidebarGroup
278-
key={group}
279-
className="py-1"
280-
data-testid={tier === 'advanced' ? `studio-menu-advanced-group-${group}` : `studio-menu-group-${group}`}
281-
>
282-
<SidebarGroupLabel
283-
id={labelId}
284-
className={cn('h-6 gap-1.5 text-[11px] font-normal text-muted-foreground', HIDDEN_ICON_LABEL_NOT_FOCUSABLE)}
285-
>
286-
<Icon className="!h-3 !w-3 opacity-60" aria-hidden="true" />
287-
<span className="flex-1 truncate">{studioMenuGroupLabel(group, locale)}</span>
288-
</SidebarGroupLabel>
289-
<SidebarMenu aria-labelledby={labelId}>{entries.map(renderEntry)}</SidebarMenu>
290-
</SidebarGroup>
291-
);
292-
});
399+
groups.map(({ group, entries }) => (
400+
<StudioMenuGroupSection
401+
key={group}
402+
label={studioMenuGroupLabel(group, locale)}
403+
labelId={`${searchId}-${tier}-${group}`}
404+
searching={searching}
405+
testId={tier === 'advanced' ? `studio-menu-advanced-group-${group}` : `studio-menu-group-${group}`}
406+
>
407+
{entries.map((entry) => renderEntry(entry, group))}
408+
</StudioMenuGroupSection>
409+
));
293410

294411
// The fold's last row, under no group: no label above it, no group around it.
295412
const renderAllTypes = (entry: StudioMenuEntry) => (
296413
<div className="px-2 py-1" data-testid="studio-menu-all-types">
297-
<SidebarMenu aria-label={labelOf(entry)}>{renderEntry(entry)}</SidebarMenu>
414+
<SidebarMenu aria-label={labelOf(entry)}>{renderEntry(entry, null)}</SidebarMenu>
298415
</div>
299416
);
300417

@@ -305,56 +422,60 @@ function StudioMenuBody({
305422
// fixed to the window's full height as the app sidebar is.
306423
className="!absolute !h-full"
307424
>
308-
<SidebarHeader className="border-b p-2">
309-
<label htmlFor={searchId} className="sr-only">
310-
{t('engine.studio.menu.search', locale)}
311-
</label>
312-
<SidebarInput
313-
id={searchId}
314-
type="search"
315-
data-testid="studio-menu-search"
316-
placeholder={t('engine.studio.menu.search', locale)}
317-
value={query}
318-
onChange={(e) => setQuery(e.target.value)}
319-
/>
320-
</SidebarHeader>
321-
<SidebarContent>
322-
<nav aria-label={t('engine.studio.menu.label', locale)} data-testid="studio-menu">
323-
{matching.length === 0 && !allTypesMatches && (
324-
<p role="status" className="px-4 py-3 text-xs text-muted-foreground" data-testid="studio-menu-no-matches">
325-
{t('engine.studio.menu.noMatches', locale)}
326-
</p>
327-
)}
328-
{!folded && renderGroups(matching, 'flat')}
329-
{!folded && allTypes && allTypesMatches && renderAllTypes(allTypes)}
330-
{folded && renderGroups(tiers.common, 'common')}
331-
{folded && (tiers.advanced.length > 0 || allTypes) && (
332-
<>
333-
<div aria-hidden="true" data-testid="studio-menu-advanced-divider" className="mx-2 my-1 h-px bg-sidebar-border" />
334-
<div className="px-2 py-1">
335-
<button
336-
type="button"
337-
data-testid="studio-menu-advanced-toggle"
338-
aria-expanded={advancedOpen}
339-
aria-controls={advancedId}
340-
onClick={toggleAdvanced}
341-
className="flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-xs font-medium text-sidebar-foreground/80 outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2"
342-
>
343-
<ChevronRight
344-
className={cn('h-3.5 w-3.5 shrink-0 transition-transform', advancedOpen && 'rotate-90')}
345-
aria-hidden="true"
346-
/>
347-
<span className="flex-1 truncate">{t('engine.studio.menu.advanced', locale)}</span>
348-
</button>
349-
</div>
350-
<div id={advancedId} data-testid="studio-menu-advanced" hidden={!advancedOpen} className="pl-2">
351-
{renderGroups(tiers.advanced, 'advanced')}
352-
{allTypes && renderAllTypes(allTypes)}
353-
</div>
354-
</>
355-
)}
356-
</nav>
357-
</SidebarContent>
425+
{/* Studio's accent over everything the menu draws, docked or in the
426+
phone drawer (the primitive puts its own class on the docked frame only). */}
427+
<div data-studio-accent="" data-testid="studio-menu-accent" className={cn('flex min-h-0 flex-1 flex-col', STUDIO_ACCENT)}>
428+
<SidebarHeader className="border-b p-2">
429+
<label htmlFor={searchId} className="sr-only">
430+
{t('engine.studio.menu.search', locale)}
431+
</label>
432+
<SidebarInput
433+
id={searchId}
434+
type="search"
435+
data-testid="studio-menu-search"
436+
placeholder={t('engine.studio.menu.search', locale)}
437+
value={query}
438+
onChange={(e) => setQuery(e.target.value)}
439+
/>
440+
</SidebarHeader>
441+
<SidebarContent>
442+
<nav aria-label={t('engine.studio.menu.label', locale)} data-testid="studio-menu">
443+
{matching.length === 0 && !allTypesMatches && (
444+
<p role="status" className="px-4 py-3 text-xs text-muted-foreground" data-testid="studio-menu-no-matches">
445+
{t('engine.studio.menu.noMatches', locale)}
446+
</p>
447+
)}
448+
{!folded && renderGroups(matching, 'flat')}
449+
{!folded && allTypes && allTypesMatches && renderAllTypes(allTypes)}
450+
{folded && renderGroups(tiers.common, 'common')}
451+
{folded && (tiers.advanced.length > 0 || allTypes) && (
452+
<>
453+
<div aria-hidden="true" data-testid="studio-menu-advanced-divider" className="mx-2 my-1 h-px bg-sidebar-border" />
454+
<div className="px-2 py-1">
455+
<button
456+
type="button"
457+
data-testid="studio-menu-advanced-toggle"
458+
aria-expanded={advancedOpen}
459+
aria-controls={advancedId}
460+
onClick={toggleAdvanced}
461+
className="flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-xs font-medium text-sidebar-foreground/80 outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2"
462+
>
463+
<ChevronRight
464+
className={cn('h-3.5 w-3.5 shrink-0 transition-transform', advancedOpen && 'rotate-90')}
465+
aria-hidden="true"
466+
/>
467+
<span className="flex-1 truncate">{t('engine.studio.menu.advanced', locale)}</span>
468+
</button>
469+
</div>
470+
<div id={advancedId} data-testid="studio-menu-advanced" hidden={!advancedOpen} className="pl-2">
471+
{renderGroups(tiers.advanced, 'advanced')}
472+
{allTypes && renderAllTypes(allTypes)}
473+
</div>
474+
</>
475+
)}
476+
</nav>
477+
</SidebarContent>
478+
</div>
358479
</Sidebar>
359480
);
360481
}

0 commit comments

Comments
 (0)