Skip to content

Commit 860d8c6

Browse files
authored
UI to delete configured notification targets (#2213)
1 parent 9996580 commit 860d8c6

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from "react";
2+
import ConfirmDialog from "../Common/ModalWrapper/ConfirmDialog";
3+
import { ConfirmModalIcon } from "../../../icons";
4+
import { DialogContentText } from "@mui/material";
5+
6+
const ConfirmDeleteTargetModal = ({
7+
onConfirm,
8+
onClose,
9+
serviceName,
10+
status,
11+
}: {
12+
onConfirm: () => void;
13+
onClose: () => void;
14+
serviceName: string;
15+
status: string;
16+
}) => {
17+
return (
18+
<ConfirmDialog
19+
title={`Delete Endpoint`}
20+
confirmText={"Delete"}
21+
isOpen={true}
22+
titleIcon={<ConfirmModalIcon />}
23+
isLoading={false}
24+
onConfirm={onConfirm}
25+
onClose={onClose}
26+
confirmationContent={
27+
<React.Fragment>
28+
<DialogContentText>
29+
Are you sure you want to delete the notification endpoint ?
30+
<br />
31+
<b>{serviceName}</b> which is <b>{status}</b>
32+
</DialogContentText>
33+
</React.Fragment>
34+
}
35+
/>
36+
);
37+
};
38+
39+
export default ConfirmDeleteTargetModal;

portal-ui/src/screens/Console/NotificationEndpoints/ListNotificationEndpoints.tsx

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
NotificationEndpointsList,
3030
TransformedEndpointItem,
3131
} from "./types";
32-
import { notificationTransform } from "./utils";
32+
import { getNotificationConfigKey, notificationTransform } from "./utils";
3333
import { AddIcon, LambdaIcon } from "../../../icons";
3434
import TableWrapper from "../Common/TableWrapper/TableWrapper";
3535

@@ -49,8 +49,12 @@ import PageLayout from "../Common/Layout/PageLayout";
4949
import SearchBox from "../Common/SearchBox";
5050
import RBIconButton from "../Buckets/BucketDetails/SummaryItems/RBIconButton";
5151
import { IAM_PAGES } from "../../../common/SecureComponent/permissions";
52-
import { setErrorSnackMessage } from "../../../systemSlice";
52+
import {
53+
setErrorSnackMessage,
54+
setServerNeedsRestart,
55+
} from "../../../systemSlice";
5356
import { useAppDispatch } from "../../../store";
57+
import ConfirmDeleteTargetModal from "./ConfirmDeleteTargetModal";
5458

5559
interface IListNotificationEndpoints {
5660
classes: any;
@@ -88,6 +92,10 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
8892
const [filter, setFilter] = useState<string>("");
8993
const [isLoading, setIsLoading] = useState<boolean>(false);
9094

95+
const [isDelConfirmOpen, setIsDelConfirmOpen] = useState<boolean>(false);
96+
const [selNotifyEndPoint, setSelNotifyEndpoint] =
97+
useState<TransformedEndpointItem | null>();
98+
9199
//Effects
92100
// load records on mount
93101
useEffect(() => {
@@ -116,6 +124,39 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
116124
setIsLoading(true);
117125
}, []);
118126

127+
const resetNotificationConfig = (
128+
ep: TransformedEndpointItem | undefined | null
129+
) => {
130+
if (ep?.name) {
131+
const configKey = getNotificationConfigKey(ep.name);
132+
let accountId = `:${ep.account_id}`;
133+
if (configKey) {
134+
api
135+
.invoke("POST", `/api/v1/configs/${configKey}${accountId}/reset`)
136+
.then((res) => {
137+
dispatch(setServerNeedsRestart(true));
138+
setSelNotifyEndpoint(null);
139+
setIsDelConfirmOpen(false);
140+
})
141+
.catch((err: ErrorResponseHandler) => {
142+
setIsDelConfirmOpen(false);
143+
dispatch(setErrorSnackMessage(err));
144+
});
145+
} else {
146+
setSelNotifyEndpoint(null);
147+
setIsDelConfirmOpen(false);
148+
console.log(`Unable to find Config key for ${ep.name}`);
149+
}
150+
}
151+
};
152+
153+
const confirmDelNotifyEndpoint = (record: TransformedEndpointItem) => {
154+
setSelNotifyEndpoint(record);
155+
setIsDelConfirmOpen(true);
156+
};
157+
158+
const tableActions = [{ type: "delete", onClick: confirmDelNotifyEndpoint }];
159+
119160
const filteredRecords = records.filter((b: TransformedEndpointItem) => {
120161
if (filter === "") {
121162
return true;
@@ -180,7 +221,7 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
180221
<Fragment>
181222
<Grid item xs={12} className={classes.tableBlock}>
182223
<TableWrapper
183-
itemActions={[]}
224+
itemActions={tableActions}
184225
columns={[
185226
{
186227
label: "Status",
@@ -262,6 +303,19 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
262303
)}
263304
</Fragment>
264305
)}
306+
307+
{isDelConfirmOpen ? (
308+
<ConfirmDeleteTargetModal
309+
onConfirm={() => {
310+
resetNotificationConfig(selNotifyEndPoint);
311+
}}
312+
status={`${selNotifyEndPoint?.status}`}
313+
serviceName={`${selNotifyEndPoint?.service_name}`}
314+
onClose={() => {
315+
setIsDelConfirmOpen(false);
316+
}}
317+
/>
318+
) : null}
265319
</PageLayout>
266320
</Fragment>
267321
);

portal-ui/src/screens/Console/NotificationEndpoints/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface NotificationEndpointItem {
2929
export interface TransformedEndpointItem {
3030
service_name: string;
3131
status: string;
32+
name: string;
33+
account_id: string;
3234
}
3335

3436
export interface NotificationEndpointsList {

portal-ui/src/screens/Console/NotificationEndpoints/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const notificationTransform = (
3535
return notificationElements.map((element) => {
3636
return {
3737
service_name: `${element.service}:${element.account_id}`,
38+
name: element.service,
39+
account_id: element.account_id,
3840
status: element.status,
3941
};
4042
});
@@ -558,3 +560,20 @@ export const notificationEndpointsFields: any = {
558560
...commonFields,
559561
],
560562
};
563+
564+
const serviceToConfigMap: Record<string, string> = {
565+
webhook: "notify_webhook",
566+
amqp: "notify_amqp",
567+
kafka: "notify_kafka",
568+
mqtt: "notify_mqtt",
569+
nats: "notify_nats",
570+
nsq: "notify_nsq",
571+
mysql: "notify_mysql",
572+
postgresql: "notify_postgres", //looks different in server response(postgresql as opposed to postgres) from restapi/admin_notification_endpoints.go
573+
elasticsearch: "notify_elasticsearch",
574+
redis: "notify_redis",
575+
};
576+
577+
export const getNotificationConfigKey = (serviceName: string) => {
578+
return serviceToConfigMap[serviceName];
579+
};

0 commit comments

Comments
 (0)