Skip to content

Commit 1878181

Browse files
committed
[ISSUE #15354] Adjust sidebar menu elements (#15455)
Move the sidebar collapse control to the header, place setting center under platform management, and add a user icon to the account dropdown. Assisted-by: Claude Code (cherry picked from commit e9e5aaa)
1 parent 9d8f220 commit 1878181

72 files changed

Lines changed: 210 additions & 129 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎console-ui-next/src/components/layout/__tests__/header-change-password.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,32 @@ describe('Header namespace switch wiring', () => {
5252
);
5353
});
5454
});
55+
56+
describe('Header sidebar and user menu wiring', () => {
57+
it('renders the sidebar toggle before the namespace selector', () => {
58+
const leftBlock = HEADER_SOURCE.slice(
59+
HEADER_SOURCE.indexOf('{/* Left - Sidebar toggle and namespace selector */}'),
60+
HEADER_SOURCE.indexOf('{/* Center - Navigation links */}'),
61+
);
62+
63+
expect(HEADER_SOURCE).toContain('sidebarCollapsed');
64+
expect(HEADER_SOURCE).toContain('toggleSidebar');
65+
expect(HEADER_SOURCE).toContain('PanelLeft');
66+
expect(HEADER_SOURCE).toContain('PanelLeftClose');
67+
expect(leftBlock.indexOf('onClick={toggleSidebar}')).toBeGreaterThan(-1);
68+
expect(leftBlock.indexOf('onClick={toggleSidebar}')).toBeLessThan(
69+
leftBlock.indexOf("t('common.selectNamespace')"),
70+
);
71+
});
72+
73+
it('shows a user icon in the dropdown username row', () => {
74+
const userMenuBlock = HEADER_SOURCE.slice(
75+
HEADER_SOURCE.indexOf('<DropdownMenuContent align="end"'),
76+
HEADER_SOURCE.indexOf('<DropdownMenuSeparator />'),
77+
);
78+
79+
expect(HEADER_SOURCE).toContain('UserRound');
80+
expect(userMenuBlock).toContain('<UserRound size={14}');
81+
expect(userMenuBlock).toContain('<span className="truncate">{username}</span>');
82+
});
83+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it } from 'vitest';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const SIDEBAR_SOURCE = fs.readFileSync(
6+
path.resolve(__dirname, '../sidebar.tsx'),
7+
'utf-8',
8+
);
9+
10+
describe('Sidebar platform layout', () => {
11+
it('keeps setting center under platform management with the existing copilot gate', () => {
12+
const settingsBlock = SIDEBAR_SOURCE.slice(
13+
SIDEBAR_SOURCE.indexOf('if (copilotEnabled)'),
14+
SIDEBAR_SOURCE.indexOf('const navTo = useCallback'),
15+
);
16+
17+
expect(settingsBlock).toContain('platformItems.push');
18+
expect(settingsBlock).toContain("key: 'settings'");
19+
expect(settingsBlock).toContain("label: t('menu.settingCenter')");
20+
expect(settingsBlock).toContain("path: '/settingCenter'");
21+
});
22+
23+
it('auto-expands platform management when setting center is active', () => {
24+
const platformPathsBlock = SIDEBAR_SOURCE.slice(
25+
SIDEBAR_SOURCE.indexOf('const platformPaths = ['),
26+
SIDEBAR_SOURCE.indexOf('if (platformPaths.some'),
27+
);
28+
29+
expect(platformPathsBlock).toContain("'/settingCenter'");
30+
});
31+
32+
it('leaves only version information in the sidebar bottom section', () => {
33+
const bottomBlock = SIDEBAR_SOURCE.slice(
34+
SIDEBAR_SOURCE.indexOf('{/* Bottom Section */}'),
35+
SIDEBAR_SOURCE.indexOf('</aside>'),
36+
);
37+
38+
expect(bottomBlock).toContain('{version && `v${version}`}');
39+
expect(bottomBlock).toContain('{startupMode && ` · ${startupMode}`}');
40+
expect(bottomBlock).not.toContain('settingCenter');
41+
expect(bottomBlock).not.toContain('toggleSidebar');
42+
expect(bottomBlock).not.toContain('PanelLeft');
43+
});
44+
});

‎console-ui-next/src/components/layout/header.tsx‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
KeyRound,
1010
Layers,
1111
ArrowLeftRight,
12+
PanelLeft,
13+
PanelLeftClose,
14+
UserRound,
1215
} from 'lucide-react';
1316
import { useAppStore } from '@/stores/app-store';
1417
import { useAuthStore } from '@/stores/auth-store';
@@ -66,13 +69,14 @@ export function Header() {
6669
const { t } = useTranslation();
6770
const navigate = useNavigate();
6871
const location = useLocation();
69-
const { theme, setTheme, language, setLanguage } = useAppStore();
72+
const { theme, setTheme, language, setLanguage, sidebarCollapsed, toggleSidebar } = useAppStore();
7073
const { username, logout, isOidcUser } = useAuthStore();
7174
const { currentNamespace, namespaces, setNamespace, getNamespaceChangeGuard } = useNamespaceStore();
7275
const { authEnabled } = useServerStore();
7376
const [changePasswordOpen, setChangePasswordOpen] = useState(false);
7477

7578
const baseUrl = getBaseUrl(language);
79+
const sidebarToggleLabel = sidebarCollapsed ? t('common.expand') : t('common.collapse');
7680

7781
const toggleTheme = () => setTheme(theme === 'light' ? 'dark' : 'light');
7882
const toggleLanguage = () => {
@@ -99,8 +103,22 @@ export function Header() {
99103

100104
return (
101105
<header className="sticky top-0 z-30 flex h-14 items-center justify-between border-b border-border bg-background/80 backdrop-blur-md px-4">
102-
{/* Left - Namespace selector */}
106+
{/* Left - Sidebar toggle and namespace selector */}
103107
<div className="flex items-center gap-2 shrink-0">
108+
<Tooltip>
109+
<TooltipTrigger asChild>
110+
<Button
111+
variant="ghost"
112+
size="icon"
113+
className="h-8 w-8 text-muted-foreground"
114+
onClick={toggleSidebar}
115+
aria-label={sidebarToggleLabel}
116+
>
117+
{sidebarCollapsed ? <PanelLeft size={16} /> : <PanelLeftClose size={16} />}
118+
</Button>
119+
</TooltipTrigger>
120+
<TooltipContent>{sidebarToggleLabel}</TooltipContent>
121+
</Tooltip>
104122
<Layers size={16} className="text-primary shrink-0" />
105123
<span className="text-xs font-medium text-foreground/70 shrink-0 hidden lg:inline">{t('common.selectNamespace')}</span>
106124
<Select value={currentNamespace} onValueChange={handleNamespaceChange}>
@@ -197,7 +215,10 @@ export function Header() {
197215
</Button>
198216
</DropdownMenuTrigger>
199217
<DropdownMenuContent align="end" className="w-48">
200-
<div className="px-2 py-1.5 text-xs text-muted-foreground">{username}</div>
218+
<div className="flex items-center gap-2 px-2 py-1.5 text-xs text-muted-foreground">
219+
<UserRound size={14} className="shrink-0" />
220+
<span className="truncate">{username}</span>
221+
</div>
201222
<DropdownMenuSeparator />
202223
{!isOidcUser() && (
203224
<>

‎console-ui-next/src/components/layout/sidebar.tsx‎

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
Settings,
1515
ChevronDown,
1616
ChevronRight,
17-
PanelLeftClose,
18-
PanelLeft,
1917
Puzzle,
2018
History,
2119
Radio,
@@ -58,19 +56,22 @@ export function Sidebar() {
5856
const { t } = useTranslation();
5957
const location = useLocation();
6058
const navigate = useNavigate();
61-
const { sidebarCollapsed, toggleSidebar } = useAppStore();
59+
const { sidebarCollapsed } = useAppStore();
6260
const { globalAdmin } = useAuthStore();
6361
const { version, startupMode, functionMode, copilotEnabled, aiEnabled } = useServerStore();
6462
const { currentNamespace, namespaceShowName } = useNamespaceStore();
65-
const [platformOpen, setPlatformOpen] = useState(false);
66-
67-
// Auto-expand platform section if current path is within it
68-
useEffect(() => {
69-
const platformPaths = ['/namespace', '/clusterManagement', '/pluginManagement', '/userManagement', '/rolesManagement', '/permissionsManagement'];
70-
if (platformPaths.some((p) => location.pathname === p)) {
71-
setPlatformOpen(true);
72-
}
73-
}, [location.pathname]);
63+
const platformPaths = [
64+
'/namespace',
65+
'/clusterManagement',
66+
'/pluginManagement',
67+
'/userManagement',
68+
'/rolesManagement',
69+
'/permissionsManagement',
70+
'/settingCenter',
71+
];
72+
const platformActive = platformPaths.some((p) => location.pathname === p);
73+
const [platformOpen, setPlatformOpen] = useState(platformActive);
74+
const platformExpanded = platformOpen || platformActive;
7475

7576
const coreItems: NavItem[] = [];
7677

@@ -151,6 +152,15 @@ export function Sidebar() {
151152
});
152153
}
153154

155+
if (copilotEnabled) {
156+
platformItems.push({
157+
key: 'settings',
158+
label: t('menu.settingCenter'),
159+
icon: <Settings size={18} />,
160+
path: '/settingCenter',
161+
});
162+
}
163+
154164
const navTo = useCallback(
155165
(url: string) => {
156166
const params = new URLSearchParams();
@@ -276,9 +286,9 @@ export function Sidebar() {
276286
)
277287
)
278288
) : (
279-
<Collapsible open={platformOpen} onOpenChange={setPlatformOpen}>
289+
<Collapsible open={platformExpanded} onOpenChange={setPlatformOpen}>
280290
<CollapsibleTrigger className="flex w-full items-center gap-2 rounded-md px-2 py-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors">
281-
{platformOpen ? <ChevronDown size={12} /> : <ChevronRight size={12} />}
291+
{platformExpanded ? <ChevronDown size={12} /> : <ChevronRight size={12} />}
282292
{t('menu.platformManagement')}
283293
</CollapsibleTrigger>
284294
<CollapsibleContent className="space-y-1">
@@ -310,33 +320,13 @@ export function Sidebar() {
310320
</ScrollArea>
311321

312322
{/* Bottom Section */}
313-
<div className="border-t border-sidebar-border p-2 space-y-1">
323+
<div className="border-t border-sidebar-border px-2 py-3">
314324
{!sidebarCollapsed && (
315-
<div className="px-3 py-1.5 text-xs text-muted-foreground text-center">
325+
<div className="min-h-5 px-2 text-center text-xs leading-5 text-muted-foreground">
316326
{version && `v${version}`}
317327
{startupMode && ` · ${startupMode}`}
318328
</div>
319329
)}
320-
{copilotEnabled && (
321-
<NavLink
322-
item={{
323-
key: 'settings',
324-
label: t('menu.settingCenter'),
325-
icon: <Settings size={18} />,
326-
path: '/settingCenter',
327-
}}
328-
collapsed={sidebarCollapsed}
329-
active={isActive('/settingCenter')}
330-
onClick={() => navTo('/settingCenter')}
331-
/>
332-
)}
333-
<button
334-
onClick={toggleSidebar}
335-
className="flex w-full items-center justify-center gap-2 rounded-md px-2 py-2 text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground transition-colors"
336-
>
337-
{sidebarCollapsed ? <PanelLeft size={18} /> : <PanelLeftClose size={18} />}
338-
{!sidebarCollapsed && <span className="text-xs">{t('common.collapse') || 'Collapse'}</span>}
339-
</button>
340330
</div>
341331
</aside>
342332
);
@@ -409,10 +399,7 @@ function NavGroup({
409399
const [open, setOpen] = useState(isGroupActive || !!item.defaultOpen);
410400
const [flyoutOpen, setFlyoutOpen] = useState(false);
411401
const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
412-
413-
useEffect(() => {
414-
if (isGroupActive) setOpen(true);
415-
}, [isGroupActive]);
402+
const expanded = open || isGroupActive;
416403

417404
useEffect(() => {
418405
return () => { if (closeTimer.current) clearTimeout(closeTimer.current); };
@@ -499,7 +486,7 @@ function NavGroup({
499486
}
500487

501488
return (
502-
<Collapsible open={open} onOpenChange={setOpen}>
489+
<Collapsible open={expanded} onOpenChange={setOpen}>
503490
<CollapsibleTrigger className="flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium text-sidebar-foreground hover:bg-sidebar-accent/60 transition-all duration-200">
504491
<span className="shrink-0">{item.icon}</span>
505492
<span className="truncate flex-1 text-left">{item.label}</span>
@@ -508,7 +495,7 @@ function NavGroup({
508495
{item.badge}
509496
</Badge>
510497
)}
511-
{open ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
498+
{expanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
512499
</CollapsibleTrigger>
513500
<CollapsibleContent className="ml-4 space-y-0.5 border-l border-sidebar-border pl-3 mt-0.5">
514501
{item.children?.map((child) => (

‎console/src/main/resources/static/next/css/main.css‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎console/src/main/resources/static/next/js/AppLayout.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎console/src/main/resources/static/next/js/CliCommandCard.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)