Skip to content

Commit

Permalink
Merge pull request galaxyproject#17634 from ahmedhamidawan/fix_tool_p…
Browse files Browse the repository at this point in the history
…anel_workflow_bugs

[23.2] Fix tool panel workflow and favorites button bugs
  • Loading branch information
mvdbeek authored Mar 11, 2024
2 parents 71741fc + d57341e commit 8697be0
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 68 deletions.
114 changes: 59 additions & 55 deletions client/src/components/Panels/Buttons/FavoritesButton.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
<script setup lang="ts">
import { library } from "@fortawesome/fontawesome-svg-core";
import { faStar } from "@fortawesome/free-regular-svg-icons";
import { faStar as faRegStar } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BButton } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, ref, watch } from "vue";
import { useUserStore } from "@/stores/userStore";
library.add(faStar, faRegStar);
interface Props {
query: string;
}
const props = defineProps<Props>();
const emit = defineEmits<{
(e: "onFavorites", filter: string): void;
}>();
const { isAnonymous } = storeToRefs(useUserStore());
const FAVORITES = ["#favorites", "#favs", "#favourites"];
const toggle = ref(false);
const tooltipText = computed(() => {
if (isAnonymous.value) {
return "Log in to Favorite Tools";
} else {
if (toggle.value) {
return "Clear";
} else {
return "Show favorites";
}
}
});
watch(
() => props.query,
() => {
toggle.value = FAVORITES.includes(props.query);
}
);
function onFavorites() {
toggle.value = !toggle.value;
if (toggle.value) {
emit("onFavorites", "#favorites");
} else {
emit("onFavorites", "");
}
}
</script>

<template>
<b-button
<BButton
v-b-tooltip.hover.top.noninteractive
class="panel-header-button-toolbox"
size="sm"
Expand All @@ -8,58 +64,6 @@
:disabled="isAnonymous"
:title="tooltipText"
@click="onFavorites">
<icon v-if="toggle" :icon="['fas', 'star']" />
<icon v-else :icon="['far', 'star']" />
</b-button>
<FontAwesomeIcon :icon="toggle ? faRegStar : faStar" />
</BButton>
</template>

