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:
parent
3a37a7f6b4
commit
55f34c45c6
|
@ -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: {
|
||||
|
|
Loading…
Reference in New Issue