Skip to content

Commit

Permalink
feat: delete resource with confirm modal
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Sep 9, 2021
1 parent c617374 commit bd7d65b
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/components/molecules/NavigatorRowLabel/ActionsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
import React from 'react';
import {Menu} from 'antd';
import {Menu, Modal} from 'antd';
import {K8sResource} from '@models/k8sresource';
import {useAppDispatch} from '@redux/hooks';
import {removeResource} from '@redux/reducers/main';
import {AppDispatch} from '@redux/store';
import {ExclamationCircleOutlined} from '@ant-design/icons';
import {isFileResource} from '@redux/services/resource';

function deleteResourceWithConfirm(resource: K8sResource, dispatch: AppDispatch) {
let title = `Are you sure you want to delete ${resource.name}?`;

if (isFileResource(resource)) {
if (!resource.range) {
title = `This action will delete the ${resource.filePath} file.\n${title}`;
}
} else {
title = `This action will delete the resource from the Cluster.\n${title}`;
}

Modal.confirm({
title,
icon: <ExclamationCircleOutlined />,
onOk() {
return new Promise(resolve => {
dispatch(removeResource(resource.id));
resolve({});
});
},
onCancel() {},
});
}
const ActionsMenu = (props: {resource: K8sResource}) => {
const {resource} = props;
const dispatch = useAppDispatch();

const deleteResource = () => {
dispatch(removeResource(resource.id));
deleteResourceWithConfirm(resource, dispatch);
};

return (
Expand Down

0 comments on commit bd7d65b

Please sign in to comment.