diff --git a/frappe/public/js/frappe/ui/sidebar/sidebar_editor.js b/frappe/public/js/frappe/ui/sidebar/sidebar_editor.js index 56c1ffc27c..777fe07bf0 100644 --- a/frappe/public/js/frappe/ui/sidebar/sidebar_editor.js +++ b/frappe/public/js/frappe/ui/sidebar/sidebar_editor.js @@ -141,15 +141,15 @@ export class SidebarEditor { me.sorting = true; }, onEnd: function (event) { + if (event.from !== event.to) return; // onAdd handles this case + if (me.new_sidebar_items.length == 0) { me.new_sidebar_items = Array.from(me.workspace_sidebar_items); } let old_index = event.oldIndex; let new_index = event.newIndex; - me.new_sidebar_items[old_index]; - let b = me.new_sidebar_items[old_index]; - me.new_sidebar_items[old_index] = me.new_sidebar_items[new_index]; - me.new_sidebar_items[new_index] = b; + let [item] = me.new_sidebar_items.splice(old_index, 1); + me.new_sidebar_items.splice(new_index, 0, item); }, }); @@ -198,21 +198,16 @@ export class SidebarEditor { ); }, onEnd: function (event) { + if (event.from !== event.to) return; // onAdd handles this case + let new_index = event.newIndex; let old_index = event.oldIndex; - let item_label = $(event.item).data("id"); - me.new_sidebar_items.forEach((item) => { - if (item.nested_items.length) { - let child = item.nested_items.find( - (child) => child.label === item_label - ); - if (child) { - let b = item.nested_items[old_index]; - item.nested_items[old_index] = item.nested_items[new_index]; - item.nested_items[new_index] = b; - } - } - }); + let section_name = $(event.to).parent().attr("item-name"); + let section_data = me.get_item_data(section_name); + if (section_data && section_data.nested_items) { + let [item] = section_data.nested_items.splice(old_index, 1); + section_data.nested_items.splice(new_index, 0, item); + } }, }); });