DEV: Modernise rest adapter query parameter construction (#17925)
Using `URLSearchParams` means that we don't have to manually encode/join strings
This commit is contained in:
parent
b6c6c803c2
commit
a9e9adf253
|
@ -47,20 +47,22 @@ export default EmberObject.extend({
|
||||||
appendQueryParams(path, findArgs, extension) {
|
appendQueryParams(path, findArgs, extension) {
|
||||||
if (findArgs) {
|
if (findArgs) {
|
||||||
if (typeof findArgs === "object") {
|
if (typeof findArgs === "object") {
|
||||||
const queryString = Object.keys(findArgs)
|
const urlSearchParams = new URLSearchParams();
|
||||||
.reject((k) => !findArgs[k])
|
|
||||||
.map((k) => k + "=" + encodeURIComponent(findArgs[k]));
|
|
||||||
|
|
||||||
if (queryString.length) {
|
for (const [key, value] of Object.entries(findArgs)) {
|
||||||
return `${path}${extension ? extension : ""}?${queryString.join(
|
if (value) {
|
||||||
"&"
|
urlSearchParams.set(key, value);
|
||||||
)}`;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryString = urlSearchParams.toString();
|
||||||
|
|
||||||
|
if (queryString) {
|
||||||
|
return `${path}${extension || ""}?${queryString}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// It's serializable as a string if not an object
|
// It's serializable as a string if not an object
|
||||||
return `${path}/${encodeURIComponent(findArgs)}${
|
return `${path}/${encodeURIComponent(findArgs)}${extension || ""}`;
|
||||||
extension ? extension : ""
|
|
||||||
}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
|
|
Loading…
Reference in New Issue