Skip to content

Commit 7457717

Browse files
Bugfix: Add the correct techs to the compare button when loading a page (#1025)
* add the correct techs to the compare button when loading a page * make comma usage consistent
1 parent 7cdff0a commit 7457717

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/js/components/filters.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class Filters {
7373
// url.hash = '#report-content';
7474

7575
/* Update the url */
76-
location.href = url;
76+
const styledUrl = url.href.replaceAll('%2C', ',');
77+
location.href = styledUrl;
7778
}
7879

7980
/* Update the list of technologies */

src/js/techreport/tableLinked.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class TableLinked {
99
this.submetric = ''; // TODO: Fetch the default one from somewhere
1010
this.data = data;
1111
this.dataArray = [];
12-
this.selectedTechs = this.getTechsFromURL()?.split(',') || [];
12+
this.selectedTechs = DataUtils.getTechsFromURL()?.split(',') || [];
1313
this.rows = filters.rows || 10;
1414

1515
this.updateContent();
16-
this.updateSelectionText(this.getTechsFromURL());
16+
this.updateSelectionText(DataUtils.getTechsFromURL());
1717

1818
const rowCount = document.getElementById('rowsPerPage');
1919
rowCount?.addEventListener('change', (e) => this.updateRowsPerPage(e));
@@ -35,8 +35,6 @@ class TableLinked {
3535

3636
this.dataArray = this.dataArray.filter(row => row.length > 0);
3737

38-
console.log('set content', content, this.dataArray);
39-
4038
const isContent = content?.length > 0 || this.dataArray?.length > 0;
4139

4240
if(tbody && isContent) {
@@ -159,11 +157,6 @@ class TableLinked {
159157
}
160158
}
161159

162-
getTechsFromURL() {
163-
const url = new URL(window.location);
164-
return url.searchParams.get('selected') || null;
165-
}
166-
167160
addColumnCheckbox(app) {
168161
const cell = document.createElement('td');
169162
const formattedApp = DataUtils.formatAppName(app);
@@ -192,7 +185,7 @@ class TableLinked {
192185

193186
// Set selected content
194187
isTechSelected(app) {
195-
const urlSelected = this.getTechsFromURL();
188+
const urlSelected = DataUtils.getTechsFromURL();
196189
return urlSelected?.includes(app) || false;
197190
}
198191

@@ -243,7 +236,8 @@ class TableLinked {
243236
updateURL(param, value) {
244237
const url = new URL(window.location);
245238
url.searchParams.set(param, value);
246-
window.history.replaceState(null, null, url);
239+
const styledUrl = url.href.replaceAll('%2C', ',');
240+
window.history.replaceState(null, null, styledUrl);
247241
}
248242

249243
updateSelectionText(allSelectedApps) {

src/js/techreport/utils/data.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ const fetchCategoryData = (rows, filters, callback) => {
139139
const lastTechNr = pageNr * rows;
140140
const paginatedTechs = category?.technologies?.slice(firstTechNr, lastTechNr);
141141

142-
const technologyFormatted = encodeURI(paginatedTechs?.join('%2C'));
142+
const techsFromUrl = getTechsFromURL();
143+
const technologyFormatted = paginatedTechs?.join(',');
144+
const technologyUrl = encodeURI(techsFromUrl || technologyFormatted);
143145

144146
const compare = document.querySelector('[data-name="selected-apps"]');
145-
compare.setAttribute('href', `/reports/techreport/tech?tech=${technologyFormatted}`);
147+
compare.setAttribute('href', `/reports/techreport/tech?tech=${technologyUrl}`);
146148

147149
let allResults = {};
148150
paginatedTechs.forEach(tech => allResults[tech] = []);
@@ -194,6 +196,11 @@ const fetchCategoryData = (rows, filters, callback) => {
194196
});
195197
}
196198

199+
const getTechsFromURL = () => {
200+
const url = new URL(window.location);
201+
return url.searchParams.get('selected') || null;
202+
}
203+
197204
export const DataUtils = {
198205
parseVitalsData,
199206
parseLighthouseData,
@@ -203,4 +210,5 @@ export const DataUtils = {
203210
getLighthouseScoreCategories,
204211
formatAppName,
205212
fetchCategoryData,
213+
getTechsFromURL,
206214
};

0 commit comments

Comments
 (0)