refactor: Use URLSearchParams API for list view filters (#21647)
This gives better data structure to manipulate than simple strings.
This commit is contained in:
parent
f6751bf415
commit
3de0eb3243
1 changed files with 19 additions and 14 deletions
|
|
@ -1544,26 +1544,31 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
}
|
||||
|
||||
get_url_with_filters() {
|
||||
const query_params = this.get_filters_for_args()
|
||||
.map((filter) => {
|
||||
if (filter[2] === "=") {
|
||||
return `${filter[1]}=${encodeURIComponent(filter[3])}`;
|
||||
}
|
||||
return [
|
||||
filter[1],
|
||||
"=",
|
||||
encodeURIComponent(JSON.stringify([filter[2], filter[3]])),
|
||||
].join("");
|
||||
})
|
||||
.join("&");
|
||||
let search_params = this.get_search_params();
|
||||
|
||||
let full_url = window.location.href.replace(window.location.search, "");
|
||||
if (query_params) {
|
||||
full_url += "?" + query_params;
|
||||
if (search_params.size) {
|
||||
full_url += "?" + search_params.toString();
|
||||
}
|
||||
return full_url;
|
||||
}
|
||||
|
||||
get_search_params() {
|
||||
let search_params = new URLSearchParams();
|
||||
|
||||
this.get_filters_for_args().forEach((filter) => {
|
||||
if (filter[2] === "=") {
|
||||
search_params.append(filter[1], encodeURIComponent(filter[3]));
|
||||
} else {
|
||||
search_params.append(
|
||||
filter[1],
|
||||
encodeURIComponent(JSON.stringify([filter[2], filter[3]]))
|
||||
);
|
||||
}
|
||||
});
|
||||
return search_params;
|
||||
}
|
||||
|
||||
get_menu_items() {
|
||||
const doctype = this.doctype;
|
||||
const items = [];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue