From 4872f9fa4ea6d576039fc6cfe8609d306214bf1e Mon Sep 17 00:00:00 2001 From: Prakash Maheshwaran <73785492+Prakashmaheshwaran@users.noreply.github.com> Date: Mon, 9 Jun 2025 21:01:45 -0400 Subject: [PATCH] add PowerShell command option to API command copy dropdown (#2633) --- .../src/components/CopyApiCommandDropdown.tsx | 65 +++++++++++++++++++ .../routes/tasks/create/CreateNewTaskForm.tsx | 29 +++------ .../src/routes/tasks/create/SavedTaskForm.tsx | 30 +++------ .../src/routes/tasks/detail/TaskDetails.tsx | 37 +++++------ .../src/routes/workflows/RunWorkflowForm.tsx | 31 +++------ .../src/routes/workflows/WorkflowRun.tsx | 32 +++------ skyvern-frontend/src/util/apiCommands.ts | 63 ++++++++++++++++++ 7 files changed, 178 insertions(+), 109 deletions(-) create mode 100644 skyvern-frontend/src/components/CopyApiCommandDropdown.tsx create mode 100644 skyvern-frontend/src/util/apiCommands.ts diff --git a/skyvern-frontend/src/components/CopyApiCommandDropdown.tsx b/skyvern-frontend/src/components/CopyApiCommandDropdown.tsx new file mode 100644 index 00000000..6ba00c2b --- /dev/null +++ b/skyvern-frontend/src/components/CopyApiCommandDropdown.tsx @@ -0,0 +1,65 @@ +import { CopyIcon } from "@radix-ui/react-icons"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { Button } from "@/components/ui/button"; +import { toast } from "@/components/ui/use-toast"; +import { copyText } from "@/util/copyText"; +import { + generateApiCommands, + type ApiCommandOptions, +} from "@/util/apiCommands"; + +interface Props { + getOptions: () => ApiCommandOptions; +} + +function CopyApiCommandDropdown({ getOptions }: Props) { + return ( + + + + + + { + const { curl } = generateApiCommands(getOptions()); + copyText(curl).then(() => { + toast({ + variant: "success", + title: "Copied to Clipboard", + description: + "The cURL command has been copied to your clipboard.", + }); + }); + }} + > + Copy cURL (Unix/Linux/macOS) + + { + const { powershell } = generateApiCommands(getOptions()); + copyText(powershell).then(() => { + toast({ + variant: "success", + title: "Copied to Clipboard", + description: + "The PowerShell command has been copied to your clipboard.", + }); + }); + }} + > + Copy PowerShell (Windows) + + + + ); +} + +export { CopyApiCommandDropdown }; diff --git a/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx b/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx index 8631daa3..aa079dba 100644 --- a/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx +++ b/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx @@ -20,14 +20,14 @@ import { toast } from "@/components/ui/use-toast"; import { useApiCredential } from "@/hooks/useApiCredential"; import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { CodeEditor } from "@/routes/workflows/components/CodeEditor"; -import { copyText } from "@/util/copyText"; import { apiBaseUrl } from "@/util/env"; +import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown"; +import { type ApiCommandOptions } from "@/util/apiCommands"; import { zodResolver } from "@hookform/resolvers/zod"; -import { CopyIcon, PlayIcon, ReloadIcon } from "@radix-ui/react-icons"; +import { PlayIcon, ReloadIcon } from "@radix-ui/react-icons"; import { ToastAction } from "@radix-ui/react-toast"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { AxiosError } from "axios"; -import fetchToCurl from "fetch-to-curl"; import { useState } from "react"; import { useForm, useFormState } from "react-hook-form"; import { Link } from "react-router-dom"; @@ -622,11 +622,9 @@ function CreateNewTaskForm({ initialValues }: Props) {
- + }) satisfies ApiCommandOptions + } + /> + }) satisfies ApiCommandOptions + } + /> + /> {taskIsRunningOrQueued && ( diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx index b7974a7b..5d1a6748 100644 --- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx +++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx @@ -14,11 +14,11 @@ import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/use-toast"; import { useApiCredential } from "@/hooks/useApiCredential"; import { useCredentialGetter } from "@/hooks/useCredentialGetter"; -import { copyText } from "@/util/copyText"; import { apiBaseUrl } from "@/util/env"; -import { CopyIcon, PlayIcon, ReloadIcon } from "@radix-ui/react-icons"; +import { type ApiCommandOptions } from "@/util/apiCommands"; +import { PlayIcon, ReloadIcon } from "@radix-ui/react-icons"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import fetchToCurl from "fetch-to-curl"; +import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown"; import { useForm } from "react-hook-form"; import { useNavigate, useParams } from "react-router-dom"; import { z } from "zod"; @@ -333,17 +333,14 @@ function RunWorkflowForm({
- + />
- + }) satisfies ApiCommandOptions + } + />