Skip to content

Commit c078e73

Browse files
show pre-populated example data values in workflow run form
1 parent ab32ab7 commit c078e73

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script setup lang="ts">
2+
import type { ExampleData } from "./types";
3+
4+
import FormExampleDataElement from "./FormExampleDataElement.vue";
5+
6+
const props = defineProps<{
7+
value: ExampleData;
8+
}>();
9+
</script>
10+
11+
<template>
12+
<FormExampleDataElement
13+
v-if="props.value.class === 'Collection'"
14+
:value="{
15+
class: 'Collection',
16+
elements: props.value.elements,
17+
identifier: 'Collection',
18+
type: props.value.collection_type,
19+
}" />
20+
<FormExampleDataElement
21+
v-else-if="props.value.class === 'File'"
22+
:value="{
23+
class: 'File',
24+
identifier: 'Dataset',
25+
location: props.value.location,
26+
}"
27+
:file-type="props.value.filetype" />
28+
</template>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<script setup lang="ts">
2+
import { BCollapse, BLink } from "bootstrap-vue";
3+
import { ref } from "vue";
4+
5+
import type { ExampleDataCollectionElement, ExampleDataFileElement } from "./types";
6+
7+
const props = defineProps<{
8+
value: ExampleDataCollectionElement | ExampleDataFileElement;
9+
fileType?: string;
10+
}>();
11+
12+
const expanded = ref(false);
13+
</script>
14+
15+
<template>
16+
<div v-if="props.value.class === 'Collection'">
17+
<div
18+
tabindex="0"
19+
role="button"
20+
class="form-example-data-element rounded"
21+
@click="expanded = !expanded"
22+
@keydown.enter="expanded = !expanded">
23+
<strong>{{ props.value.identifier || "Collection" }}</strong>
24+
<i>({{ props.value.type }})</i>
25+
<span class="float-right"> {{ expanded ? "Hide" : "Show" }} elements </span>
26+
</div>
27+
<BCollapse :visible="expanded" class="pl-2">
28+
<FormExampleDataElement v-for="(element, index) in props.value.elements" :key="index" :value="element" />
29+
</BCollapse>
30+
</div>
31+
<div v-else-if="props.value.class === 'File'">
32+
<div class="form-example-data-element rounded d-flex justify-content-between align-items-center w-100">
33+
<div>
34+
<strong>{{ props.value.identifier || "Dataset" }}</strong>
35+
<i v-if="props.fileType">({{ props.fileType }})</i>
36+
</div>
37+
<BLink v-if="props.value.location" :href="props.value.location" target="_blank">
38+
<i>{{ props.value.location }}</i>
39+
</BLink>
40+
</div>
41+
</div>
42+
</template>
43+
44+
<style scoped lang="scss">
45+
.form-example-data-element {
46+
// background-color: $state-success-bg; // TODO: Does not seem to work even
47+
// with the "theme/blue.scss" import
48+
background-color: #c2ebc2;
49+
padding: 0.5rem 1.25rem;
50+
}
51+
</style>

client/src/components/Form/Elements/FormData/types.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
type ExampleDataFile = {
2+
class: "File";
3+
filetype: string;
4+
location: string;
5+
};
6+
7+
type ExampleDataCollection = {
8+
class: "Collection";
9+
collection_type: string;
10+
elements?: Array<ExampleDataFileElement | ExampleDataCollectionElement>;
11+
};
12+
13+
export type ExampleDataFileElement = {
14+
class: "File";
15+
identifier: string;
16+
location: string;
17+
};
18+
19+
export type ExampleDataCollectionElement = {
20+
class: "Collection";
21+
elements?: Array<ExampleDataFileElement | ExampleDataCollectionElement>;
22+
identifier: string;
23+
type: string;
24+
};
25+
26+
export type ExampleData = ExampleDataFile | ExampleDataCollection;
27+
128
export type DataOption = {
229
id: string;
330
hid?: number;
@@ -13,3 +40,7 @@ export type DataOption = {
1340
export function isDataOption(item: object): item is DataOption {
1441
return !!item && "src" in item;
1542
}
43+
44+
export function isExampleData(item: object): item is ExampleData {
45+
return !!item && "class" in item && (item as ExampleData).class !== undefined;
46+
}

client/src/components/Form/FormElement.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { computed, ref, useAttrs } from "vue";
99
1010
import { linkify } from "@/utils/utils";
1111
12+
import { isExampleData } from "./Elements/FormData/types";
1213
import type { FormParameterAttributes, FormParameterTypes, FormParameterValue } from "./parameterTypes";
1314
1415
import FormBoolean from "./Elements/FormBoolean.vue";
1516
import FormColor from "./Elements/FormColor.vue";
1617
import FormData from "./Elements/FormData/FormData.vue";
1718
import FormDataUri from "./Elements/FormData/FormDataUri.vue";
19+
import FormExampleData from "./Elements/FormData/FormExampleData.vue";
1820
import FormDirectory from "./Elements/FormDirectory.vue";
1921
import FormDrilldown from "./Elements/FormDrilldown/FormDrilldown.vue";
2022
import FormError from "./Elements/FormError.vue";
@@ -169,6 +171,13 @@ const showField = computed(
169171
const formDataField = computed(() =>
170172
props.type && ["data", "data_collection"].includes(props.type) ? (props.type as "data" | "data_collection") : null
171173
);
174+
const isExampleDataField = computed(() => {
175+
const dataField = formDataField.value;
176+
if (dataField && isExampleData(props.value)) {
177+
return true;
178+
}
179+
return false;
180+
});
172181
const isUriDataField = computed(() => {
173182
const dataField = props.type == "data";
174183
if (dataField && props.value && "src" in props.value) {
@@ -409,6 +418,11 @@ function onAlert(value: string | undefined) {
409418
v-model="currentValue"
410419
:value="attrs.value"
411420
:multiple="attrs.multiple" />
421+
<FormExampleData
422+
v-else-if="isExampleDataField"
423+
:id="id"
424+
:value="attrs.value"
425+
:multiple="attrs.multiple" />
412426
<FormData
413427
v-else-if="formDataField"
414428
:id="id"

0 commit comments

Comments
 (0)