Skip to content

Commit f087214

Browse files
committed
Store compare page tab in URL
1 parent 85985de commit f087214

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

site/frontend/src/pages/compare/page.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {loadBenchmarkInfo} from "../../api";
33
import AsOf from "../../components/as-of.vue";
44
import {
5-
createUrlFromParams,
5+
changeUrl,
66
createUrlWithAppendedParams,
77
getUrlParams,
88
navigateToUrlParams,
@@ -41,6 +41,21 @@ function loadSelectorFromUrl(urlParams: Dict<string>): CompareSelector {
4141
};
4242
}
4343
44+
function loadTabFromUrl(urlParams: Dict<string>): Tab | null {
45+
const tab = urlParams["tab"] ?? "";
46+
if (tab == Tab.CompileTime) {
47+
return Tab.CompileTime;
48+
} else if (tab == Tab.Bootstrap) {
49+
return Tab.Bootstrap;
50+
}
51+
return null;
52+
}
53+
54+
function storeTabToUrl(urlParams: Dict<string>, tab: Tab) {
55+
urlParams["tab"] = tab as string;
56+
changeUrl(urlParams);
57+
}
58+
4459
function loadFilterFromUrl(
4560
urlParams: Dict<string>,
4661
defaultFilter: DataFilter
@@ -141,10 +156,7 @@ function storeFilterToUrl(
141156
defaultFilter.category.secondary
142157
);
143158
144-
// Change URL without creating a history entry
145-
if (history.replaceState) {
146-
history.replaceState({}, null, createUrlFromParams(urlParams).toString());
147-
}
159+
changeUrl(urlParams);
148160
}
149161
150162
async function loadCompareData(
@@ -246,10 +258,12 @@ const info = await loadBenchmarkInfo();
246258
const selector = loadSelectorFromUrl(urlParams);
247259
const filter = ref(loadFilterFromUrl(urlParams, defaultFilter));
248260
249-
const tab: Ref<Tab> = ref(Tab.CompileTime);
261+
const initialTab: Tab = loadTabFromUrl(urlParams) ?? Tab.CompileTime;
262+
const tab: Ref<Tab> = ref(initialTab);
250263
251264
function changeTab(newTab: Tab) {
252265
tab.value = newTab;
266+
storeTabToUrl(getUrlParams(), newTab);
253267
}
254268
255269
const data: Ref<CompareResponse | null> = ref(null);
@@ -273,6 +287,7 @@ loadCompareData(selector, loading);
273287
<Tabs
274288
@change-tab="changeTab"
275289
:data="data"
290+
:initial-tab="initialTab"
276291
:compile-time-summary="totalSummary"
277292
/>
278293
<template v-if="tab === Tab.CompileTime">

site/frontend/src/pages/compare/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ export interface CompareResponse {
6868
}
6969

7070
export enum Tab {
71-
CompileTime,
72-
Bootstrap,
71+
CompileTime = "compile",
72+
Bootstrap = "bootstrap",
7373
}

site/frontend/src/utils/navigation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ export function getUrlParams(): Dict<string> {
4242
export function navigateToUrlParams(params: URLSearchParams) {
4343
window.location.search = params.toString();
4444
}
45+
46+
/**
47+
* Changes the current URL without navigating away from the page and without
48+
* creating a history entry.
49+
*/
50+
export function changeUrl(params: Dict<string>) {
51+
if (history.replaceState) {
52+
history.replaceState({}, null, createUrlFromParams(params).toString());
53+
}
54+
}

0 commit comments

Comments
 (0)