DEV: Modernise discovery controller query parameter construction (#17927)

Using `URLSearchParams` means that we don't have to manually encode/join strings
This commit is contained in:
David Taylor 2022-08-15 17:20:44 +01:00 committed by GitHub
parent 3a37a7f6b4
commit 55f34c45c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -45,17 +45,19 @@ export default Controller.extend({
url += "/top";
let queryParams = this.router.currentRoute.queryParams;
queryParams.period = period;
if (Object.keys(queryParams).length) {
url =
`${url}?` +
Object.keys(queryParams)
.map((key) => `${key}=${queryParams[key]}`)
.join("&");
const urlSearchParams = new URLSearchParams();
for (const [key, value] of Object.entries(
this.router.currentRoute.queryParams
)) {
if (typeof value !== "undefined") {
urlSearchParams.set(key, value);
}
}
return url;
urlSearchParams.set("period", period);
return `${url}?${urlSearchParams.toString()}`;
},
actions: {