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"; url += "/top";
let queryParams = this.router.currentRoute.queryParams; const urlSearchParams = new URLSearchParams();
queryParams.period = period;
if (Object.keys(queryParams).length) { for (const [key, value] of Object.entries(
url = this.router.currentRoute.queryParams
`${url}?` + )) {
Object.keys(queryParams) if (typeof value !== "undefined") {
.map((key) => `${key}=${queryParams[key]}`) urlSearchParams.set(key, value);
.join("&"); }
} }
return url; urlSearchParams.set("period", period);
return `${url}?${urlSearchParams.toString()}`;
}, },
actions: { actions: {