Skip to content

Commit

Permalink
refactor stores, track help mode position, only drag from header
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Mar 22, 2024
1 parent cbfa45a commit b4850ef
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 95 deletions.
10 changes: 7 additions & 3 deletions client/src/components/Form/FormDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script>
import { mapStores } from "pinia";
import { mapActions } from "pinia";
import Vue from "vue";
import { useHelpModeTextStore } from "@/stores/helpmode/helpModeTextStore";
Expand Down Expand Up @@ -102,7 +102,6 @@ export default {
};
},
computed: {
...mapStores(useHelpModeTextStore),
validation() {
return validateInputs(this.formIndex, this.formData, this.allowEmptyValueOnRequiredInput);
},
Expand Down Expand Up @@ -153,9 +152,14 @@ export default {
// highlight initial errors
this.onErrors();
},
destroyed() {
// since the user is leaving the form, the help mode is reset
this.clearHelpModeText();
},
methods: {
...mapActions(useHelpModeTextStore, ["storeHelpModeText", "clearHelpModeText"]),
callHelpMode() {
this.helpModeTextStore.addHelpModeText("tool_form_base");
this.storeHelpModeText("tool_form_base");
},
buildFormData() {
const params = {};
Expand Down
18 changes: 5 additions & 13 deletions client/src/components/Masthead/HelpModeSwitch.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
<script setup lang="ts">
import { computed } from "vue";
import { storeToRefs } from "pinia";
import { useHelpModeStatusStore } from "@/stores/helpmode/helpModeStatusStore";
const tooltip = "Enable/Disable Help Mode";
const statusStore = useHelpModeStatusStore();
const enabledStatus = computed({
get() {
return statusStore.helpmodestatus;
},
set(value: boolean) {
statusStore.setHelpModeStatus(value);
},
});
const { status } = storeToRefs(useHelpModeStatusStore());
function toggleEnabledStatus() {
enabledStatus.value = !enabledStatus.value;
status.value = !status.value;
}
</script>

<template>
<div>
<button
class="help-mode-button"
:class="{ highlight: enabledStatus }"
:class="{ highlight: status }"
:title="tooltip"
:aria-label="tooltip"
@click="toggleEnabledStatus"
@keydown.enter="toggleEnabledStatus">
<i class="fas fa-question-circle fa-lg" :class="{ highlight: enabledStatus }"> </i> Help Me
<i class="fas fa-question-circle fa-lg" :class="{ highlight: status }"> </i> Help Me
</button>
</div>
</template>
Expand Down
86 changes: 54 additions & 32 deletions client/src/components/Panels/HelpModeText.vue
Original file line number Diff line number Diff line change
@@ -1,62 +1,82 @@
<script setup lang="ts">
import { library } from "@fortawesome/fontawesome-svg-core";
import { faTimes } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { useDraggable } from "@vueuse/core";
import { BButton } from "bootstrap-vue";
import MarkdownIt from "markdown-it";
import { computed, onMounted, ref } from "vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref, watch } from "vue";
import { useHelpModeStatusStore } from "@/stores/helpmode/helpModeStatusStore";
import { useHelpModeTextStore } from "@/stores/helpmode/helpModeTextStore";
import Heading from "@/components/Common/Heading.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
library.add(faTimes);
const md = MarkdownIt();
const helpInfo = useHelpModeTextStore();
const status = useHelpModeStatusStore();
// local refs
const { content, loading } = storeToRefs(useHelpModeTextStore());
const { status, position } = storeToRefs(useHelpModeStatusStore());
const el = ref<HTMLElement | null>(null);
const helpModeHeader = ref<HTMLElement | null>(null);
const helpTextRef = ref(null);
// local computed refs
const helpText = computed({
get() {
return md.render(helpInfo.helpmodetext);
return md.render(content.value);
},
set() {
//do nothing, this is set in components that add helptext
},
});
const helpStatus = computed({
get() {
return status.helpmodestatus;
},
set(value: boolean) {
status.setHelpModeStatus(value);
},
});
function closeHelpMode() {
helpStatus.value = !helpStatus.value;
}
const el = ref<HTMLElement | null>(null);
const { x, y, style } = useDraggable(el, {
initialValue: { x: 0, y: 0 },
// draggable properties
const {
x: dragX,
y: dragY,
style,
} = useDraggable(helpModeHeader, {
initialValue: position.value,
});
const helpTextRef = ref(null);
// watch both x and y, and do something if they change:
watch(
() => [dragX.value, dragY.value],
([newX, newY]) => {
if (newX && newY) {
position.value = { x: newX, y: newY };
}
}
);
onMounted(() => {
const links = (helpTextRef.value as unknown as HTMLElement).querySelectorAll("a");
links.forEach((link: HTMLAnchorElement) => {
link.setAttribute("target", "_blank");
});
});
</script>

<template>
<div
ref="el"
:style="style"
style="position: fixed"
class="helptext unified-panel-body d-flex justify-content-between">
<div class="header">
<h1>Galaxy Help Mode</h1>
<button class="close-button" @click="closeHelpMode">
<i class="fas fa-times"></i>
</button>
<div ref="el" :style="style" class="help-text unified-panel-body d-flex justify-content-between">
<div ref="helpModeHeader" class="header">
<Heading h4 inline size="sm" class="flex-grow-1 mx-2">Galaxy Help Mode</Heading>
<BButton class="close-button" size="sm" @click="status = false">
<FontAwesomeIcon :icon="faTimes" />
</BButton>
</div>
<div ref="helpTextRef" class="help-mode-container" v-html="helpText"></div>
<!-- eslint-disable-next-line vue/no-v-html -->
<div v-if="!loading" ref="helpTextRef" class="help-mode-container" v-html="helpText" />
<LoadingSpan v-else message="Loading help text" />
</div>
</template>
<style>
.helptext {

<style scoped lang="scss">
.help-text {
display: flex;
flex-direction: column;
width: 25% !important;
Expand All @@ -68,6 +88,7 @@ onMounted(() => {
border-width: 2px;
border: solid;
opacity: 90%;
position: fixed;
}
.header {
display: flex;
Expand All @@ -76,6 +97,7 @@ onMounted(() => {
justify-content: space-between;
align-items: center;
border-bottom: 2px solid #868686;
cursor: move;
/* padding-bottom: 10px; */
}
.help-mode-container {
Expand Down
5 changes: 3 additions & 2 deletions client/src/entry/analysis/modules/Analysis.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup>
import { storeToRefs } from "pinia";
import { onMounted, onUnmounted, ref } from "vue";
import { useRouter } from "vue-router/composables";
Expand All @@ -15,7 +16,7 @@ import DragAndDropModal from "@/components/Upload/DragAndDropModal.vue";
const router = useRouter();
const showCenter = ref(false);
const { showPanels } = usePanels();
const status = useHelpModeStatusStore();
const { status: helpModeStatus } = storeToRefs(useHelpModeStatusStore());
// methods
function hideCenter() {
Expand Down Expand Up @@ -49,6 +50,6 @@ onUnmounted(() => {
<HistoryIndex />
</FlexPanel>
<DragAndDropModal />
<HelpModeText v-if="status.helpmodestatus" />
<HelpModeText v-if="helpModeStatus" />
</div>
</template>
20 changes: 0 additions & 20 deletions client/src/stores/helpmode/helpModeStatusStore.js

This file was deleted.

32 changes: 32 additions & 0 deletions client/src/stores/helpmode/helpModeStatusStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Stores Galaxy Help Mode's status
*/

import { defineStore } from "pinia";
import { ref } from "vue";

// import { useHelpModeTextStore } from "./helpModeTextStore";

export const useHelpModeStatusStore = defineStore("helpModeStatusStore", () => {
// TODO: Maybe `status` should be tracked in local storage?
// const status: Ref<boolean> = useUserLocalStorage("help-mode-status", false);

const status = ref(false);
const position = ref({ x: 0, y: 0 });

// TODO: I removed the following since we now clear the text when we go away from
// a component (the component is is destroyed) anyways.

// Clear help mode text when help mode is disabled
// watch(() => status.value, (newStatus) => {
// status.value = newStatus;
// if (!newStatus) {
// useHelpModeTextStore().clearHelpModeText();
// }
// });

return {
status,
position,
};
});
25 changes: 0 additions & 25 deletions client/src/stores/helpmode/helpModeTextStore.js

This file was deleted.

45 changes: 45 additions & 0 deletions client/src/stores/helpmode/helpModeTextStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Stores Galaxy Help Mode's help content
* TODO: Maybe this store is not needed and we have one singular `helpModeStore`?
*/

import { defineStore } from "pinia";
import { ref } from "vue";

import config from "./helpTextConfig.yml";

const DEFAULT_HELP_TEXT = "Welcome to Galaxy Help Mode!";

export const useHelpModeTextStore = defineStore("helpModeTextStore", () => {
// TODO: We can store multiple help mode texts in the following variable, referenced by "content ids".
// Then, `storeHelpModeText` can be modified to accept an id, and fetch and store the corresponding
// help mode text. Then maybe we could have a tabbed interface within the help mode, we would prevent
// multiple fetched for the same component or it would still open up other possibilities...
// const contents = ref({});

const content = ref(DEFAULT_HELP_TEXT);
const loading = ref(false);

/** Adds help mode text for the given Galaxy component `id` */
async function storeHelpModeText(id: string) {
const file_path = config[id];
loading.value = true;
await fetch("https://raw.githubusercontent.com/assuntad23/galaxy-help-markdown/main/" + file_path)
.then((response) => response.text())
.then((text) => {
content.value = text;
loading.value = false;
});
}

function clearHelpModeText() {
content.value = DEFAULT_HELP_TEXT;
}

return {
content,
loading,
storeHelpModeText,
clearHelpModeText,
};
});

0 comments on commit b4850ef

Please sign in to comment.