Fix duplicated tools in tool panel view section copying.

This commit is contained in:
John Chilton
2023-11-15 14:21:38 -05:00
parent edcc043b61
commit 3e4089526e
2 changed files with 29 additions and 4 deletions
+26 -2
View File
@@ -63,14 +63,38 @@ class ToolSection(Dictifiable, HasPanelItems):
self.links = item.get("links") or None
self.elems = ToolPanelElements()
def copy(self):
def copy(self, merge_tools=False):
copy = ToolSection()
copy.name = self.name
copy.id = self.id
copy.version = self.version
copy.description = self.description
copy.links = self.links
copy.elems.update(self.elems)
for key, panel_type, value in self.panel_items_iter():
if panel_type == panel_item_types.TOOL and merge_tools:
tool = value
tool_lineage = tool.lineage
tool_copied = False
if tool_lineage is not None:
version_ids = tool_lineage.get_version_ids(reverse=True)
for version_id in version_ids:
if copy.elems.has_tool_with_id(version_id):
tool_copied = True
break
if self.elems.has_tool_with_id(version_id):
copy.elems.append_tool(self.elems.get_tool_with_id(version_id))
tool_copied = True
break
if not tool_copied:
copy.elems[key] = value
else:
copy.elems[key] = value
return copy
def to_dict(self, trans, link_details=False, tool_help=False, toolbox=None):
+3 -2
View File
@@ -120,7 +120,7 @@ class StaticToolPanelView(ToolPanelView):
f"Failed to find matching section for (id, name) = ({element.section}, {element.section})"
)
continue
section = closest_section.copy()
section = closest_section.copy(merge_tools=True)
apply_filter(element, section.elems)
new_panel.append_section(section.id, section)
elif element.content_type == "label":
@@ -151,7 +151,8 @@ class StaticToolPanelView(ToolPanelView):
if closest_section is None:
log.warning(f"Failed to find matching section for (id, name) = ({element.items_from}, None)")
continue
elems = closest_section.elems.copy()
section = closest_section.copy(merge_tools=True)
elems = section.elems
apply_filter(element, elems)
for key, item in elems.items():
new_panel[key] = item