Skip to content

Commit

Permalink
remove panel_labels from api/tools return's section.tools
Browse files Browse the repository at this point in the history
improve typing
  • Loading branch information
ahmedhamidawan committed Sep 28, 2023
1 parent 04a3701 commit 840b6b0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
8 changes: 3 additions & 5 deletions client/src/components/Panels/Common/ToolSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { computed, onMounted, onUnmounted, ref, watch } from "vue";
import { eventHub } from "@/components/plugins/eventHub.js";
import { useConfig } from "@/composables/config";
import { ToolSectionLabel } from "@/stores/toolStore";
import { useToolStore } from "@/stores/toolStore";
import { type ToolSectionLabel, useToolStore } from "@/stores/toolStore";
import ariaAlert from "@/utils/ariaAlert";
import Tool from "./Tool.vue";
Expand Down Expand Up @@ -67,9 +66,8 @@ const elems = computed(() => {
if (props.category.tools !== undefined && props.category.tools.length > 0) {
return props.category.tools.map((toolId: string) => {
const tool = toolStore.getToolForId(toolId);
if (!tool && toolId.startsWith("panel_label_") && props.category.panel_labels) {
const labelId = toolId.split("panel_label_")[1];
return props.category.panel_labels.find((label: ToolSectionLabel) => label.id === labelId);
if (!tool && typeof toolId !== "string") {
return toolId as ToolSectionLabel;
} else {
return tool;
}
Expand Down
4 changes: 1 addition & 3 deletions client/src/components/Panels/ToolBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ const query = computed({
});
const { currentPanel } = storeToRefs(toolStore);
// const localPanelView = computed(() => (props.setDefault ? props.panelView.value : props.panelView));
const hasResults = computed(() => results.value.length > 0);
// const panelLoaded = computed(() => !!props.panelView && toolStore.panel[props.panelView] !== undefined);
const queryTooShort = computed(() => query.value && query.value.length < 3);
const queryFinished = computed(() => query.value && queryPending.value != true);
Expand Down Expand Up @@ -237,7 +235,7 @@ function setButtonText() {
</script>

<template>
<div class="unified-panel">
<div class="unified-panel" data-description="panel toolbox">
<div class="unified-panel-controls">
<ToolSearch
:enable-advanced="!props.workflow"
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/Panels/ToolPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ watchEffect(async () => {
}
});
function updatePanelView(panelView: string) {
toolStore.setCurrentPanelView(panelView);
async function updatePanelView(panelView: string) {
await toolStore.setCurrentPanelView(panelView);
}
function onInsertTool(toolId: string, toolName: string) {
Expand All @@ -75,8 +75,8 @@ function onInsertWorkflowSteps(workflowId: string, workflowStepCount: number | u
</script>

<template>
<div class="unified-panel" aria-labelledby="toolbox-heading">
<div v-if="isConfigLoaded" unselectable="on">
<div v-if="isConfigLoaded" class="unified-panel" aria-labelledby="toolbox-heading">
<div unselectable="on">
<div class="unified-panel-header-inner">
<nav class="d-flex justify-content-between mx-3 my-2">
<Heading v-if="!showAdvanced" id="toolbox-heading" h2 inline size="sm">{{
Expand Down
29 changes: 15 additions & 14 deletions client/src/components/Panels/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ export function createWhooshQuery(filterSettings: ToolFilters) {
}
query += ") AND (";
for (const [key, filterValue] of Object.entries(filterSettings)) {
if (key === "ontology" && filterValue.includes("operation")) {
query += "edam_operations:(" + filterValue + ") AND ";
} else if (key === "ontology" && filterValue.includes("topic")) {
query += "edam_topics:(" + filterValue + ") AND ";
} else if (key == "id") {
query += "id_exact:(" + filterValue + ") AND ";
} else if (key != "name") {
query += key + ":(" + filterValue + ") AND ";
if (filterValue) {
if (key === "ontology" && filterValue.includes("operation")) {
query += "edam_operations:(" + filterValue + ") AND ";
} else if (key === "ontology" && filterValue.includes("topic")) {
query += "edam_topics:(" + filterValue + ") AND ";
} else if (key == "id") {
query += "id_exact:(" + filterValue + ") AND ";
} else if (key != "name") {
query += key + ":(" + filterValue + ") AND ";
}
}
}
query += ")";
Expand Down Expand Up @@ -167,14 +169,13 @@ export function getValidToolsInEachSection(
return Object.entries(currentPanel).map(([id, section]) => {
const validatedSection = { ...section } as ToolSection;
if (validatedSection.tools && Array.isArray(validatedSection.tools)) {
// filter on valid tools and panel_labels in this section
// filter on valid tools and panel labels in this section
validatedSection.tools = validatedSection.tools.filter((toolId) => {
if (validToolIdsInCurrentView.includes(toolId)) {
if (typeof toolId === "string" && validToolIdsInCurrentView.includes(toolId)) {
return true;
} else if (typeof toolId !== "string") {
// is a special case where there is a label within a section
return true;
} else if (toolId.startsWith("panel_label_") && validatedSection.panel_labels) {
// panel_label_ is a special id where there is a label within a section
const labelId = toolId.split("panel_label_")[1];
return validatedSection.panel_labels.find((label) => label.id === labelId) !== undefined;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ToolsList/ToolsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const filterSettings = computed(() => {
const newFilterSettings: FilterSettings = {};
Object.entries(props).forEach(([filter, value]) => {
if (value && value !== "") {
newFilterSettings[filter] = value;
newFilterSettings[filter] = value as string;
}
});
return newFilterSettings;
Expand Down
5 changes: 2 additions & 3 deletions client/src/stores/toolStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export interface ToolSection {
version?: string;
description?: string;
links?: Record<string, string>;
tools?: string[];
tools?: (string | ToolSectionLabel)[];
elems?: (Tool | ToolSection)[];
panel_labels?: any[];
}

export interface ToolSectionLabel {
Expand All @@ -54,7 +53,7 @@ export interface ToolSectionLabel {
}

export interface FilterSettings {
[key: string]: any;
[key: string]: string | undefined;
name?: string;
section?: string;
ontology?: string;
Expand Down
15 changes: 4 additions & 11 deletions lib/galaxy/tool_util/toolbox/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,27 @@ def to_dict(self, trans, link_details=False, tool_help=False, toolbox=None, only
"""Return a dict that includes section's attributes.
if `only_ids` is `True`, we store only the ids of the section's tools in `section.tools`
(and full `ToolSectionLabel` objects in `section.panel_labels` if any are present)
(also full `ToolSectionLabel` objects in `section.tools` if any are present)
if `only_ids` is `False`, we store the section's full `Tool` (and any other) objects in
`section.elems`
"""

section_dict = super().to_dict()
section_elts = []
section_panel_labels = []
kwargs = dict(trans=trans, link_details=link_details, tool_help=tool_help)
for elt in self.elems.values():
if hasattr(elt, "tool_type") and toolbox:
if only_ids:
section_elts.append(elt.id)
else:
section_elts.append(toolbox.get_tool_to_dict(trans, elt, tool_help=tool_help))
else:
# if section has a ToolSectionLabel within it
if only_ids and elt.text:
section_panel_labels.append(elt.to_dict(**kwargs))
section_elts.append("panel_label_" + str(elt.id))
else:
section_elts.append(elt.to_dict(**kwargs))
elif not only_ids or (only_ids and elt.text):
# if !only_ids or (only_ids & section has a ToolSectionLabel within it)
section_elts.append(elt.to_dict(**kwargs))

if only_ids:
section_dict["tools"] = section_elts
if section_panel_labels:
section_dict["panel_labels"] = section_panel_labels
else:
section_dict["elems"] = section_elts

Expand Down

0 comments on commit 840b6b0

Please sign in to comment.