From 7a42df26b257e644204a87ade0790b4630db3da5 Mon Sep 17 00:00:00 2001 From: Nikhil Shahi Date: Sun, 27 Nov 2022 15:07:14 -0600 Subject: [PATCH 1/2] add UI for delete endpoint --- frontend/src/api/endpoints/index.ts | 10 ++ frontend/src/components/Endpoint/index.tsx | 114 +++++++++++++++++---- 2 files changed, 104 insertions(+), 20 deletions(-) diff --git a/frontend/src/api/endpoints/index.ts b/frontend/src/api/endpoints/index.ts index 460759aa..ebbbd3ef 100644 --- a/frontend/src/api/endpoints/index.ts +++ b/frontend/src/api/endpoints/index.ts @@ -120,3 +120,13 @@ export const deleteHost = async ( }) return resp.data } + +export const deleteEndpoint = async ( + endpointId: string, + headers?: AxiosRequestHeaders, +): Promise => { + const resp = await axios.delete(`${getAPIURL()}/endpoint/${endpointId}`, { + headers, + }) + return resp.data +} diff --git a/frontend/src/components/Endpoint/index.tsx b/frontend/src/components/Endpoint/index.tsx index 4e1f4c0e..c26eb778 100644 --- a/frontend/src/components/Endpoint/index.tsx +++ b/frontend/src/components/Endpoint/index.tsx @@ -1,4 +1,4 @@ -import React from "react" +import React, { useState } from "react" import NextLink from "next/link" import { BiInfoCircle } from "@react-icons/all-files/bi/BiInfoCircle" import { BsSearch } from "@react-icons/all-files/bs/BsSearch" @@ -18,6 +18,15 @@ import { Tab, TabPanels, TabPanel, + Button, + useDisclosure, + AlertDialog, + AlertDialogOverlay, + AlertDialogContent, + AlertDialogHeader, + AlertDialogBody, + AlertDialogFooter, + useToast, } from "@chakra-ui/react" import { useRouter } from "next/router" import { SectionHeader } from "components/utils/Card" @@ -33,6 +42,8 @@ import TraceList from "./TraceList" import { AlertTab } from "./AlertTab" import EndpointOverview from "./Overview" import TestList from "./TestList" +import { deleteEndpoint } from "api/endpoints" +import { makeToast } from "utils" interface EndpointPageProps { endpoint: ApiEndpointDetailed @@ -49,6 +60,10 @@ const EndpointPage: React.FC = React.memo( "rgb(179, 181, 185)", "rgb(91, 94, 109)", ) + const [deleting, setDeleting] = useState(false) + const { isOpen, onOpen, onClose } = useDisclosure() + const cancelRef = React.useRef() + const toast = useToast() const { tab, uuid } = router.query const getDefaultTab = () => { switch (tab) { @@ -67,6 +82,27 @@ const EndpointPage: React.FC = React.memo( } } + const handleEndpointDelete = async () => { + try { + setDeleting(true) + await deleteEndpoint(endpoint.uuid) + router.push("/endpoints") + } catch (err) { + toast( + makeToast( + { + title: "Deleting endpoint failed...", + status: "error", + description: err.response?.data, + }, + err.response?.status, + ), + ) + } finally { + setDeleting(false) + } + } + return ( = React.memo( h="100vh" overflow="hidden" > - - - - - Endpoints - - - - - {endpoint?.method.toUpperCase()} - - - {endpoint.path} - + + + + + + + Endpoints + + + + + {endpoint?.method.toUpperCase()} + + + {endpoint.path} + + + + = React.memo( + + + + + Delete Host + + + + Are you sure you want to delete this endpoint? + + + + + + + + + ) }, From 004044e5a6f2a3624aa8132f734d08e28df62eef Mon Sep 17 00:00:00 2001 From: Nikhil Shahi Date: Sun, 27 Nov 2022 15:13:15 -0600 Subject: [PATCH 2/2] fix alert dialog text --- frontend/src/components/Endpoint/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Endpoint/index.tsx b/frontend/src/components/Endpoint/index.tsx index c26eb778..b40681bf 100644 --- a/frontend/src/components/Endpoint/index.tsx +++ b/frontend/src/components/Endpoint/index.tsx @@ -199,7 +199,7 @@ const EndpointPage: React.FC = React.memo( - Delete Host + Delete Endpoint