From e1b7f1ce16aebfcc9bc6a960f01bc232ac766ef5 Mon Sep 17 00:00:00 2001 From: yuri <1969yuri1969@gmail.com> Date: Mon, 26 Aug 2024 09:13:30 +0200 Subject: [PATCH] chore(ui): improve copy as curl functionality (#4696) --- ui/src/components/flows/Curl.vue | 49 ++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/ui/src/components/flows/Curl.vue b/ui/src/components/flows/Curl.vue index 4a1f0e5ca9..d2b28f1563 100644 --- a/ui/src/components/flows/Curl.vue +++ b/ui/src/components/flows/Curl.vue @@ -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: { @@ -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]; } @@ -115,8 +138,22 @@ command.push(`'${this.generateUrl()}'`); + return command + }, + generatePrefix() { + return ["curl", "-O", `'${this.exampleFileInputUrl}'`]; + }, + toShell(command) { return command.join(" "); } } } - \ No newline at end of file + + +