From c90374c286e29758c399f33be9d1576f88b1d06c Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 20 Jul 2023 16:38:26 +0530 Subject: [PATCH] perf: Lazily compute common workflow transitions --- frappe/public/js/frappe/list/list_view.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/list/list_view.js b/frappe/public/js/frappe/list/list_view.js index 4facb9893b..dcca1e9784 100644 --- a/frappe/public/js/frappe/list/list_view.js +++ b/frappe/public/js/frappe/list/list_view.js @@ -545,7 +545,6 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { if (toggle) { this.page.show_actions_menu(); this.page.clear_primary_action(); - this.toggle_workflow_actions(); } else { this.page.hide_actions_menu(); this.set_primary_action(); @@ -1313,6 +1312,11 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { this.update_checkbox($target); }); + + let me = this; + this.page.actions_btn_group.on("show.bs.dropdown", () => { + me.toggle_workflow_actions(); + }); } setup_like() { @@ -1697,7 +1701,12 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { toggle_workflow_actions() { if (!frappe.model.has_workflow(this.doctype)) return; + + Object.keys(this.workflow_action_items).forEach((key) => { + this.workflow_action_items[key].addClass("disabled"); + }); const checked_items = this.get_checked_items(); + frappe .xcall("frappe.model.workflow.get_common_transition_actions", { docs: checked_items, @@ -1705,6 +1714,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { }) .then((actions) => { Object.keys(this.workflow_action_items).forEach((key) => { + this.workflow_action_items[key].removeClass("disabled"); this.workflow_action_items[key].toggle(actions.includes(key)); }); });