Skip to content

Commit

Permalink
Merge pull request galaxyproject#17037 from dannon/no-more-eventhub
Browse files Browse the repository at this point in the history
Remove eventHub custom module, swap to appropriate alternatives.
  • Loading branch information
mvdbeek authored Nov 16, 2023
2 parents 43c5573 + d59c554 commit e340737
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 137 deletions.
26 changes: 5 additions & 21 deletions client/src/components/ActivityBar/Items/UploadItem.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { onMounted, onUnmounted, type Ref, ref } from "vue";
import { storeToRefs } from "pinia";
import { onMounted } from "vue";
import { eventHub } from "@/components/plugins/eventHub.js";
import { useGlobalUploadModal } from "@/composables/globalUploadModal.js";
import { useUploadStore } from "@/stores/uploadStore";
import Query from "@/utils/query-string-parsing.js";
import ActivityItem from "components/ActivityBar/ActivityItem.vue";
const { openGlobalUploadModal } = useGlobalUploadModal();
export interface Props {
id: string;
title: string;
Expand All @@ -22,34 +21,19 @@ const emit = defineEmits<{
(e: "click"): void;
}>();
const status: Ref<string> = ref("success");
const percentage: Ref<number> = ref(0);
const { openGlobalUploadModal } = useGlobalUploadModal();
const { percentage, status } = storeToRefs(useUploadStore());
onMounted(() => {
eventHub.$on("upload:status", setStatus);
eventHub.$on("upload:percentage", setPercentage);
if (Query.get("tool_id") == "upload1") {
openGlobalUploadModal();
}
});
onUnmounted(() => {
eventHub.$off("upload:status", setStatus);
eventHub.$off("upload:percentage", setPercentage);
});
function onUploadModal() {
emit("click");
openGlobalUploadModal();
}
function setStatus(val: string): void {
status.value = val;
}
function setPercentage(val: number): void {
percentage.value = val;
}
</script>

<template>
Expand Down
49 changes: 27 additions & 22 deletions client/src/components/History/CurrentHistory/HistoryEmpty.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
<script setup lang="ts">
import { useEventBus } from "@vueuse/core";
import { useGlobalUploadModal } from "@/composables/globalUploadModal";
import { localize } from "@/utils/localization";
const { emit } = useEventBus<string>("open-tool-section");
const props = withDefaults(
defineProps<{
message?: string;
writable?: boolean;
}>(),
{
message: "This history is empty.",
writable: true,
}
);
const { openGlobalUploadModal } = useGlobalUploadModal();
function clickDataLink() {
emit("getext");
}
</script>

<template>
<b-alert show>
<h4 class="mb-1">
<i class="fa fa-info-circle empty-message"></i>
<span>{{ message | l }}</span>
<span>{{ localize(message) }}</span>
</h4>
<p v-if="writable">
<p v-if="props.writable">
<a v-localize href="#" @click.prevent="openGlobalUploadModal">You can load your own data</a>
<span v-localize>or</span>
<a v-localize href="#" @click.prevent="clickDataLink">get data from an external source</a>.
</p>
</b-alert>
</template>

<script>
import { useGlobalUploadModal } from "composables/globalUploadModal";
export default {
props: {
message: { type: String, default: "This history is empty." },
writable: { type: Boolean, default: true },
},
setup() {
const { openGlobalUploadModal } = useGlobalUploadModal();
return { openGlobalUploadModal };
},
methods: {
clickDataLink() {
this.eventHub.$emit("openToolSection", "getext");
},
},
};
</script>
8 changes: 5 additions & 3 deletions client/src/components/Panels/Common/ToolSection.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useEventBus } from "@vueuse/core";
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
import { eventHub } from "@/components/plugins/eventHub.js";
import { useConfig } from "@/composables/config";
import { type ToolSectionLabel, useToolStore } from "@/stores/toolStore";
import ariaAlert from "@/utils/ariaAlert";
Expand All @@ -15,6 +15,8 @@ const emit = defineEmits<{
(e: "onOperation", tool: any, evt: Event): void;
}>();
const eventBus = useEventBus<string>("open-tool-section");
const props = defineProps({
category: {
type: Object,
Expand Down Expand Up @@ -132,11 +134,11 @@ watch(
);
onMounted(() => {
eventHub.$on("openToolSection", openToolSection);
eventBus.on(openToolSection);
});
onUnmounted(() => {
eventHub.$off("openToolSection", openToolSection);
eventBus.off(openToolSection);
});
function openToolSection(sectionId: string) {
Expand Down
96 changes: 41 additions & 55 deletions client/src/components/Upload/UploadButton.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
<script setup lang="ts">
import { library } from "@fortawesome/fontawesome-svg-core";
import { faUpload } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { storeToRefs } from "pinia";
import { computed, onMounted } from "vue";
import { useGlobalUploadModal } from "@/composables/globalUploadModal";
import { useUploadStore } from "@/stores/uploadStore";
import localize from "@/utils/localization";
import Query from "@/utils/query-string-parsing";
library.add(faUpload);
const props = withDefaults(
defineProps<{
title?: string;
}>(),
{
title: "Download from URL or upload files from disk",
}
);
const { openGlobalUploadModal } = useGlobalUploadModal();
const { percentage, status } = storeToRefs(useUploadStore());
onMounted(() => {
if (Query.get("tool_id") == "upload1") {
openGlobalUploadModal();
}
});
const localizedTitle = computed(() => {
return localize(props.title);
});
function showUploadDialog() {
openGlobalUploadModal();
}
</script>
<template>
<b-button
id="activity-upload"
v-b-tooltip.hover.noninteractive.bottom
:aria-label="title | localize"
:title="title | localize"
:aria-label="localizedTitle"
:title="localizedTitle"
class="upload-button"
size="sm"
@click="showUploadDialog">
Expand All @@ -21,56 +60,3 @@
</span>
</b-button>
</template>

<script>
import { library } from "@fortawesome/fontawesome-svg-core";
import { faUpload } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { VBTooltip } from "bootstrap-vue";
import { useGlobalUploadModal } from "composables/globalUploadModal";
import Query from "utils/query-string-parsing";
library.add(faUpload);
export default {
components: { FontAwesomeIcon },
directives: {
"v-b-tooltip": VBTooltip,
},
props: {
title: { type: String, default: "Download from URL or upload files from disk" },
},
setup() {
const { openGlobalUploadModal } = useGlobalUploadModal();
return { openGlobalUploadModal };
},
data() {
return {
status: "",
percentage: 0,
};
},
mounted() {
this.eventHub.$on("upload:status", this.setStatus);
this.eventHub.$on("upload:percentage", this.setPercentage);
if (Query.get("tool_id") == "upload1") {
this.showUploadDialog();
}
},
beforeDestroy() {
this.eventHub.$off("upload:status", this.setStatus);
this.eventHub.$off("upload:percentage", this.setPercentage);
},
methods: {
showUploadDialog() {
this.openGlobalUploadModal();
},
setStatus(val) {
this.status = val;
},
setPercentage(val) {
this.percentage = Math.round(val);
},
},
};
</script>
15 changes: 9 additions & 6 deletions client/src/components/Upload/UploadContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
getUploadDatatypes,
getUploadDbKeys,
} from "components/Upload/utils";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref } from "vue";
import { eventHub } from "@/components/plugins/eventHub.js";
import { useUploadStore } from "@/stores/uploadStore";
import { uploadPayload } from "@/utils/upload-payload.js";
import CompositeBox from "./CompositeBox";
Expand Down Expand Up @@ -79,6 +80,8 @@ const listExtensions = ref([]);
const listDbKeys = ref([]);
const regular = ref(null);
const { percentage, status } = storeToRefs(useUploadStore());
const effectiveExtensions = computed(() => {
if (props.formats === null || !datatypesMapperReady.value) {
return listExtensions.value;
Expand Down Expand Up @@ -133,12 +136,12 @@ async function loadMappers() {
datatypesMapperReady.value = true;
}
function progress(percentage, status = null) {
if (percentage !== null) {
eventHub.$emit(`upload:percentage`, percentage);
function progress(newPercentage, newStatus = null) {
if (newPercentage !== null) {
percentage.value = newPercentage;
}
if (status !== null) {
eventHub.$emit(`upload:status`, status);
if (newStatus !== null) {
status.value = newStatus;
}
}
Expand Down
21 changes: 0 additions & 21 deletions client/src/components/plugins/eventHub.js

This file was deleted.

1 change: 0 additions & 1 deletion client/src/components/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { eventHubMixin, eventHubPlugin } from "./eventHub";
export { iconMixin, iconPlugin } from "./icons";
export { localizationPlugin } from "./localization";
export { vueRxShortcutPlugin, vueRxShortcuts } from "./vueRxShortcuts";
Expand Down
9 changes: 9 additions & 0 deletions client/src/stores/uploadStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineStore } from "pinia";
import { ref } from "vue";

export const useUploadStore = defineStore("upload", () => {
const percentage = ref<number>(0);
const status = ref<string>("");

return { percentage, status };
});
7 changes: 1 addition & 6 deletions client/src/utils/mountVueComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// the same plugins and events.

import BootstrapVue from "bootstrap-vue";
import { eventHubPlugin, iconPlugin, localizationPlugin, vueRxShortcutPlugin } from "components/plugins";
import { iconPlugin, localizationPlugin, vueRxShortcutPlugin } from "components/plugins";
import Vue from "vue";
import Vuex from "vuex";

Expand All @@ -14,11 +14,6 @@ Vue.use(Vuex);
// Bootstrap components
Vue.use(BootstrapVue);

// Add a global event bus. We could just use root but I don't think that will
// work right when we have more than one root, which we often will until the
// application has been completely converted to Vue.
Vue.use(eventHubPlugin);

// localization filters and directives
Vue.use(localizationPlugin);

Expand Down
2 changes: 0 additions & 2 deletions client/tests/jest/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { createLocalVue, shallowMount } from "@vue/test-utils";
import BootstrapVue from "bootstrap-vue";
import { eventHubPlugin } from "components/plugins/eventHub";
import { iconPlugin } from "components/plugins/icons";
import { localizationPlugin } from "components/plugins/localization";
import { vueRxShortcutPlugin } from "components/plugins/vueRxShortcuts";
Expand Down Expand Up @@ -190,7 +189,6 @@ export function getLocalVue(instrumentLocalization = false) {
const l = instrumentLocalization ? testLocalize : _l;
localVue.use(localizationPlugin, l);
localVue.use(vueRxShortcutPlugin);
localVue.use(eventHubPlugin);
localVue.use(iconPlugin);
localVue.directive("b-tooltip", mockedDirective);
localVue.directive("b-popover", mockedDirective);
Expand Down

0 comments on commit e340737

Please sign in to comment.