Skip to content

Commit

Permalink
change api/tool_panels from dict of views to dict containing
Browse files Browse the repository at this point in the history
`default_panel_view` and `views` dict

use this api instead of waiting for `isConfigLoaded` in `ToolPanel`
  • Loading branch information
ahmedhamidawan committed Oct 26, 2023
1 parent 48ad326 commit 34b0296
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
49 changes: 28 additions & 21 deletions client/src/components/Panels/ToolPanel.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script setup lang="ts">
import axios from "axios";
import { storeToRefs } from "pinia";
import { ref, watch } from "vue";
import { onMounted, ref, watch } from "vue";
import { useConfig } from "@/composables/config";
import { getAppRoot } from "@/onload";
import { useToolStore } from "@/stores/toolStore";
import localize from "@/utils/localization";
Expand All @@ -26,49 +27,55 @@ const emit = defineEmits<{
(e: "onInsertWorkflowSteps", workflowId: string, workflowStepCount: number | undefined): void;
}>();
const { isConfigLoaded, config } = useConfig();
const arePanelsFetched = ref(false);
const defaultPanelView = ref("");
const toolStore = useToolStore();
const { currentPanelView, isPanelPopulated } = storeToRefs(toolStore);
const query = ref("");
const panelViews = ref(null);
const showAdvanced = ref(false);
onMounted(async () => {
await axios
.get(`${getAppRoot()}api/tool_panels`)
.then(async ({ data }) => {
const { default_panel_view, views } = data;
defaultPanelView.value = default_panel_view;
panelViews.value = views;
await initializeTools();
})
.catch((error) => {
console.error(error);
})
.finally(() => {
arePanelsFetched.value = true;
});
});
watch(
() => currentPanelView.value,
() => {
query.value = "";
}
);
// as soon as config is loaded, load tools
watch(
() => isConfigLoaded.value,
async (newVal) => {
if (newVal) {
await loadTools();
}
},
{ immediate: true }
);
// if currentPanelView ever becomes null || "", load tools
watch(
() => currentPanelView.value,
async (newVal) => {
if (!newVal && isConfigLoaded.value) {
await loadTools();
if (!newVal && arePanelsFetched.value) {
await initializeTools();
}
}
);
async function loadTools() {
panelViews.value = panelViews.value === null ? config.value.panel_views : panelViews.value;
async function initializeTools() {
try {
await toolStore.fetchTools();
await toolStore.initCurrentPanelView(config.value.default_panel_view);
await toolStore.initCurrentPanelView(defaultPanelView.value);
} catch (error: any) {
console.error("ToolPanel - Load tools error:", error);
console.error("ToolPanel - Intialize error:", error);
}
}
Expand All @@ -94,7 +101,7 @@ function onInsertWorkflowSteps(workflowId: string, workflowStepCount: number | u
</script>

<template>
<div v-if="isConfigLoaded" class="unified-panel" aria-labelledby="toolbox-heading">
<div v-if="arePanelsFetched" 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">
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/webapps/galaxy/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ def index(self, trans: GalaxyWebTransaction, **kwds):
def panel_views(self, trans: GalaxyWebTransaction, **kwds):
"""
GET /api/tool_panels
returns a dictionary of available tool panel views
returns a dictionary of available tool panel views and default view
"""

return self.app.toolbox.panel_view_dicts()
rval = {}
rval["default_panel_view"] = self.app.toolbox._default_panel_view
rval["views"] = self.app.toolbox.panel_view_dicts()
return rval

@expose_api_anonymous_and_sessionless
def panel_view(self, trans: GalaxyWebTransaction, view, **kwds):
Expand Down
11 changes: 7 additions & 4 deletions test/integration/test_edam_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_edam_toolbox(self):

tool_panels = self.galaxy_interactor.get("tool_panels")
tool_panels.raise_for_status()
panel_views = tool_panels.json()
panel_views = tool_panels.json()["views"]
assert len(panel_views) > 1
assert isinstance(panel_views, dict)
edam_panel_view = panel_views["ontology:edam_merged"]
Expand Down Expand Up @@ -54,7 +54,10 @@ def test_edam_toolbox(self):
tool_panels = self.galaxy_interactor.get("tool_panels")
tool_panels.raise_for_status()
panel_views = tool_panels.json()
assert len(panel_views) > 1
assert isinstance(panel_views, dict)
edam_panel_view = panel_views["ontology:edam_topics"]
default = panel_views["default_panel_view"]
assert default == "ontology:edam_topics"
views = panel_views["views"]
assert len(views) > 1
assert isinstance(views, dict)
edam_panel_view = views["ontology:edam_topics"]
assert edam_panel_view["view_type"] == "ontology"

0 comments on commit 34b0296

Please sign in to comment.