Skip to content

Commit a50348e

Browse files
authored
add UI for delete endpoint (#147)
1 parent d062298 commit a50348e

File tree

2 files changed

+104
-20
lines changed

2 files changed

+104
-20
lines changed

frontend/src/api/endpoints/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@ export const deleteHost = async (
120120
})
121121
return resp.data
122122
}
123+
124+
export const deleteEndpoint = async (
125+
endpointId: string,
126+
headers?: AxiosRequestHeaders,
127+
): Promise<any> => {
128+
const resp = await axios.delete(`${getAPIURL()}/endpoint/${endpointId}`, {
129+
headers,
130+
})
131+
return resp.data
132+
}

frontend/src/components/Endpoint/index.tsx

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React, { useState } from "react"
22
import NextLink from "next/link"
33
import { BiInfoCircle } from "@react-icons/all-files/bi/BiInfoCircle"
44
import { BsSearch } from "@react-icons/all-files/bs/BsSearch"
@@ -18,6 +18,15 @@ import {
1818
Tab,
1919
TabPanels,
2020
TabPanel,
21+
Button,
22+
useDisclosure,
23+
AlertDialog,
24+
AlertDialogOverlay,
25+
AlertDialogContent,
26+
AlertDialogHeader,
27+
AlertDialogBody,
28+
AlertDialogFooter,
29+
useToast,
2130
} from "@chakra-ui/react"
2231
import { useRouter } from "next/router"
2332
import { SectionHeader } from "components/utils/Card"
@@ -33,6 +42,8 @@ import TraceList from "./TraceList"
3342
import { AlertTab } from "./AlertTab"
3443
import EndpointOverview from "./Overview"
3544
import TestList from "./TestList"
45+
import { deleteEndpoint } from "api/endpoints"
46+
import { makeToast } from "utils"
3647

3748
interface EndpointPageProps {
3849
endpoint: ApiEndpointDetailed
@@ -49,6 +60,10 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
4960
"rgb(179, 181, 185)",
5061
"rgb(91, 94, 109)",
5162
)
63+
const [deleting, setDeleting] = useState<boolean>(false)
64+
const { isOpen, onOpen, onClose } = useDisclosure()
65+
const cancelRef = React.useRef()
66+
const toast = useToast()
5267
const { tab, uuid } = router.query
5368
const getDefaultTab = () => {
5469
switch (tab) {
@@ -67,6 +82,27 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
6782
}
6883
}
6984

85+
const handleEndpointDelete = async () => {
86+
try {
87+
setDeleting(true)
88+
await deleteEndpoint(endpoint.uuid)
89+
router.push("/endpoints")
90+
} catch (err) {
91+
toast(
92+
makeToast(
93+
{
94+
title: "Deleting endpoint failed...",
95+
status: "error",
96+
description: err.response?.data,
97+
},
98+
err.response?.status,
99+
),
100+
)
101+
} finally {
102+
setDeleting(false)
103+
}
104+
}
105+
70106
return (
71107
<VStack
72108
w="full"
@@ -75,25 +111,32 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
75111
h="100vh"
76112
overflow="hidden"
77113
>
78-
<VStack alignItems="flex-start" pt="6" px="6">
79-
<NextLink href="/endpoints">
80-
<HStack color={headerColor} spacing="1" cursor="pointer">
81-
<TiFlowSwitch />
82-
<Text fontWeight="semibold">Endpoints</Text>
83-
</HStack>
84-
</NextLink>
85-
<HStack spacing="4" pb="6">
86-
<Badge
87-
fontSize="xl"
88-
px="2"
89-
py="1"
90-
colorScheme={METHOD_TO_COLOR[endpoint?.method] || "gray"}
91-
>
92-
{endpoint?.method.toUpperCase()}
93-
</Badge>
94-
<Code fontSize="xl" fontWeight="semibold" p="1">
95-
{endpoint.path}
96-
</Code>
114+
<VStack w="full" alignItems="flex-start" pt="6" px="6">
115+
<HStack w="full" justifyContent="space-between">
116+
<VStack alignItems="flex-start">
117+
<NextLink href="/endpoints">
118+
<HStack color={headerColor} spacing="1" cursor="pointer">
119+
<TiFlowSwitch />
120+
<Text fontWeight="semibold">Endpoints</Text>
121+
</HStack>
122+
</NextLink>
123+
<HStack spacing="4" pb="6">
124+
<Badge
125+
fontSize="xl"
126+
px="2"
127+
py="1"
128+
colorScheme={METHOD_TO_COLOR[endpoint?.method] || "gray"}
129+
>
130+
{endpoint?.method.toUpperCase()}
131+
</Badge>
132+
<Code fontSize="xl" fontWeight="semibold" p="1">
133+
{endpoint.path}
134+
</Code>
135+
</HStack>
136+
</VStack>
137+
<Button colorScheme="red" isLoading={deleting} onClick={onOpen}>
138+
Delete
139+
</Button>
97140
</HStack>
98141
</VStack>
99142
<Tabs
@@ -148,6 +191,37 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
148191
</TabPanel>
149192
</TabPanels>
150193
</Tabs>
194+
<AlertDialog
195+
isOpen={isOpen}
196+
leastDestructiveRef={cancelRef}
197+
onClose={onClose}
198+
>
199+
<AlertDialogOverlay>
200+
<AlertDialogContent>
201+
<AlertDialogHeader fontSize="lg" fontWeight="bold">
202+
Delete Endpoint
203+
</AlertDialogHeader>
204+
205+
<AlertDialogBody>
206+
Are you sure you want to delete this endpoint?
207+
</AlertDialogBody>
208+
209+
<AlertDialogFooter>
210+
<Button ref={cancelRef} onClick={onClose}>
211+
Cancel
212+
</Button>
213+
<Button
214+
isLoading={deleting}
215+
colorScheme="red"
216+
onClick={handleEndpointDelete}
217+
ml={3}
218+
>
219+
Delete
220+
</Button>
221+
</AlertDialogFooter>
222+
</AlertDialogContent>
223+
</AlertDialogOverlay>
224+
</AlertDialog>
151225
</VStack>
152226
)
153227
},

0 commit comments

Comments
 (0)