1
1
<script setup lang="ts">
2
2
import {loadBenchmarkInfo } from " ../../api" ;
3
3
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" ;
5
10
import {computed , Ref , ref } from " vue" ;
6
11
import {withLoading } from " ../../utils/loading" ;
7
12
import {postMsgpack } from " ../../utils/requests" ;
@@ -34,6 +39,72 @@ function loadSelectorFromUrl(urlParams: Dict<string>): CompareSelector {
34
39
};
35
40
}
36
41
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
+
37
108
async function loadCompareData(selector : CompareSelector , loading : Ref <boolean >) {
38
109
const response: CompareResponse = await withLoading (loading , async () => {
39
110
const params = {
@@ -47,17 +118,24 @@ async function loadCompareData(selector: CompareSelector, loading: Ref<boolean>)
47
118
}
48
119
49
120
function updateSelection(params : SelectionParams ) {
50
- navigateToUrlParams (createUrlParams ({
121
+ navigateToUrlParams (createUrlWithAppendedParams ({
51
122
start: params .start ,
52
123
end: params .end ,
53
124
stat: params .stat
54
- }));
125
+ }).searchParams );
126
+ }
127
+
128
+ function updateFilter(newFilter : DataFilter ) {
129
+ filter .value = newFilter ;
130
+ storeFilterToUrl (newFilter , defaultFilter , getUrlParams ());
55
131
}
56
132
57
133
function exportData() {
58
134
exportToMarkdown (testCases .value );
59
135
}
60
136
137
+ const urlParams = getUrlParams ();
138
+
61
139
const defaultFilter: DataFilter = {
62
140
name: null ,
63
141
nonRelevant: false ,
@@ -87,8 +165,8 @@ const filteredSummary = computed(() => computeSummary(testCases.value));
87
165
const loading = ref (false );
88
166
89
167
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 ) );
92
170
93
171
const data: Ref <CompareResponse | null > = ref (null );
94
172
loadCompareData (selector , loading );
@@ -104,7 +182,9 @@ loadCompareData(selector, loading);
104
182
</div >
105
183
<div v-if =" data !== null" >
106
184
<QuickLinks :stat =" selector.stat" />
107
- <Filters :defaultFilter =" defaultFilter" @change =" f => filter = f"
185
+ <Filters :defaultFilter =" defaultFilter"
186
+ :initialFilter =" filter"
187
+ @change =" updateFilter"
108
188
@export =" exportData" />
109
189
<OverallTable :summary =" filteredSummary" />
110
190
<Aggregations :cases =" testCases" />
0 commit comments