|
| 1 | +<template> |
| 2 | + <b-alert v-if="errorMessage" variant="warning" show>{{ errorMessage }}</b-alert> |
| 3 | + <MarkdownSelector v-else-if="labels !== undefined" argument-name="Dataset" :labels="labels" @onOk="onLabel" /> |
| 4 | + <DataDialog |
| 5 | + v-else-if="currentHistoryId !== null" |
| 6 | + :history="currentHistoryId" |
| 7 | + format="id" |
| 8 | + @onOk="onData" |
| 9 | + @onCancel="$emit('cancel')" /> |
| 10 | + <b-alert v-else v-localize variant="info" show> No history available to choose from. </b-alert> |
| 11 | +</template> |
| 12 | + |
| 13 | +<script setup lang="ts"> |
| 14 | +import { storeToRefs } from "pinia"; |
| 15 | +import { type Ref, ref, watch } from "vue"; |
| 16 | +
|
| 17 | +import type { DatasetLabel, WorkflowLabel } from "@/components/Markdown/Editor/types"; |
| 18 | +import { stringify } from "@/components/Markdown/Utilities/stringify"; |
| 19 | +import { useHistoryStore } from "@/stores/historyStore"; |
| 20 | +
|
| 21 | +import DataDialog from "@/components/DataDialog/DataDialog.vue"; |
| 22 | +import MarkdownSelector from "@/components/Markdown/MarkdownSelector.vue"; |
| 23 | +
|
| 24 | +const { currentHistoryId } = storeToRefs(useHistoryStore()); |
| 25 | +
|
| 26 | +const props = defineProps<{ |
| 27 | + content: string; |
| 28 | + labels?: Array<WorkflowLabel>; |
| 29 | +}>(); |
| 30 | +
|
| 31 | +const emit = defineEmits<{ |
| 32 | + (e: "cancel"): void; |
| 33 | + (e: "change", content: string): void; |
| 34 | +}>(); |
| 35 | +
|
| 36 | +interface contentType { |
| 37 | + dataset_id?: string; |
| 38 | + dataset_label?: DatasetLabel; |
| 39 | + dataset_url?: string; |
| 40 | +} |
| 41 | +
|
| 42 | +const contentObject: Ref<contentType | undefined> = ref(); |
| 43 | +const errorMessage = ref(""); |
| 44 | +
|
| 45 | +function onData(datasetId: any) { |
| 46 | + if (contentObject.value) { |
| 47 | + contentObject.value.dataset_id = datasetId; |
| 48 | + contentObject.value.dataset_label = undefined; |
| 49 | + contentObject.value.dataset_url = undefined; |
| 50 | + emit("change", stringify(contentObject.value)); |
| 51 | + } |
| 52 | +} |
| 53 | +
|
| 54 | +function onLabel(selectedLabel: any) { |
| 55 | + if (selectedLabel !== undefined) { |
| 56 | + const labelType = selectedLabel.type; |
| 57 | + const label = selectedLabel.label; |
| 58 | + if (contentObject.value && label && labelType) { |
| 59 | + contentObject.value.dataset_label = { |
| 60 | + invocation_id: "", |
| 61 | + [labelType]: label, |
| 62 | + }; |
| 63 | + contentObject.value.dataset_id = undefined; |
| 64 | + contentObject.value.dataset_url = undefined; |
| 65 | + emit("change", stringify(contentObject.value)); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +
|
| 70 | +function parseContent() { |
| 71 | + try { |
| 72 | + contentObject.value = JSON.parse(props.content); |
| 73 | + errorMessage.value = ""; |
| 74 | + } catch (e) { |
| 75 | + errorMessage.value = `Failed to parse: ${e}`; |
| 76 | + } |
| 77 | +} |
| 78 | +
|
| 79 | +watch( |
| 80 | + () => props.content, |
| 81 | + () => parseContent(), |
| 82 | + { immediate: true } |
| 83 | +); |
| 84 | +</script> |
0 commit comments