From 860d8c6b78cecac5f1d86ed895cf4f309ee3aa7b Mon Sep 17 00:00:00 2001 From: Prakash Senthil Vel <23444145+prakashsvmx@users.noreply.github.com> Date: Thu, 18 Aug 2022 02:10:37 +0530 Subject: [PATCH] UI to delete configured notification targets (#2213) --- .../ConfirmDeleteTargetModal.tsx | 39 ++++++++++++ .../ListNotificationEndpoints.tsx | 60 ++++++++++++++++++- .../Console/NotificationEndpoints/types.ts | 2 + .../Console/NotificationEndpoints/utils.ts | 19 ++++++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 portal-ui/src/screens/Console/NotificationEndpoints/ConfirmDeleteTargetModal.tsx diff --git a/portal-ui/src/screens/Console/NotificationEndpoints/ConfirmDeleteTargetModal.tsx b/portal-ui/src/screens/Console/NotificationEndpoints/ConfirmDeleteTargetModal.tsx new file mode 100644 index 000000000..4df69de45 --- /dev/null +++ b/portal-ui/src/screens/Console/NotificationEndpoints/ConfirmDeleteTargetModal.tsx @@ -0,0 +1,39 @@ +import React from "react"; +import ConfirmDialog from "../Common/ModalWrapper/ConfirmDialog"; +import { ConfirmModalIcon } from "../../../icons"; +import { DialogContentText } from "@mui/material"; + +const ConfirmDeleteTargetModal = ({ + onConfirm, + onClose, + serviceName, + status, +}: { + onConfirm: () => void; + onClose: () => void; + serviceName: string; + status: string; +}) => { + return ( + } + isLoading={false} + onConfirm={onConfirm} + onClose={onClose} + confirmationContent={ + + + Are you sure you want to delete the notification endpoint ? +
+ {serviceName} which is {status} +
+
+ } + /> + ); +}; + +export default ConfirmDeleteTargetModal; diff --git a/portal-ui/src/screens/Console/NotificationEndpoints/ListNotificationEndpoints.tsx b/portal-ui/src/screens/Console/NotificationEndpoints/ListNotificationEndpoints.tsx index cfa64568d..0c5575904 100644 --- a/portal-ui/src/screens/Console/NotificationEndpoints/ListNotificationEndpoints.tsx +++ b/portal-ui/src/screens/Console/NotificationEndpoints/ListNotificationEndpoints.tsx @@ -29,7 +29,7 @@ import { NotificationEndpointsList, TransformedEndpointItem, } from "./types"; -import { notificationTransform } from "./utils"; +import { getNotificationConfigKey, notificationTransform } from "./utils"; import { AddIcon, LambdaIcon } from "../../../icons"; import TableWrapper from "../Common/TableWrapper/TableWrapper"; @@ -49,8 +49,12 @@ import PageLayout from "../Common/Layout/PageLayout"; import SearchBox from "../Common/SearchBox"; import RBIconButton from "../Buckets/BucketDetails/SummaryItems/RBIconButton"; import { IAM_PAGES } from "../../../common/SecureComponent/permissions"; -import { setErrorSnackMessage } from "../../../systemSlice"; +import { + setErrorSnackMessage, + setServerNeedsRestart, +} from "../../../systemSlice"; import { useAppDispatch } from "../../../store"; +import ConfirmDeleteTargetModal from "./ConfirmDeleteTargetModal"; interface IListNotificationEndpoints { classes: any; @@ -88,6 +92,10 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => { const [filter, setFilter] = useState(""); const [isLoading, setIsLoading] = useState(false); + const [isDelConfirmOpen, setIsDelConfirmOpen] = useState(false); + const [selNotifyEndPoint, setSelNotifyEndpoint] = + useState(); + //Effects // load records on mount useEffect(() => { @@ -116,6 +124,39 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => { setIsLoading(true); }, []); + const resetNotificationConfig = ( + ep: TransformedEndpointItem | undefined | null + ) => { + if (ep?.name) { + const configKey = getNotificationConfigKey(ep.name); + let accountId = `:${ep.account_id}`; + if (configKey) { + api + .invoke("POST", `/api/v1/configs/${configKey}${accountId}/reset`) + .then((res) => { + dispatch(setServerNeedsRestart(true)); + setSelNotifyEndpoint(null); + setIsDelConfirmOpen(false); + }) + .catch((err: ErrorResponseHandler) => { + setIsDelConfirmOpen(false); + dispatch(setErrorSnackMessage(err)); + }); + } else { + setSelNotifyEndpoint(null); + setIsDelConfirmOpen(false); + console.log(`Unable to find Config key for ${ep.name}`); + } + } + }; + + const confirmDelNotifyEndpoint = (record: TransformedEndpointItem) => { + setSelNotifyEndpoint(record); + setIsDelConfirmOpen(true); + }; + + const tableActions = [{ type: "delete", onClick: confirmDelNotifyEndpoint }]; + const filteredRecords = records.filter((b: TransformedEndpointItem) => { if (filter === "") { return true; @@ -180,7 +221,7 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => { { )} )} + + {isDelConfirmOpen ? ( + { + resetNotificationConfig(selNotifyEndPoint); + }} + status={`${selNotifyEndPoint?.status}`} + serviceName={`${selNotifyEndPoint?.service_name}`} + onClose={() => { + setIsDelConfirmOpen(false); + }} + /> + ) : null} ); diff --git a/portal-ui/src/screens/Console/NotificationEndpoints/types.ts b/portal-ui/src/screens/Console/NotificationEndpoints/types.ts index e856524ae..a752839a7 100644 --- a/portal-ui/src/screens/Console/NotificationEndpoints/types.ts +++ b/portal-ui/src/screens/Console/NotificationEndpoints/types.ts @@ -29,6 +29,8 @@ export interface NotificationEndpointItem { export interface TransformedEndpointItem { service_name: string; status: string; + name: string; + account_id: string; } export interface NotificationEndpointsList { diff --git a/portal-ui/src/screens/Console/NotificationEndpoints/utils.ts b/portal-ui/src/screens/Console/NotificationEndpoints/utils.ts index bc7ecf17a..322c1bb45 100644 --- a/portal-ui/src/screens/Console/NotificationEndpoints/utils.ts +++ b/portal-ui/src/screens/Console/NotificationEndpoints/utils.ts @@ -35,6 +35,8 @@ export const notificationTransform = ( return notificationElements.map((element) => { return { service_name: `${element.service}:${element.account_id}`, + name: element.service, + account_id: element.account_id, status: element.status, }; }); @@ -558,3 +560,20 @@ export const notificationEndpointsFields: any = { ...commonFields, ], }; + +const serviceToConfigMap: Record = { + webhook: "notify_webhook", + amqp: "notify_amqp", + kafka: "notify_kafka", + mqtt: "notify_mqtt", + nats: "notify_nats", + nsq: "notify_nsq", + mysql: "notify_mysql", + postgresql: "notify_postgres", //looks different in server response(postgresql as opposed to postgres) from restapi/admin_notification_endpoints.go + elasticsearch: "notify_elasticsearch", + redis: "notify_redis", +}; + +export const getNotificationConfigKey = (serviceName: string) => { + return serviceToConfigMap[serviceName]; +};