Skip to content

Commit 21a911b

Browse files
committed
fix: persist active tab via URL params, show full worker names
- Tab state now stored in ?tab= URL param so it survives navigation - Day period selector preserves tab=infra when changing time range - Worker names shown in full (not truncated) for easier identification
1 parent 09a6593 commit 21a911b

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

src/lib/components/dash/WorkerHealth.svelte

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
function errorRate(row: WorkerRow): number {
2727
return row.requests > 0 ? (row.errors / row.requests) * 100 : 0;
2828
}
29-
30-
function shortName(name: string): string {
31-
return name.replace(/^esolia-/, '');
32-
}
3329
</script>
3430

3531
<div class="rounded-lg border border-accent-200 dark:border-accent-700">
@@ -61,7 +57,7 @@
6157
{@const er = errorRate(w)}
6258
<tr class="border-b border-accent-100 dark:border-accent-800">
6359
<td class="px-4 py-1.5 font-mono text-xs text-accent-800 dark:text-accent-200">
64-
{shortName(w.script_name)}
60+
{w.script_name}
6561
</td>
6662
<td class="px-4 py-1.5 text-right tabular-nums text-accent-600 dark:text-accent-400">
6763
{w.requests.toLocaleString()}

src/routes/dash/+page.svelte

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import WorkerHealth from '$lib/components/dash/WorkerHealth.svelte';
66
import WorkflowStatus from '$lib/components/dash/WorkflowStatus.svelte';
77
import DeploymentTimeline from '$lib/components/dash/DeploymentTimeline.svelte';
8+
import { page } from '$app/stores';
9+
import { goto } from '$app/navigation';
810
911
let { data } = $props();
1012
@@ -14,7 +16,30 @@
1416
const isError = $derived(data.status !== 200 || d.error);
1517
1618
type Tab = 'seo' | 'infra' | 'workflows' | 'security';
17-
let activeTab: Tab = $state('seo');
19+
const validTabs: Tab[] = ['seo', 'infra', 'workflows', 'security'];
20+
const activeTab: Tab = $derived.by(() => {
21+
const t = $page.url.searchParams.get('tab');
22+
return validTabs.includes(t as Tab) ? (t as Tab) : 'seo';
23+
});
24+
25+
function buildParams(overrides: Record<string, string>): string {
26+
const entries: [string, string][] = [];
27+
for (const [k, v] of $page.url.searchParams.entries()) {
28+
if (!(k in overrides)) entries.push([k, v]);
29+
}
30+
for (const [k, v] of Object.entries(overrides)) {
31+
entries.push([k, v]);
32+
}
33+
return entries.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
34+
}
35+
36+
function switchTab(tab: Tab) {
37+
void goto(`/dash?${buildParams({ tab })}`, { replaceState: true, noScroll: true });
38+
}
39+
40+
function dayLink(d: number): string {
41+
return `/dash?${buildParams({ days: String(d), tab: 'infra' })}`;
42+
}
1843
1944
function cqStatusDot(summary: { pagesWithIssues: number }): string {
2045
if (summary.pagesWithIssues === 0) return 'bg-emerald-500';
@@ -87,9 +112,7 @@
87112
{activeTab === tab.id
88113
? 'bg-white text-accent-900 shadow-sm dark:bg-accent-700 dark:text-accent-100'
89114
: 'text-accent-600 hover:text-accent-900 dark:text-accent-400 dark:hover:text-accent-200'}"
90-
onclick={() => {
91-
activeTab = tab.id as Tab;
92-
}}
115+
onclick={() => switchTab(tab.id as Tab)}
93116
>
94117
{tab.label}
95118
</button>
@@ -667,14 +690,11 @@
667690
<div class="flex gap-1 rounded-md bg-accent-100 p-0.5 dark:bg-accent-800">
668691
{#each [1, 7, 14, 30] as d (d)}
669692
<a
670-
href="/dash?days={d}"
693+
href={dayLink(d)}
671694
class="rounded px-2 py-1 text-xs font-medium transition-colors
672695
{infra.days === d
673696
? 'bg-white text-accent-900 shadow-sm dark:bg-accent-700 dark:text-accent-100'
674697
: 'text-accent-500 hover:text-accent-800 dark:text-accent-400 dark:hover:text-accent-200'}"
675-
onclick={() => {
676-
activeTab = 'infra';
677-
}}
678698
>
679699
{d}d
680700
</a>

0 commit comments

Comments
 (0)