From 068971b4deb5a395eb6210007982766b642a8c7e Mon Sep 17 00:00:00 2001 From: Suresh Chaudhary Date: Thu, 21 May 2026 10:44:23 +0530 Subject: [PATCH] chore: persist time ranges across logs and dashboard pages when navigating via the sidebar --- ui/components/sidebar.tsx | 47 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/ui/components/sidebar.tsx b/ui/components/sidebar.tsx index 5d8049c5c98..dcb159c2188 100644 --- a/ui/components/sidebar.tsx +++ b/ui/components/sidebar.tsx @@ -188,6 +188,29 @@ const TimeFilterPages = new Set([ "/workspace/mcp-logs", ]); +const preserveTimeFilters = ( + baseHref: string, + subItemUrl: string, + pathname: string, + search: string, +): string => { + if (TimeFilterPages.has(subItemUrl) && TimeFilterPages.has(pathname)) { + const currentParams = new URLSearchParams(search); + const startTime = currentParams.get("start_time"); + const endTime = currentParams.get("end_time"); + const period = currentParams.get("period"); + if ((startTime && endTime) || period) { + const params = new URLSearchParams(); + if (startTime) params.set("start_time", startTime); + if (endTime) params.set("end_time", endTime); + if (period) params.set("period", period); + const sep = baseHref.includes("?") ? "&" : "?"; + return `${baseHref}${sep}${params.toString()}`; + } + } + return baseHref; +}; + const SidebarItemView = ({ item, isActive, @@ -405,7 +428,8 @@ const SidebarItemView = ({ {item.title} {item.subItems?.map((subItem) => { - const href = getSidebarItemHref(subItem); + const baseHref = getSidebarItemHref(subItem); + const href = preserveTimeFilters(baseHref, subItem.url, pathname, search); const isSubItemActive = subItem.queryParam ? pathname === subItem.url : isRouteMatch(subItem.url); @@ -468,26 +492,7 @@ const SidebarItemView = ({ {item.subItems?.map((subItem: SidebarItem) => { const baseHref = getSidebarItemHref(subItem); - const subItemHref = (() => { - if ( - TimeFilterPages.has(subItem.url) && - TimeFilterPages.has(pathname) - ) { - const currentParams = new URLSearchParams(search); - const startTime = currentParams.get("start_time"); - const endTime = currentParams.get("end_time"); - const period = currentParams.get("period"); - if ((startTime && endTime) || period) { - const params = new URLSearchParams(); - if (startTime) params.set("start_time", startTime); - if (endTime) params.set("end_time", endTime); - if (period) params.set("period", period); - const sep = baseHref.includes("?") ? "&" : "?"; - return `${baseHref}${sep}${params.toString()}`; - } - } - return baseHref; - })(); + const subItemHref = preserveTimeFilters(baseHref, subItem.url, pathname, search); // For query param based subitems, check if tab matches const isSubItemActive = subItem.queryParam ? pathname === subItem.url