diff --git a/skyvern-frontend/src/routes/workflows/ImportWorkflowButton.tsx b/skyvern-frontend/src/routes/workflows/ImportWorkflowButton.tsx new file mode 100644 index 00000000..3afd39ae --- /dev/null +++ b/skyvern-frontend/src/routes/workflows/ImportWorkflowButton.tsx @@ -0,0 +1,101 @@ +import { getClient } from "@/api/AxiosClient"; +import { Label } from "@/components/ui/label"; +import { ReloadIcon, UploadIcon } from "@radix-ui/react-icons"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { useId } from "react"; +import { stringify as convertToYAML } from "yaml"; +import { WorkflowApiResponse } from "./types/workflowTypes"; +import { useCredentialGetter } from "@/hooks/useCredentialGetter"; +import { useNavigate } from "react-router-dom"; +import { AxiosError } from "axios"; +import { toast } from "@/components/ui/use-toast"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; + +function isJsonString(str: string): boolean { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +} + +function ImportWorkflowButton() { + const inputId = useId(); + const credentialGetter = useCredentialGetter(); + const queryClient = useQueryClient(); + const navigate = useNavigate(); + + const createWorkflowFromYamlMutation = useMutation({ + mutationFn: async (yaml: string) => { + const client = await getClient(credentialGetter); + return client.post( + "/workflows", + yaml, + { + headers: { + "Content-Type": "text/plain", + }, + }, + ); + }, + onSuccess: (response) => { + queryClient.invalidateQueries({ + queryKey: ["workflows"], + }); + navigate(`/workflows/${response.data.workflow_permanent_id}/edit`); + }, + onError: (error: AxiosError) => { + toast({ + variant: "destructive", + title: "Error importing workflow", + description: error.message || "An error occurred", + }); + }, + }); + + return ( + + + + + + + Import a workflow from a YAML or JSON file + + + + ); +} + +export { ImportWorkflowButton }; diff --git a/skyvern-frontend/src/routes/workflows/Workflows.tsx b/skyvern-frontend/src/routes/workflows/Workflows.tsx index dee1212e..265d64dd 100644 --- a/skyvern-frontend/src/routes/workflows/Workflows.tsx +++ b/skyvern-frontend/src/routes/workflows/Workflows.tsx @@ -1,6 +1,7 @@ import { getClient } from "@/api/AxiosClient"; import { WorkflowApiResponse, WorkflowRunApiResponse } from "@/api/types"; import { StatusBadge } from "@/components/StatusBadge"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Pagination, @@ -37,10 +38,10 @@ import { import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useNavigate, useSearchParams } from "react-router-dom"; import { stringify as convertToYAML } from "yaml"; +import { ImportWorkflowButton } from "./ImportWorkflowButton"; import { WorkflowCreateYAMLRequest } from "./types/workflowYamlTypes"; -import { WorkflowTitle } from "./WorkflowTitle"; -import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { WorkflowActions } from "./WorkflowActions"; +import { WorkflowTitle } from "./WorkflowTitle"; const emptyWorkflowRequest: WorkflowCreateYAMLRequest = { title: "New Workflow", @@ -178,19 +179,22 @@ function Workflows() {

Workflows

- +
+ + +