Skip to content

The only tool you need to know what is happening and how to fix it.

sidebar fixes

dduxa31a8dd9aa35
diff --git a/frontend/src/lib/components/app-sidebar.svelte b/frontend/src/lib/components/app-sidebar.svelte
index 82ef76e1..a9f3480e 100644
--- a/frontend/src/lib/components/app-sidebar.svelte
+++ b/frontend/src/lib/components/app-sidebar.svelte
@@ -1,61 +1,21 @@
<script lang="ts">
import * as Sidebar from "$lib/components/ui/sidebar";
- import { List, Bug, Link2, BarChart3 } from "@lucide/svelte";
+ import { useSidebar } from '$lib/components/ui/sidebar';
+ import { List, Bug, Link2, ChartLine } from "@lucide/svelte";
import { themeState } from '$lib/state/theme.svelte';
import { LayoutDashboard } from "@lucide/svelte";
import { page } from '$app/state';
-
- // Pages that share time range params
- const timeRangePages = ['/metrics', '/transactions'];
+ import { createRowClickHandler } from "$lib/utils/navigation";
const sidebarItems = [
- {Icon: LayoutDashboard, href: "/", title: "Dashboard"},
- {Icon: Bug, href: "/issues", title: "Issues"},
- {Icon: List, href: "/transactions", title: "Transactions"},
- {Icon: BarChart3, href: "/metrics", title: "Metrics"},
- {Icon: Link2, href: "/connection", title: "Connection"},
+ {Icon: LayoutDashboard, href: "/", title: "Dashboard", stickyParams: [] as string[]},
+ {Icon: Bug, href: "/issues", title: "Issues", stickyParams: [] as string[]},
+ {Icon: List, href: "/transactions", title: "Transactions", stickyParams: ['presets', 'from', 'to']},
+ {Icon: ChartLine, href: "/metrics", title: "Metrics", stickyParams: ['presets', 'from', 'to']},
+ {Icon: Link2, href: "/connection", title: "Connection", stickyParams: [] as string[]},
]
- // Reactive sidebar items with computed hrefs - explicitly read page.url to track dependency
- const sidebarItemsWithHref = $derived.by(() => {
- // Read page.url properties directly to establish reactive dependency
- const currentPath = page.url.pathname;
- const currentSearch = page.url.search;
- const preset = page.url.searchParams.get('preset');
- const from = page.url.searchParams.get('from');
- const to = page.url.searchParams.get('to');
- const servers = page.url.searchParams.get('servers');
-
- const isCurrentTimeRangePage = timeRangePages.some(p => currentPath.startsWith(p));
-
- return sidebarItems.map(item => {
- const isTargetTimeRangePage = timeRangePages.includes(item.href);
-
- let computedHref = item.href;
-
- if (isCurrentTimeRangePage && isTargetTimeRangePage) {
- const params = new URLSearchParams();
-
- if (preset) {
- params.set('preset', preset);
- } else if (from && to) {
- params.set('from', from);
- params.set('to', to);
- }
-
- // Also preserve servers param for metrics page
- if (item.href === '/metrics' && servers) {
- params.set('servers', servers);
- }
-
- const queryString = params.toString();
- computedHref = queryString ? `${item.href}?${queryString}` : item.href;
- }
-
- return { ...item, computedHref };
- });
- });
-
+ const sidebar = useSidebar();
</script>
<Sidebar.Sidebar>
@@ -70,14 +30,15 @@
<Sidebar.SidebarGroup>
<Sidebar.SidebarGroupContent>
<Sidebar.SidebarMenu>
- {#each sidebarItemsWithHref as sidebarItem}
+ {#each sidebarItems as sidebarItem}
<Sidebar.SidebarMenuItem>
- <a href={sidebarItem.computedHref}>
- <Sidebar.SidebarMenuButton isActive={page.url.pathname === sidebarItem.href || page.url.pathname.startsWith(sidebarItem.href + '/')}>
- <sidebarItem.Icon />
- <span>{sidebarItem.title}</span>
- </Sidebar.SidebarMenuButton>
- </a>
+ <Sidebar.SidebarMenuButton isActive={page.url.pathname === sidebarItem.href || page.url.pathname.startsWith(sidebarItem.href + '/')} onclick={(e) => {
+ sidebar.setOpenMobile(false)
+ createRowClickHandler(sidebarItem.href, ...sidebarItem.stickyParams)(e)
+ }}>
+ <sidebarItem.Icon />
+ <span>{sidebarItem.title}</span>
+ </Sidebar.SidebarMenuButton>
</Sidebar.SidebarMenuItem>
{/each}
</Sidebar.SidebarMenu>
diff --git a/frontend/src/lib/utils/navigation.ts b/frontend/src/lib/utils/navigation.ts
index 1b7e2b48..49d87842 100644
--- a/frontend/src/lib/utils/navigation.ts
+++ b/frontend/src/lib/utils/navigation.ts
@@ -1,24 +1,29 @@
import { goto } from '$app/navigation';
+export function addStickyParamsToHref(href: string, ...stickyParams: string[]) {
+ let finalHref = href;
+
+ if (stickyParams.length > 0) {
+ const currentParams = new URLSearchParams(window.location.search);
+ const url = new URL(href, window.location.origin);
+
+ stickyParams.forEach(stickyParam => {
+ const currentValue = currentParams.get(stickyParam);
+ if (currentValue !== null) {
+ url.searchParams.set(stickyParam, currentValue);
+ }
+ });
+
+ finalHref = url.pathname + url.search;
+ }
+ return finalHref;
+}
+
// in the future it would be really cool if we could bind the type here to get type safety and force the use of resolve :/
// this also won't work with absolute paths - meh so be it
export function createRowClickHandler(href: string, ...stickyParams: string[]) {
return (event: MouseEvent) => {
- let finalHref = href;
-
- if (stickyParams.length > 0) {
- const currentParams = new URLSearchParams(window.location.search);
- const url = new URL(href, window.location.origin);
-
- stickyParams.forEach(stickyParam => {
- const currentValue = currentParams.get(stickyParam);
- if (currentValue !== null) {
- url.searchParams.set(stickyParam, currentValue);
- }
- });
-
- finalHref = url.pathname + url.search;
- }
+ const finalHref = addStickyParamsToHref(href, ...stickyParams);
if (event.ctrlKey || event.metaKey) {
window.open(finalHref, '_blank');