Merge pull request #35810 from KerollesFathy/show-current-saved-selected-filter

refactor: show current selected saved filter
This commit is contained in:
Saqib Ansari 2026-01-12 12:49:06 +05:30 committed by GitHub
commit c8fb8f2724
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ export default class ListFilter {
Object.assign(this, arguments[0]); Object.assign(this, arguments[0]);
this.can_add_global = frappe.user.has_role(["System Manager", "Administrator"]); this.can_add_global = frappe.user.has_role(["System Manager", "Administrator"]);
this.filters = []; this.filters = [];
this.active_filter = null;
this.refresh_list_filter(); this.refresh_list_filter();
} }
@ -19,6 +20,13 @@ export default class ListFilter {
[], [],
__("Saved Filters") __("Saved Filters")
); );
// Clear active filter on clicking 'x' button
const filter_x_btn = $(".filter-x-button");
filter_x_btn.on("click", () => {
this.active_filter = null;
this.update_active_filter_label("Saved Filters");
});
} }
render_saved_filters() { render_saved_filters() {
@ -30,7 +38,7 @@ export default class ListFilter {
// Apply filter // Apply filter
$item.find(".filter-label").on("click", () => { $item.find(".filter-label").on("click", () => {
this.apply_saved_filter(filter.name); this.apply_saved_filter(filter.name, filter.filter_name);
}); });
// Remove filter // Remove filter
@ -46,12 +54,20 @@ export default class ListFilter {
this.append_create_new_item($menu); this.append_create_new_item($menu);
} }
apply_saved_filter(filter_name) { apply_saved_filter(filter_name, filter_label) {
this.list_view.filter_area.clear().then(() => { this.list_view.filter_area.clear().then(() => {
this.list_view.filter_area.add(this.get_filters_values(filter_name)); this.list_view.filter_area.add(this.get_filters_values(filter_name));
this.active_filter = filter_label;
this.update_active_filter_label(this.active_filter);
}); });
} }
update_active_filter_label(label) {
$(`.inner-group-button[data-label="${encodeURIComponent("Saved Filters")}"] button`)
.contents()
.first()[0].textContent = label;
}
bind_remove_filter(filter) { bind_remove_filter(filter) {
frappe.confirm( frappe.confirm(
__("Are you sure you want to remove the {0} filter?", [filter.filter_name.bold()]), __("Are you sure you want to remove the {0} filter?", [filter.filter_name.bold()]),
@ -59,6 +75,7 @@ export default class ListFilter {
const name = filter.name; const name = filter.name;
const applied_filters = this.get_filters_values(name); const applied_filters = this.get_filters_values(name);
this.remove_filter(name).then(() => this.refresh_list_filter()); this.remove_filter(name).then(() => this.refresh_list_filter());
this.update_active_filter_label("Saved Filters");
this.list_view.filter_area.remove_filters(applied_filters); this.list_view.filter_area.remove_filters(applied_filters);
} }
); );