Skip to content

Commit 0e24d7d

Browse files
committed
add the correct techs to the compare button when loading a page
1 parent 4894095 commit 0e24d7d

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/js/techreport/tableLinked.js

+3-10
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

src/js/techreport/utils/data.js

+10-2
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)