Skip to content

Commit 9bdb9d6

Browse files
committed
Load initial state of UI filters in compare page from URL
1 parent 49440ef commit 9bdb9d6

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

site/static/compare/script.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
function findQueryParam(name) {
2-
let urlParams = window.location.search?.substring(1).split("&").map(x => x.split("="));
3-
let pair = urlParams?.find(x => x[0] === name)
4-
if (pair) {
5-
return unescape(pair[1]);
6-
}
2+
let params = new URLSearchParams(window.location.search.slice(1));
3+
return params.get(name);
74
}
85

96
function createDefaultFilter() {
@@ -29,6 +26,43 @@ function createDefaultFilter() {
2926
};
3027
}
3128

29+
/**
30+
* Loads the initial state of UI filters from URL parameters.
31+
*/
32+
function initializeFilterFromUrl() {
33+
const defaultFilter = createDefaultFilter();
34+
let params = new URLSearchParams(window.location.search.slice(1));
35+
36+
function getBoolOrDefault(name, defaultValue) {
37+
const urlValue = params.get(name);
38+
if (urlValue !== null) {
39+
return urlValue === "true";
40+
}
41+
return defaultValue;
42+
}
43+
44+
return {
45+
name: params.get("name"),
46+
nonRelevant: getBoolOrDefault("nonRelevant", defaultFilter.nonRelevant),
47+
profile: {
48+
check: getBoolOrDefault("check", defaultFilter.profile.check),
49+
debug: getBoolOrDefault("debug", defaultFilter.profile.debug),
50+
opt: getBoolOrDefault("opt", defaultFilter.profile.opt),
51+
doc: getBoolOrDefault("doc", defaultFilter.profile.doc)
52+
},
53+
scenario: {
54+
full: getBoolOrDefault("full", defaultFilter.scenario.full),
55+
incrFull: getBoolOrDefault("incrFull", defaultFilter.scenario.incrFull),
56+
incrUnchanged: getBoolOrDefault("incrUnchanged", defaultFilter.scenario.incrUnchanged),
57+
incrPatched: getBoolOrDefault("incrPatched", defaultFilter.scenario.incrPatched)
58+
},
59+
category: {
60+
primary: getBoolOrDefault("primary", defaultFilter.category.primary),
61+
secondary: getBoolOrDefault("secondary", defaultFilter.category.secondary)
62+
}
63+
};
64+
}
65+
3266
const app = Vue.createApp({
3367
mounted() {
3468
const app = this;
@@ -46,7 +80,7 @@ const app = Vue.createApp({
4680
},
4781
data() {
4882
return {
49-
filter: createDefaultFilter(),
83+
filter: initializeFilterFromUrl(),
5084
showRawData: false,
5185
data: null,
5286
dataLoading: false

0 commit comments

Comments
 (0)