<script>
import { mapState } from "pinia";
import { useUserStore } from "@/stores/userStore";
export default {
name: "FavoritesButton",
props: {
query: {
type: String,
required: true,
},
},
data() {
return {
searchKey: "#favorites",
toggle: false,
};
},
computed: {
...mapState(useUserStore, ["isAnonymous"]),
tooltipText() {
if (this.isAnonymous) {
return this.l("Log in to Favorite Tools");
} else {
if (this.toggle) {
return this.l("Clear");
} else {
return this.l("Show favorites");
}
}
},
},
watch: {
query() {
this.toggle = this.query == this.searchKey;
},
},
methods: {
onFavorites() {
this.toggle = !this.toggle;
if (this.toggle) {
this.$emit("onFavorites", this.searchKey);
} else {
this.$emit("onFavorites", "");
}
},
},
};
</script>
19 changes: 14 additions & 5 deletions client/src/components/Panels/Common/ToolSearch.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script setup lang="ts">
import { computed, type ComputedRef, onMounted, onUnmounted, type PropType, type Ref, ref } from "vue";
import { storeToRefs } from "pinia";
import { computed, type ComputedRef, onMounted, onUnmounted, type PropType, type Ref, ref, watch } from "vue";
import { useRouter } from "vue-router/composables";
import { getGalaxyInstance } from "@/app";
import { type Tool, type ToolSection, useToolStore } from "@/stores/toolStore";
import { useUserStore } from "@/stores/userStore";
import Filtering, { contains, type ValidFilter } from "@/utils/filtering";
import _l from "@/utils/localization";
Expand Down Expand Up @@ -109,6 +110,7 @@ const validFilters: ComputedRef<Record<string, ValidFilter<string>>> = computed(
});
const ToolFilters: ComputedRef<Filtering<string>> = computed(() => new Filtering(validFilters.value));
const { currentFavorites } = storeToRefs(useUserStore());
const toolStore = useToolStore();
const sectionNames = toolStore.sectionDatalist("default").map((option: { value: string; text: string }) => option.text);
Expand All @@ -118,8 +120,6 @@ const ontologyList = toolStore
onMounted(() => {
searchWorker.value = new Worker(new URL("../toolSearch.worker.js", import.meta.url));
const Galaxy = getGalaxyInstance();
const favoritesResults = Galaxy?.user.getFavorites().tools;
searchWorker.value.onmessage = ({ data }) => {
const { type, payload, sectioned, query, closestTerm } = data;
Expand All @@ -128,7 +128,7 @@ onMounted(() => {
} else if (type === "clearFilterResult") {
emit("onResults", null, null, null);
} else if (type === "favoriteToolsResult") {
emit("onResults", favoritesResults, null, null);
emit("onResults", currentFavorites.value.tools, null, null);
}
};
});
Expand All @@ -137,6 +137,15 @@ onUnmounted(() => {
searchWorker.value?.terminate();
});
watch(
() => currentFavorites.value.tools,
() => {
if (FAVORITES.includes(props.query)) {
post({ type: "favoriteTools" });
}
}
);
function checkQuery(q: string) {
emit("onQuery", q);
if (q && q.length >= MIN_QUERY_LENGTH) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Panels/ToolBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function setButtonText() {
@onQuery="(q) => (query = q)"
@onResults="onResults" />
<section v-if="!propShowAdvanced">
<UploadButton />
<UploadButton v-if="!props.workflow" />
<div v-if="hasResults && resultPanel" class="pb-2">
<b-button size="sm" class="w-100" @click="onToggle">
<FontAwesomeIcon :icon="buttonIcon" />
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Panels/ToolPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const emit = defineEmits<{
const arePanelsFetched = ref(false);
const toolStore = useToolStore();
const { currentPanelView, defaultPanelView, isPanelPopulated, loading, panelViews } = storeToRefs(toolStore);
const { currentPanelView, defaultPanelView, isPanelPopulated, loading, panel, panelViews } = storeToRefs(toolStore);
const loadingView = ref<string | undefined>(undefined);
const query = ref("");
Expand Down Expand Up @@ -62,7 +62,7 @@ watch(
watch(
() => currentPanelView.value,
async (newVal) => {
if (!newVal && arePanelsFetched.value) {
if ((!newVal || !panel.value[newVal]) && arePanelsFetched.value) {
await initializeTools();
}
}
Expand Down
5 changes: 2 additions & 3 deletions client/src/components/ToolsList/ToolsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ const filterSettings = computed(() => {
return newFilterSettings;
});
const itemsLoaded: Ref<Tool[]> = ref([]);
onMounted(async () => {
await toolStore.fetchTools(filterSettings.value);
itemsLoaded.value = Object.values(toolStore.getToolsById(filterSettings.value));
});
const filterCount = computed(() => Object.keys(filterSettings.value).length);
const itemsLoaded = computed<Tool[]>(() => Object.values(toolStore.getToolsById(filterSettings.value)));
function scrollToTop() {
scrollContainer.value?.scrollTo({ top: 0, behavior: "smooth" });
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ToolsList/ToolsListTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default {
}
},
async fetchHelp(tool) {
await fetchData(`api/tools/${tool.id}/build`).then((response) => {
await fetchData(`api/tools/${encodeURIComponent(tool.id)}/build`).then((response) => {
const help = response.help;
Vue.set(tool, "_showDetails", false); // maybe not needed
if (help && help != "\n") {
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def set_beacon(
return payload

@router.delete(
"/api/users/{user_id}/favorites/{object_type}/{object_id}",
"/api/users/{user_id}/favorites/{object_type}/{object_id:path}",
name="remove_favorite",
summary="Remove the object from user's favorites",
)
Expand Down

0 comments on commit 8697be0

Please sign in to comment.