2022-04-04 17:35:44 +05:30
|
|
|
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Modal } from 'antd';
|
2023-08-08 14:09:32 +03:00
|
|
|
import { useCallback } from 'react';
|
2021-09-23 15:43:43 +05:30
|
|
|
import { connect } from 'react-redux';
|
2022-03-22 12:10:31 +05:30
|
|
|
import { bindActionCreators, Dispatch } from 'redux';
|
2021-09-23 15:43:43 +05:30
|
|
|
import { ThunkDispatch } from 'redux-thunk';
|
|
|
|
|
import { DeleteDashboard, DeleteDashboardProps } from 'store/actions';
|
|
|
|
|
import AppActions from 'types/actions';
|
|
|
|
|
|
|
|
|
|
import { Data } from '../index';
|
2022-03-29 12:24:03 +05:30
|
|
|
import { TableLinkText } from './styles';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2023-09-11 10:51:10 +05:30
|
|
|
function DeleteButton({
|
|
|
|
|
deleteDashboard,
|
|
|
|
|
id,
|
|
|
|
|
refetchDashboardList,
|
|
|
|
|
}: DeleteButtonProps): JSX.Element {
|
2023-08-08 14:09:32 +03:00
|
|
|
const [modal, contextHolder] = Modal.useModal();
|
|
|
|
|
|
|
|
|
|
const openConfirmationDialog = useCallback((): void => {
|
|
|
|
|
modal.confirm({
|
2022-04-04 17:35:44 +05:30
|
|
|
title: 'Do you really want to delete this dashboard?',
|
|
|
|
|
icon: <ExclamationCircleOutlined style={{ color: '#e42b35' }} />,
|
|
|
|
|
onOk() {
|
|
|
|
|
deleteDashboard({
|
|
|
|
|
uuid: id,
|
2023-09-11 10:51:10 +05:30
|
|
|
refetch: refetchDashboardList,
|
2022-04-04 17:35:44 +05:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
okText: 'Delete',
|
|
|
|
|
okButtonProps: { danger: true },
|
|
|
|
|
centered: true,
|
2021-09-23 15:43:43 +05:30
|
|
|
});
|
2023-09-11 10:51:10 +05:30
|
|
|
}, [modal, deleteDashboard, id, refetchDashboardList]);
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2022-04-04 17:35:44 +05:30
|
|
|
return (
|
2023-08-08 14:09:32 +03:00
|
|
|
<>
|
|
|
|
|
<TableLinkText type="danger" onClick={openConfirmationDialog}>
|
|
|
|
|
Delete
|
|
|
|
|
</TableLinkText>
|
|
|
|
|
|
|
|
|
|
{contextHolder}
|
|
|
|
|
</>
|
2022-04-04 17:35:44 +05:30
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
interface DispatchProps {
|
|
|
|
|
deleteDashboard: ({
|
|
|
|
|
uuid,
|
|
|
|
|
}: DeleteDashboardProps) => (dispatch: Dispatch<AppActions>) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (
|
|
|
|
|
dispatch: ThunkDispatch<unknown, unknown, AppActions>,
|
|
|
|
|
): DispatchProps => ({
|
|
|
|
|
deleteDashboard: bindActionCreators(DeleteDashboard, dispatch),
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-11 10:51:10 +05:30
|
|
|
export type DeleteButtonProps = Data & DispatchProps;
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
const WrapperDeleteButton = connect(null, mapDispatchToProps)(DeleteButton);
|
|
|
|
|
|
|
|
|
|
// This is to avoid the type collision
|
2022-03-22 12:10:31 +05:30
|
|
|
function Wrapper(props: Data): JSX.Element {
|
2023-09-11 10:51:10 +05:30
|
|
|
const {
|
|
|
|
|
createdBy,
|
|
|
|
|
description,
|
|
|
|
|
id,
|
|
|
|
|
key,
|
|
|
|
|
refetchDashboardList,
|
|
|
|
|
lastUpdatedTime,
|
|
|
|
|
name,
|
|
|
|
|
tags,
|
|
|
|
|
} = props;
|
2022-03-24 12:06:57 +05:30
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
return (
|
|
|
|
|
<WrapperDeleteButton
|
|
|
|
|
{...{
|
2022-03-24 12:06:57 +05:30
|
|
|
createdBy,
|
|
|
|
|
description,
|
|
|
|
|
id,
|
|
|
|
|
key,
|
|
|
|
|
lastUpdatedTime,
|
|
|
|
|
name,
|
|
|
|
|
tags,
|
2023-09-11 10:51:10 +05:30
|
|
|
refetchDashboardList,
|
2021-09-23 15:43:43 +05:30
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
export default Wrapper;
|