Skip to content

Commit

Permalink
refactor: Use URLSearchParams API for list view filters (frappe#21647)
Browse files Browse the repository at this point in the history
This gives better data structure to manipulate than simple strings.
  • Loading branch information
ankush authored Jul 11, 2023
1 parent f6751bf commit 3de0eb3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions frappe/public/js/frappe/list/list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 3de0eb3

Please sign in to comment.