This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'delete volume' similar to delete table (#56)
- Loading branch information
Showing
4 changed files
with
196 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Modal, Typography } from 'antd'; | ||
import React, { useCallback } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useDeleteVolume } from '../../hooks/volumes'; | ||
import { useNotification } from '../../utils/NotificationContext'; | ||
|
||
interface DeleteVolumeModalProps { | ||
open: boolean; | ||
closeModal: () => void; | ||
catalog: string; | ||
schema: string; | ||
volume: string; | ||
} | ||
|
||
export function DeleteVolumeModal({ | ||
open, | ||
closeModal, | ||
catalog, | ||
schema, | ||
volume, | ||
}: DeleteVolumeModalProps) { | ||
const navigate = useNavigate(); | ||
const { setNotification } = useNotification(); | ||
const mutation = useDeleteVolume({ | ||
onSuccessCallback: () => { | ||
setNotification(`${volume} volume successfully deleted`, 'success'); | ||
navigate(`/data/${catalog}/${schema}`); | ||
}, | ||
catalog, | ||
schema, | ||
}); | ||
|
||
const handleSubmit = useCallback(() => { | ||
mutation.mutate( | ||
{ catalog_name: catalog, schema_name: schema, name: volume }, | ||
{ | ||
onError: (error: Error) => { | ||
setNotification(error.message, 'error'); | ||
}, | ||
}, | ||
); | ||
}, [mutation, volume, setNotification]); | ||
|
||
return ( | ||
<Modal | ||
title={ | ||
<Typography.Title type={'danger'} level={4}> | ||
Delete volume | ||
</Typography.Title> | ||
} | ||
okText="Delete" | ||
okType="danger" | ||
cancelText="Cancel" | ||
open={open} | ||
destroyOnClose | ||
onCancel={closeModal} | ||
onOk={handleSubmit} | ||
okButtonProps={{ loading: mutation.isPending }} | ||
> | ||
<Typography.Text> | ||
Are you sure you want to delete the volume | ||
</Typography.Text> | ||
<Typography.Text strong>{` ${volume}`}</Typography.Text> | ||
<Typography.Text>? This operation cannot be undone.</Typography.Text> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { DeleteOutlined, MoreOutlined } from '@ant-design/icons'; | ||
import { Button, Dropdown, MenuProps } from 'antd'; | ||
import { useMemo, useState } from 'react'; | ||
import { DeleteVolumeModal } from '../modals/DeleteVolumeModal'; | ||
|
||
interface VolumeActionDropdownProps { | ||
catalog: string; | ||
schema: string; | ||
volume: string; | ||
} | ||
|
||
enum VolumeActionsEnum { | ||
Delete, | ||
} | ||
|
||
export default function VolumeActionsDropdown({ | ||
catalog, | ||
schema, | ||
volume, | ||
}: VolumeActionDropdownProps) { | ||
const [dropdownVisible, setDropdownVisible] = useState<boolean>(false); | ||
const [action, setAction] = useState<VolumeActionsEnum | null>(null); | ||
|
||
const menuItems = useMemo( | ||
(): MenuProps['items'] => [ | ||
{ | ||
key: 'deleteVolume', | ||
label: 'Delete Volume', | ||
onClick: () => setAction(VolumeActionsEnum.Delete), | ||
icon: <DeleteOutlined />, | ||
danger: true, | ||
}, | ||
], | ||
[], | ||
); | ||
|
||
return ( | ||
<> | ||
<Dropdown | ||
menu={{ items: menuItems }} | ||
trigger={['click']} | ||
onOpenChange={() => setDropdownVisible(!dropdownVisible)} | ||
> | ||
<Button | ||
type="text" | ||
icon={ | ||
<MoreOutlined | ||
rotate={dropdownVisible ? 90 : 0} | ||
style={{ transition: 'transform 0.5s' }} | ||
/> | ||
} | ||
/> | ||
</Dropdown> | ||
<DeleteVolumeModal | ||
open={action === VolumeActionsEnum.Delete} | ||
closeModal={() => setAction(null)} | ||
catalog={catalog} | ||
schema={schema} | ||
volume={volume} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters