Skip to content

Commit

Permalink
feat(ui): multiple improvements of no code editor (#7028)
Browse files Browse the repository at this point in the history
* chore(ui): properly handle metadata inputs adding and removal

* feat(ui): make sure plugin documentation is properly updated on task selection
  • Loading branch information
MilosPaunovic authored Jan 29, 2025
1 parent 1a23df3 commit 815467e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
7 changes: 6 additions & 1 deletion ui/src/components/code/NoCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:metadata
@update-metadata="(k, v) => emits('updateMetadata', {[k]: v})"
@update-task="(yaml) => emits('updateTask', yaml)"
@update-documentation="(task) => emits('updateDocumentation', task)"
/>
</div>
</template>
Expand All @@ -25,7 +26,11 @@
import Breadcrumbs from "./components/Breadcrumbs.vue";
import Editor from "./segments/Editor.vue";
const emits = defineEmits(["updateTask", "updateMetadata"]);
const emits = defineEmits([
"updateTask",
"updateMetadata",
"updateDocumentation",
]);
const props = defineProps({
flow: {type: String, required: true},
});
Expand Down
22 changes: 19 additions & 3 deletions ui/src/components/code/segments/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
:flow
:creation
@update-task="(yaml) => emits('updateTask', yaml)"
@update-documentation="(task) => emits('updateDocumentation', task)"
/>
</div>
</template>

<script setup lang="ts">
import {ref, shallowRef, computed} from "vue";
import {watch, ref, shallowRef, computed} from "vue";
import {Field, Fields, CollapseItem} from "../utils/types";
Expand All @@ -72,6 +73,16 @@
import {useRoute} from "vue-router";
const route = useRoute();
watch(
() => route.query,
async (newQuery) => {
if (!newQuery?.section && !newQuery?.identifier) {
emits("updateDocumentation", null);
}
},
{deep: true},
);
import {useI18n} from "vue-i18n";
const {t} = useI18n({useScope: "global"});
Expand All @@ -80,7 +91,12 @@
const panel = computed(() => store.state.code.panel);
const emits = defineEmits(["save", "updateTask", "updateMetadata"]);
const emits = defineEmits([
"save",
"updateTask",
"updateMetadata",
"updateDocumentation",
]);
const saveEvent = (e: KeyboardEvent) => {
if (e.type === "keydown" && e.key === "s" && e.ctrlKey) {
Expand Down Expand Up @@ -144,7 +160,7 @@
component: shallowRef(MetadataInputs),
value: props.metadata.inputs,
label: t("no_code.fields.general.inputs"),
inputs: props.metadata.inputs,
inputs: props.metadata.inputs ?? [],
},
outputs: {
component: shallowRef(Editor),
Expand Down
11 changes: 8 additions & 3 deletions ui/src/components/code/segments/Task.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:section
@update:model-value="validateTask"
/>

<component
v-else
:is="lastBreadcumb.component.type"
Expand All @@ -28,9 +28,9 @@
</template>

<script setup lang="ts">
import {ref, watch, computed} from "vue";
import {onBeforeMount, ref, watch, computed} from "vue";
const emits = defineEmits(["updateTask"]);
const emits = defineEmits(["updateTask", "updateDocumentation"]);
const props = defineProps({
flow: {type: String, required: true},
creation: {type: Boolean, default: false},
Expand Down Expand Up @@ -64,6 +64,11 @@
YamlUtils.extractTask(props.flow, route.query.identifier)?.toString() || "",
);
onBeforeMount(() => {
const type = YamlUtils.parse(yaml.value)?.type ?? null;
emits("updateDocumentation", type);
});
watch(
() => route.query.section,
(value) => {
Expand Down
10 changes: 4 additions & 6 deletions ui/src/components/flows/MetadataInputs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,15 @@
...mapState("plugin", ["inputSchema", "inputsType"]),
},
mounted() {
if (this.inputs && this.inputs.length > 0) {
if (this.inputs.at(-1).length) this.newInputs = this.inputs.at(-1);
else this.newInputs = this.inputs;
}
this.newInputs = this.inputs;
this.$store
.dispatch("plugin/loadInputsType")
.then((_) => (this.loading = false));
},
data() {
return {
newInputs: [{type: "STRING"}],
newInputs: [],
selectedInput: undefined,
selectedIndex: undefined,
isEditOpen: false,
Expand Down Expand Up @@ -122,10 +119,11 @@
}
},
updateSelected(value) {
this.newInputs[this.selectedIndex] = value;
this.newInputs = value;
},
deleteInput(index) {
this.newInputs.splice(index, 1);
this.$emit("update:modelValue", this.newInputs);
},
addInput() {
this.newInputs.push({type: "STRING"});
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/flows/MetadataInputsContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
emits: ["update:modelValue"],
props: {
modelValue: {
type: Array,
default: () => [],
type: Object,
default: () => {},
},
inputs: {
type: Array,
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/inputs/EditorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
:flow="flowYaml"
@update-metadata="(e) => onUpdateMetadata(e, true)"
@update-task="(e) => editorUpdate(e)"
@update-documentation="(task) => updatePluginDocumentation(undefined, task)"
/>
</div>
<div class="slider" @mousedown.prevent.stop="dragEditor" v-if="combinedEditor" />
Expand Down Expand Up @@ -740,9 +741,9 @@
emit(type, event);
};
const updatePluginDocumentation = (event) => {
const updatePluginDocumentation = (event, task) => {
const pluginSingleList = store.getters["plugin/getPluginSingleList"];
const taskType = YamlUtils.getTaskType(
const taskType = task !== undefined ? task : YamlUtils.getTaskType(
event.model.getValue(),
event.position,
pluginSingleList
Expand Down

0 comments on commit 815467e

Please sign in to comment.