Skip to content

Commit

Permalink
Fix duplicated tools in tool panel view section copying.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Nov 15, 2023
1 parent edcc043 commit 3e40895
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
28 changes: 26 additions & 2 deletions lib/galaxy/tool_util/toolbox/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,38 @@ def __init__(self, item=None):
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):
Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy/tool_util/toolbox/views/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def definition_with_items_to_panel(definition, allow_sections: bool = True, item
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":
Expand Down Expand Up @@ -151,7 +151,8 @@ def definition_with_items_to_panel(definition, allow_sections: bool = True, item
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
Expand Down

0 comments on commit 3e40895

Please sign in to comment.