forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdownVisualization.vue
More file actions
121 lines (106 loc) · 4.28 KB
/
MarkdownVisualization.vue
File metadata and controls
121 lines (106 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script setup lang="ts">
import { BAlert } from "bootstrap-vue";
import { computed, type Ref, ref, watch } from "vue";
import type { DatasetLabel, Invocation } from "@/components/Markdown/Editor/types";
import { parseInput, parseOutput } from "@/components/Markdown/Utilities/parseInvocation";
import { stringify } from "@/components/Markdown/Utilities/stringify";
import { useInvocationStore } from "@/stores/invocationStore";
import VisualizationWrapper from "./VisualizationWrapper.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
const DEFAULT_HEIGHT = 400;
const props = defineProps<{
content: string;
name?: string;
}>();
const emit = defineEmits(["change"]);
const datasetLabel: Ref<DatasetLabel | undefined> = ref();
const datasetName: Ref<string | undefined> = ref();
const errorMessage = ref("");
const visualizationConfig = ref();
const visualizationHeight = ref(DEFAULT_HEIGHT);
const visualizationKey = ref(0);
const visualizationName = ref();
const visualizationTitle = ref("");
const { getInvocationById, getInvocationLoadError, isLoadingInvocation } = useInvocationStore();
const currentContent = ref(props.content);
const invocation = computed(() => invocationId.value && getInvocationById(invocationId.value));
const invocationId = computed(() => datasetLabel.value?.invocation_id || "");
const invocationLoading = computed(() => isLoadingInvocation(invocationId.value));
const invocationLoadError = computed(() => getInvocationLoadError(invocationId.value));
function onChange(incomingData: Record<string, any>) {
const newContent = {
visualization_name: visualizationName.value,
visualization_title: incomingData.visualization_title,
dataset_label: datasetLabel.value,
dataset_name: datasetName.value,
height: visualizationHeight.value,
...incomingData.visualization_config,
};
currentContent.value = stringify(newContent);
emit("change", currentContent.value);
}
function processContent() {
try {
errorMessage.value = "";
const parsedContent = { ...JSON.parse(props.content) };
datasetLabel.value = parsedContent.dataset_label;
datasetName.value = parsedContent.dataset_name;
visualizationConfig.value = {
dataset_id: parsedContent.dataset_id,
dataset_url: parsedContent.dataset_url,
settings: parsedContent.settings,
tracks: parsedContent.tracks,
};
visualizationHeight.value = parsedContent.height || DEFAULT_HEIGHT;
visualizationTitle.value = parsedContent.visualization_title || "";
visualizationName.value = props.name || parsedContent.visualization_name;
if (!visualizationName.value) {
throw new Error("Please add a 'visualization_name` to the dictionary.");
}
processInvocation();
if (currentContent.value !== props.content) {
currentContent.value = props.content;
visualizationKey.value++;
}
} catch (e) {
errorMessage.value = String(e);
}
}
function processInvocation() {
if (invocation.value) {
const inputId = parseInput(invocation.value as Invocation, datasetLabel.value?.input);
const outputId = parseOutput(invocation.value as Invocation, datasetLabel.value?.output);
const datasetId = inputId || outputId;
visualizationConfig.value.dataset_id = datasetId;
}
}
watch(
() => props.content,
() => processContent(),
{ immediate: true },
);
watch(
() => invocation.value,
() => processInvocation(),
);
</script>
<template>
<div class="markdown-visualization">
<BAlert v-if="errorMessage" v-localize class="m-0" variant="danger" show>
{{ errorMessage }}
</BAlert>
<BAlert v-else-if="invocationLoadError" v-localize class="m-0" variant="danger" show>
{{ invocationLoadError }}
</BAlert>
<LoadingSpan v-else-if="invocationLoading" />
<VisualizationWrapper
v-else-if="visualizationConfig"
:key="visualizationKey"
class="markdown-visualization"
:config="visualizationConfig"
:height="visualizationHeight"
:name="visualizationName"
:title="visualizationTitle"
@change="onChange" />
</div>
</template>