Skip to content

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

#36

dduxe90b9f9f8626
diff --git a/frontend/src/lib/utils/navigation.ts b/frontend/src/lib/utils/navigation.ts
index 11a0c918..1b7e2b48 100644
--- a/frontend/src/lib/utils/navigation.ts
+++ b/frontend/src/lib/utils/navigation.ts
@@ -1,18 +1,30 @@
import { goto } from '$app/navigation';
-/**
- * Handles row click with support for ctrl/cmd+click to open in new tab.
- * Returns an onclick handler for use in table rows.
- */
-export function createRowClickHandler(href: string) {
+// 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) => {
- // Check for ctrl (Windows/Linux) or cmd (Mac) key
+ 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;
+ }
+
if (event.ctrlKey || event.metaKey) {
- // Open in new tab
- window.open(href, '_blank');
+ window.open(finalHref, '_blank');
} else {
- // Normal navigation
- goto(href);
+ // eslint-disable-next-line svelte/no-navigation-without-resolve
+ goto(finalHref);
}
};
-}
+}
\ No newline at end of file
diff --git a/frontend/src/routes/transactions/+page.svelte b/frontend/src/routes/transactions/+page.svelte
index fa413fdc..699c7f22 100644
--- a/frontend/src/routes/transactions/+page.svelte
+++ b/frontend/src/routes/transactions/+page.svelte
@@ -16,6 +16,8 @@
import { TimeRangePicker } from "$lib/components/ui/time-range-picker";
import { CalendarDate, getLocalTimeZone, today } from "@internationalized/date";
import { projectsState } from '$lib/state/projects.svelte';
+ import { createRowClickHandler } from '$lib/utils/navigation';
+ import { resolve } from '$app/paths';
const timezone = $derived(getTimezone());
@@ -271,26 +273,6 @@
loadData(false); // Don't push to history for sorting
}
- function getEndpointUrl(endpoint: string): string {
- const params = new URLSearchParams();
- if (selectedPreset) {
- params.set('preset', selectedPreset);
- } else {
- params.set('from', getFromDateTimeUTC());
- params.set('to', getToDateTimeUTC());
- }
- return `/transactions/${encodeURIComponent(endpoint)}?${params.toString()}`;
- }
-
- function navigateToEndpoint(endpoint: string, event: MouseEvent) {
- const url = getEndpointUrl(endpoint);
- if (event.ctrlKey || event.metaKey) {
- window.open(url, '_blank');
- } else {
- window.location.href = url;
- }
- }
-
onMount(() => {
// Add popstate listener for back/forward navigation
window.addEventListener('popstate', handlePopState);
@@ -396,7 +378,7 @@
{@const impactLevel = getImpactLevel(endpoint.count, endpoint.p50Duration, endpoint.p95Duration)}
<Table.Row
class="cursor-pointer hover:bg-muted/50"
- onclick={(e) => navigateToEndpoint(endpoint.endpoint, e)}
+ onclick={createRowClickHandler(resolve(`/transactions/${encodeURIComponent(endpoint.endpoint)}`), 'preset', 'from', 'to')}
>
<Table.Cell class="font-mono text-sm">
{endpoint.endpoint}