From 4800fe4f0a931693feaa9b5118b8c0c091df0b26 Mon Sep 17 00:00:00 2001 From: Kerem Yilmaz Date: Tue, 10 Sep 2024 11:30:48 -0700 Subject: [PATCH] Add delete action in workflows table (#802) Co-authored-by: Muhammed Salih Altun --- .../src/components/icons/GarbageIcon.tsx | 2 +- .../src/routes/workflows/Workflows.tsx | 33 ++----- .../workflows/WorkflowsBetaAlertCard.tsx | 37 -------- .../workflows/editor/DeleteWorkflowButton.tsx | 94 +++++++++++++++++++ 4 files changed, 101 insertions(+), 65 deletions(-) delete mode 100644 skyvern-frontend/src/routes/workflows/WorkflowsBetaAlertCard.tsx create mode 100644 skyvern-frontend/src/routes/workflows/editor/DeleteWorkflowButton.tsx diff --git a/skyvern-frontend/src/components/icons/GarbageIcon.tsx b/skyvern-frontend/src/components/icons/GarbageIcon.tsx index a250203a..aac716ac 100644 --- a/skyvern-frontend/src/components/icons/GarbageIcon.tsx +++ b/skyvern-frontend/src/components/icons/GarbageIcon.tsx @@ -1,5 +1,5 @@ type Props = { - className: string; + className?: string; }; function GarbageIcon({ className }: Props) { diff --git a/skyvern-frontend/src/routes/workflows/Workflows.tsx b/skyvern-frontend/src/routes/workflows/Workflows.tsx index 6dabc621..79b459be 100644 --- a/skyvern-frontend/src/routes/workflows/Workflows.tsx +++ b/skyvern-frontend/src/routes/workflows/Workflows.tsx @@ -28,7 +28,6 @@ import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { basicTimeFormat } from "@/util/timeFormat"; import { cn } from "@/util/utils"; import { - CounterClockwiseClockIcon, Pencil2Icon, PlayIcon, PlusIcon, @@ -36,10 +35,10 @@ import { } from "@radix-ui/react-icons"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useNavigate, useSearchParams } from "react-router-dom"; -import { WorkflowsBetaAlertCard } from "./WorkflowsBetaAlertCard"; -import { WorkflowTitle } from "./WorkflowTitle"; -import { WorkflowCreateYAMLRequest } from "./types/workflowYamlTypes"; import { stringify as convertToYAML } from "yaml"; +import { DeleteWorkflowButton } from "./editor/DeleteWorkflowButton"; +import { WorkflowCreateYAMLRequest } from "./types/workflowYamlTypes"; +import { WorkflowTitle } from "./WorkflowTitle"; const emptyWorkflowRequest: WorkflowCreateYAMLRequest = { title: "New Workflow", @@ -114,10 +113,6 @@ function Workflows() { }, }); - if (workflows?.length === 0 && workflowsPage === 1) { - return ; - } - function handleRowClick( event: React.MouseEvent, workflowPermanentId: string, @@ -215,25 +210,6 @@ function Workflows() {
- - - - - - View Past Runs - - @@ -272,6 +248,9 @@ function Workflows() { Create New Run +
diff --git a/skyvern-frontend/src/routes/workflows/WorkflowsBetaAlertCard.tsx b/skyvern-frontend/src/routes/workflows/WorkflowsBetaAlertCard.tsx deleted file mode 100644 index 44ccb297..00000000 --- a/skyvern-frontend/src/routes/workflows/WorkflowsBetaAlertCard.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { Button } from "@/components/ui/button"; - -function WorkflowsBetaAlertCard() { - return ( -
-
-

Workflows (Beta)

-
-
Workflows through UI are currently under construction.
-
- Today, you can create and run workflows through the Skyvern API. -
- -
- ); -} - -export { WorkflowsBetaAlertCard }; diff --git a/skyvern-frontend/src/routes/workflows/editor/DeleteWorkflowButton.tsx b/skyvern-frontend/src/routes/workflows/editor/DeleteWorkflowButton.tsx new file mode 100644 index 00000000..5bd7bdbd --- /dev/null +++ b/skyvern-frontend/src/routes/workflows/editor/DeleteWorkflowButton.tsx @@ -0,0 +1,94 @@ +import { getClient } from "@/api/AxiosClient"; +import { GarbageIcon } from "@/components/icons/GarbageIcon"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { toast } from "@/components/ui/use-toast"; +import { useCredentialGetter } from "@/hooks/useCredentialGetter"; +import { ReloadIcon } from "@radix-ui/react-icons"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { AxiosError } from "axios"; + +type Props = { + id: string; +}; + +function DeleteWorkflowButton({ id }: Props) { + const credentialGetter = useCredentialGetter(); + const queryClient = useQueryClient(); + + const deleteWorkflowMutation = useMutation({ + mutationFn: async (id: string) => { + const client = await getClient(credentialGetter); + return client.delete(`/workflows/${id}`); + }, + onSuccess: () => { + queryClient.invalidateQueries({ + queryKey: ["workflows"], + }); + }, + onError: (error: AxiosError) => { + toast({ + variant: "destructive", + title: "Failed to delete workflow", + description: error.message, + }); + }, + }); + + return ( + + + + + + + + + Delete Workflow + + + e.preventDefault()}> + + Are you sure? + This workflow will be deleted. + + + + + + + + + + ); +} + +export { DeleteWorkflowButton };