Skip to content

Commit 1a0c542

Browse files
authored
Merge pull request #1593 from Kobzol/compare-page-filters
Fix compare page regression
2 parents 665e70d + 6bf2587 commit 1a0c542

File tree

8 files changed

+192
-90
lines changed

8 files changed

+192
-90
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@ import {withLoading} from "../../utils/loading";
55
import {renderPlots} from "./plots";
66
import {BootstrapData, BootstrapSelector} from "./state";
77
import {BOOTSTRAP_DATA_URL} from "../../urls";
8-
import {createUrlParams, getUrlParams, navigateToUrlParams} from "../../utils/navigation";
8+
import {createUrlWithAppendedParams, getUrlParams, navigateToUrlParams} from "../../utils/navigation";
99
1010
import {postJson} from "../../utils/requests";
1111
1212
async function loadBootstrapData(selector: BootstrapSelector, loading: Ref<boolean>) {
13-
const bootstrapData: BootstrapData = await withLoading(loading, () => postJson<BootstrapData>(BOOTSTRAP_DATA_URL, selector));
13+
const bootstrapData: BootstrapData = await withLoading(loading, () => postJson<BootstrapData>(BOOTSTRAP_DATA_URL, selector));
1414
15-
// Wait for the UI to be updated, which also resets the plot HTML elements.
16-
// Then draw the plots.
17-
await nextTick();
18-
renderPlots(bootstrapData, selector);
15+
// Wait for the UI to be updated, which also resets the plot HTML elements.
16+
// Then draw the plots.
17+
await nextTick();
18+
renderPlots(bootstrapData, selector);
1919
}
2020
2121
function loadSelectorFromUrl(urlParams: Dict<string>): BootstrapSelector {
22-
const start = urlParams["start"] ?? "";
23-
const end = urlParams["end"] ?? "";
24-
return {
25-
start,
26-
end,
27-
min_seconds: 25
28-
};
22+
const start = urlParams["start"] ?? "";
23+
const end = urlParams["end"] ?? "";
24+
return {
25+
start,
26+
end,
27+
min_seconds: 25
28+
};
2929
}
3030
3131
function updateSelection(params: SelectionParams) {
32-
navigateToUrlParams(createUrlParams({
33-
start: params.start,
34-
end: params.end
35-
}));
32+
navigateToUrlParams(createUrlWithAppendedParams({
33+
start: params.start,
34+
end: params.end
35+
}).searchParams);
3636
}
3737
3838
const loading = ref(true);

site/frontend/src/pages/compare/header/filters.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import Toggle from "../toggle.vue";
33
import {DataFilter} from "../types";
44
import Tooltip from "../tooltip.vue";
55
import {ref, toRaw, watch} from "vue";
6+
import {deepCopy} from "../../../utils/copy";
67
7-
const props = defineProps<{defaultFilter: DataFilter}>();
8+
const props = defineProps<{
9+
// When reset, set filter to this value
10+
defaultFilter: DataFilter,
11+
// Initialize the filter with this value
12+
initialFilter: DataFilter
13+
}>();
814
const emit = defineEmits<{
915
(e: "change", filter: DataFilter): void;
1016
(e: "export"): void;
1117
}>();
1218
1319
function reset() {
14-
filter.value = props.defaultFilter;
20+
// We must not change the default filter
21+
filter.value = deepCopy(props.defaultFilter);
1522
}
1623
17-
let filter = ref({...props.defaultFilter});
24+
let filter = ref(deepCopy(props.initialFilter));
1825
watch(filter, (newValue, _) => {
1926
emit("change", toRaw(newValue));
2027
}, {deep: true});

