Skip to content

Commit

Permalink
chore(ui): improve copy as curl functionality (#4696)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri1969 authored and brian-mulier-p committed Aug 29, 2024
1 parent 095e29e commit e1b7f1c
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions ui/src/components/flows/Curl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@
default: true
}
},
data() {
return {
exampleFileName: "kestra.json"
}
},
computed: {
curlCommand() {
return this.generateCurlCommand();
const mainCommand = this.generateCurlCommand();
if (this.flow.inputs && this.flow.inputs.find((input) => input.type === "FILE")) {
return `${this.toShell(this.generatePrefix())} && \\\n${this.toShell(mainCommand)}`;
} else {
return `${this.toShell(mainCommand)}`;
}
},
exampleFileInputUrl() {
return `https://huggingface.co/datasets/kestra/datasets/resolve/main/json/${this.exampleFileName}`;
}
},
methods: {
Expand All @@ -55,16 +69,25 @@
switch (input.type) {
case "FILE": {
const fileInput = this.inputs[input.id];
if (fileInput) {
inputValue = fileInput.name;
}
inputValue = this.exampleFileName;
break;
}
case "SECRET": {
inputValue = this.inputs[input.id] ? "******" : undefined;
break;
}
case "DURATION": {
inputValue = this.$moment.duration(this.$moment(this.inputs[input.id]).format("hh:mm:ss")).toJSON();
break;
}
case "DATE": {
inputValue = this.$moment(this.inputs[input.id]).format("YYYY-MM-DD");
break;
}
case "TIME": {
inputValue = this.$moment(this.inputs[input.id]).format("hh:mm:ss");
break;
}
default:
inputValue = this.inputs[input.id];
}
Expand Down Expand Up @@ -115,8 +138,22 @@
command.push(`'${this.generateUrl()}'`);
return command
},
generatePrefix() {
return ["curl", "-O", `'${this.exampleFileInputUrl}'`];
},
toShell(command) {
return command.join(" ");
}
}
}
</script>
</script>

<style lang="scss" scoped>
/* Allow line-wraps */
code {
display: block;
white-space: pre-wrap;
}
</style>

0 comments on commit e1b7f1c

Please sign in to comment.