From 3de0eb324386cfe8cd749e1380bc33b8a366b9f1 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 11 Jul 2023 20:12:20 +0530 Subject: [PATCH] refactor: Use URLSearchParams API for list view filters (#21647) This gives better data structure to manipulate than simple strings. --- frappe/public/js/frappe/list/list_view.js | 33 +++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/frappe/public/js/frappe/list/list_view.js b/frappe/public/js/frappe/list/list_view.js index 10f933aecdc..ba512af2a13 100644 --- a/frappe/public/js/frappe/list/list_view.js +++ b/frappe/public/js/frappe/list/list_view.js @@ -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 = [];