Skip to content

Commit cb5bd56

Browse files
Copilotphrocker
andauthored
Auto-expand sidebar submenus based on current page URL (#93)
* Initial plan * Add auto-expand functionality for sidebar submenus based on current URL Co-authored-by: phrocker <1781585+phrocker@users.noreply.github.com> * Improve active link highlighting to select most specific match Co-authored-by: phrocker <1781585+phrocker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: phrocker <1781585+phrocker@users.noreply.github.com>
1 parent 6b92c6b commit cb5bd56

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

api/src/main/resources/templates/fragments/header.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,61 @@
331331
$("#systemBanner").show();
332332
[/]
333333
334+
// Auto-expand sidebar submenu based on current URL
335+
(function() {
336+
const currentPath = window.location.pathname;
337+
338+
// Define URL patterns for each submenu
339+
const submenuPatterns = {
340+
'infrastructureSubmenu': ['/sso/v1/enclaves/', '/sso/v1/integrations'],
341+
'securitySubmenu': ['/sso/v1/zerotrust/', '/sso/v1/atpl/', '/sso/trust-scores', '/sso/v1/attributes/'],
342+
'aiSubmenu': ['/sso/v1/users/', '/sso/v1/agent/'],
343+
'systemSubmenu': ['/sso/v1/system/', '/sso/v1/telemetry', '/sso/v1/automation/', '/sso/v1/k8s/']
344+
};
345+
346+
// Find which submenu should be expanded
347+
for (const [submenuId, patterns] of Object.entries(submenuPatterns)) {
348+
for (const pattern of patterns) {
349+
if (currentPath.startsWith(pattern)) {
350+
// Use Bootstrap's Collapse API to show the submenu
351+
const submenuElement = document.getElementById(submenuId);
352+
if (submenuElement) {
353+
// Add 'show' class to expand the submenu
354+
submenuElement.classList.add('show');
355+
356+
// Find and highlight the active menu item within this submenu
357+
const links = submenuElement.querySelectorAll('a.nav-link');
358+
let bestMatch = null;
359+
let bestMatchLength = 0;
360+
361+
// Find the most specific (longest) matching link
362+
links.forEach(function(link) {
363+
const href = link.getAttribute('href');
364+
if (href && currentPath.startsWith(href) && href.length > bestMatchLength) {
365+
bestMatch = link;
366+
bestMatchLength = href.length;
367+
}
368+
});
369+
370+
// Apply active class to the best match only
371+
if (bestMatch) {
372+
bestMatch.classList.add('active');
373+
}
374+
}
375+
return; // Exit once we find a match
376+
}
377+
}
378+
}
379+
380+
// Also highlight top-level menu items (Dashboard, Notifications)
381+
$('#menu > li > a.nav-link').each(function() {
382+
const href = $(this).attr('href');
383+
if (href && currentPath === href) {
384+
$(this).addClass('active');
385+
}
386+
});
387+
})();
388+
334389
});
335390

336391
/*]]>*/

0 commit comments

Comments
 (0)