mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
Alerting: Fix notification route removal (#48774)
* Fix notification route removal * fix tests Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
This commit is contained in:
parent
454e804657
commit
ee8e125134
@ -166,7 +166,7 @@ describe('deleteRoute', () => {
|
||||
const routeToDelete = routes[1];
|
||||
|
||||
// Act
|
||||
const updatedRoutes = deleteRoute(routes, routeToDelete);
|
||||
const updatedRoutes = deleteRoute(routes, routeToDelete.id);
|
||||
|
||||
// Assert
|
||||
expect(updatedRoutes).toHaveLength(2);
|
||||
@ -179,7 +179,7 @@ describe('deleteRoute', () => {
|
||||
const routes: FormAmRoute[] = [buildAmRoute({ id: '1' }), buildAmRoute({ id: '2' }), buildAmRoute({ id: '3' })];
|
||||
|
||||
// Act
|
||||
const updatedRoutes = deleteRoute(routes, buildAmRoute({ id: '-1' }));
|
||||
const updatedRoutes = deleteRoute(routes, '-1');
|
||||
|
||||
// Assert
|
||||
expect(updatedRoutes).toHaveLength(3);
|
||||
|
@ -63,8 +63,8 @@ export const updatedRoute = (routes: FormAmRoute[], updatedRoute: FormAmRoute):
|
||||
return newRoutes;
|
||||
};
|
||||
|
||||
export const deleteRoute = (routes: FormAmRoute[], routeToRemove: FormAmRoute): FormAmRoute[] => {
|
||||
return routes.filter((route) => route.id !== routeToRemove.id);
|
||||
export const deleteRoute = (routes: FormAmRoute[], routeId: string): FormAmRoute[] => {
|
||||
return routes.filter((route) => route.id !== routeId);
|
||||
};
|
||||
|
||||
export const AmRoutesTable: FC<AmRoutesTableProps> = ({
|
||||
@ -78,7 +78,7 @@ export const AmRoutesTable: FC<AmRoutesTableProps> = ({
|
||||
alertManagerSourceName,
|
||||
}) => {
|
||||
const [editMode, setEditMode] = useState(false);
|
||||
const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false);
|
||||
const [deletingRouteId, setDeletingRouteId] = useState<string | undefined>(undefined);
|
||||
const [expandedId, setExpandedId] = useState<string | number>();
|
||||
const permissions = getNotificationsPermissions(alertManagerSourceName);
|
||||
const canEditRoutes = contextSrv.hasPermission(permissions.update);
|
||||
@ -155,23 +155,11 @@ export const AmRoutesTable: FC<AmRoutesTableProps> = ({
|
||||
aria-label="Delete route"
|
||||
name="trash-alt"
|
||||
onClick={() => {
|
||||
setShowDeleteModal(true);
|
||||
setDeletingRouteId(item.data.id);
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
</HorizontalGroup>
|
||||
<ConfirmModal
|
||||
isOpen={showDeleteModal}
|
||||
title="Delete notification policy"
|
||||
body="Deleting this notification policy will permanently remove it. Are you sure you want to delete this policy?"
|
||||
confirmText="Yes, delete"
|
||||
icon="exclamation-triangle"
|
||||
onConfirm={() => {
|
||||
const newRoutes = deleteRoute(routes, item.data);
|
||||
onChange(newRoutes);
|
||||
}}
|
||||
onDismiss={() => setShowDeleteModal(false)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
@ -209,6 +197,7 @@ export const AmRoutesTable: FC<AmRoutesTableProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<DynamicTable
|
||||
cols={cols}
|
||||
isExpandable={true}
|
||||
@ -249,5 +238,21 @@ export const AmRoutesTable: FC<AmRoutesTableProps> = ({
|
||||
)
|
||||
}
|
||||
/>
|
||||
<ConfirmModal
|
||||
isOpen={!!deletingRouteId}
|
||||
title="Delete notification policy"
|
||||
body="Deleting this notification policy will permanently remove it. Are you sure you want to delete this policy?"
|
||||
confirmText="Yes, delete"
|
||||
icon="exclamation-triangle"
|
||||
onConfirm={() => {
|
||||
if (deletingRouteId) {
|
||||
const newRoutes = deleteRoute(routes, deletingRouteId);
|
||||
onChange(newRoutes);
|
||||
setDeletingRouteId(undefined);
|
||||
}
|
||||
}}
|
||||
onDismiss={() => setDeletingRouteId(undefined)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user