site/frontend/src/pages/compare/header/quick-links.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import {createUrlWithParams, getUrlParams} from "../../../utils/navigation";
2+
import {createUrlWithAppendedParams, getUrlParams} from "../../../utils/navigation";
33
44
const props = defineProps<{stat: string}>();
55
@@ -14,7 +14,7 @@ function createMetric(label: string, stat: string, description: string): {
1414
function createUrlForMetric(stat: string): string {
1515
const params = getUrlParams();
1616
params["stat"] = stat;
17-
return createUrlWithParams(params).toString();
17+
return createUrlWithAppendedParams(params).toString();
1818
}
1919
2020
const metrics = [

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

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<script setup lang="ts">
22
import {loadBenchmarkInfo} from "../../api";
33
import AsOf from "../../components/as-of.vue";
4-
import {createUrlParams, getUrlParams, navigateToUrlParams} from "../../utils/navigation";
4+
import {
5+
createUrlFromParams,
6+
createUrlWithAppendedParams,
7+
getUrlParams,
8+
navigateToUrlParams
9+
} from "../../utils/navigation";
510
import {computed, Ref, ref} from "vue";
611
import {withLoading} from "../../utils/loading";
712
import {postMsgpack} from "../../utils/requests";
@@ -34,6 +39,72 @@ function loadSelectorFromUrl(urlParams: Dict<string>): CompareSelector {
3439
};
3540
}
3641
42+
function loadFilterFromUrl(urlParams: Dict<string>, defaultFilter: DataFilter): DataFilter {
43+
function getBoolOrDefault(name: string, defaultValue: boolean): boolean {
44+
if (urlParams.hasOwnProperty(name)) {
45+
return urlParams[name] === "true";
46+
}
47+
return defaultValue;
48+
}
49+
50+
return {
51+
name: urlParams["name"] ?? defaultFilter.name,
52+
nonRelevant: getBoolOrDefault("nonRelevant", defaultFilter.nonRelevant),
53+
showRawData: getBoolOrDefault("showRawData", defaultFilter.showRawData),
54+
profile: {
55+
check: getBoolOrDefault("check", defaultFilter.profile.check),
56+
debug: getBoolOrDefault("debug", defaultFilter.profile.debug),
57+
opt: getBoolOrDefault("opt", defaultFilter.profile.opt),
58+
doc: getBoolOrDefault("doc", defaultFilter.profile.doc)
59+
},
60+
scenario: {
61+
full: getBoolOrDefault("full", defaultFilter.scenario.full),
62+
incrFull: getBoolOrDefault("incrFull", defaultFilter.scenario.incrFull),
63+
incrUnchanged: getBoolOrDefault("incrUnchanged", defaultFilter.scenario.incrUnchanged),
64+
incrPatched: getBoolOrDefault("incrPatched", defaultFilter.scenario.incrPatched)
65+
},
66+
category: {
67+
primary: getBoolOrDefault("primary", defaultFilter.category.primary),
68+
secondary: getBoolOrDefault("secondary", defaultFilter.category.secondary)
69+
}
70+
};
71+
}
72+
73+
/**
74+
* Stores the given filter parameters into URL, so that the current "view" can be shared with
75+
* others easily.
76+
*/
77+
function storeFilterToUrl(filter: DataFilter, defaultFilter: DataFilter, urlParams: Dict<string>) {
78+
function storeOrReset<T extends boolean | string>(name: string, value: T, defaultValue: T) {
79+
if (value === defaultValue) {
80+
if (urlParams.hasOwnProperty(name)) {
81+
delete urlParams[name];
82+
}
83+
} else {
84+
urlParams[name] = value.toString();
85+
}
86+
}
87+
88+
storeOrReset("name", filter.name || null, defaultFilter.name);
89+
storeOrReset("nonRelevant", filter.nonRelevant, defaultFilter.nonRelevant);
90+
storeOrReset("showRawData", filter.showRawData, defaultFilter.showRawData);
91+
storeOrReset("check", filter.profile.check, defaultFilter.profile.check);
92+
storeOrReset("debug", filter.profile.debug, defaultFilter.profile.debug);
93+
storeOrReset("opt", filter.profile.opt, defaultFilter.profile.opt);
94+
storeOrReset("doc", filter.profile.doc, defaultFilter.profile.doc);
95+
storeOrReset("full", filter.scenario.full, defaultFilter.scenario.full);
96+
storeOrReset("incrFull", filter.scenario.incrFull, defaultFilter.scenario.incrFull);
97+
storeOrReset("incrUnchanged", filter.scenario.incrUnchanged, defaultFilter.scenario.incrUnchanged);
98+
storeOrReset("incrPatched", filter.scenario.incrPatched, defaultFilter.scenario.incrPatched);
99+
storeOrReset("primary", filter.category.primary, defaultFilter.category.primary);
100+
storeOrReset("secondary", filter.category.secondary, defaultFilter.category.secondary);
101+
102+
// Change URL without creating a history entry
103+
if (history.replaceState) {
104+
history.replaceState({}, null, createUrlFromParams(urlParams).toString());
105+
}
106+
}
107+
37108
async function loadCompareData(selector: CompareSelector, loading: Ref<boolean>) {
38109
const response: CompareResponse = await withLoading(loading, async () => {
39110
const params = {
@@ -47,17 +118,24 @@ async function loadCompareData(selector: CompareSelector, loading: Ref<boolean>)
47118
}
48119
49120
function updateSelection(params: SelectionParams) {
50-
navigateToUrlParams(createUrlParams({
121+
navigateToUrlParams(createUrlWithAppendedParams({
51122
start: params.start,
52123
end: params.end,
53124
stat: params.stat
54-
}));
125+
}).searchParams);
126+
}
127+
128+
function updateFilter(newFilter: DataFilter) {
129+
filter.value = newFilter;
130+
storeFilterToUrl(newFilter, defaultFilter, getUrlParams());
55131
}
56132
57133
function exportData() {
58134
exportToMarkdown(testCases.value);
59135
}
60136
137+
const urlParams = getUrlParams();
138+
61139
const defaultFilter: DataFilter = {
62140
name: null,
63141
nonRelevant: false,
@@ -87,8 +165,8 @@ const filteredSummary = computed(() => computeSummary(testCases.value));
87165
const loading = ref(false);
88166
89167
const info = await loadBenchmarkInfo();
90-
const selector = loadSelectorFromUrl(getUrlParams());
91-
const filter = ref({...defaultFilter});
168+
const selector = loadSelectorFromUrl(urlParams);
169+
const filter = ref(loadFilterFromUrl(urlParams, defaultFilter));
92170
93171
const data: Ref<CompareResponse | null> = ref(null);
94172
loadCompareData(selector, loading);
@@ -104,7 +182,9 @@ loadCompareData(selector, loading);
104182
</div>
105183
<div v-if="data !== null">
106184
<QuickLinks :stat="selector.stat" />
107-
<Filters :defaultFilter="defaultFilter" @change="f => filter = f"
185+
<Filters :defaultFilter="defaultFilter"
186+
:initialFilter="filter"
187+
@change="updateFilter"
108188
@export="exportData" />
109189
<OverallTable :summary="filteredSummary" />
110190
<Aggregations :cases="testCases" />

site/frontend/src/pages/detailed-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createUrlWithParams, getUrlParams} from "../utils/navigation";
1+
import {createUrlWithAppendedParams, getUrlParams} from "../utils/navigation";
22
import {postMsgpack} from "../utils/requests";
33
import {SELF_PROFILE_DATA_URL} from "../urls";
44

@@ -158,7 +158,7 @@ function populate_data(data, state: Selector) {
158158
}
159159
}
160160
let inner = th.innerHTML;
161-
th.innerHTML = `<a href="${createUrlWithParams(clickState).toString()}">${inner}</a>`;
161+
th.innerHTML = `<a href="${createUrlWithAppendedParams(clickState).toString()}">${inner}</a>`;
162162
}
163163

164164
if (!state.scenario.includes("incr-")) {

0 commit comments

Comments
 (0)