forked from unitycatalog/unitycatalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui] Feat/delete schema (unitycatalog/unitycatalog-ui#61)
* delete schema functionality * prettier
- Loading branch information
1 parent
1efd09d
commit ddd5dbe
Showing
4 changed files
with
165 additions
and
1 deletion.
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,64 @@ | ||
import { Modal, Typography } from 'antd'; | ||
import React, { useCallback } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useNotification } from '../../utils/NotificationContext'; | ||
import { useDeleteSchema } from '../../hooks/schemas'; | ||
|
||
interface DeleteSchemaModalProps { | ||
open: boolean; | ||
closeModal: () => void; | ||
catalog: string; | ||
schema: string; | ||
} | ||
|
||
export function DeleteSchemaModal({ | ||
open, | ||
closeModal, | ||
catalog, | ||
schema, | ||
}: DeleteSchemaModalProps) { | ||
const navigate = useNavigate(); | ||
const { setNotification } = useNotification(); | ||
const mutation = useDeleteSchema({ | ||
onSuccessCallback: () => { | ||
setNotification(`${schema} schema successfully deleted`, 'success'); | ||
navigate(`/data/${catalog}`); | ||
}, | ||
catalog, | ||
}); | ||
|
||
const handleSubmit = useCallback(() => { | ||
mutation.mutate( | ||
{ catalog_name: catalog, name: schema }, | ||
{ | ||
onError: (error: Error) => { | ||
setNotification(error.message, 'error'); | ||
}, | ||
}, | ||
); | ||
}, [mutation, catalog, schema, setNotification]); | ||
|
||
return ( | ||
<Modal | ||
title={ | ||
<Typography.Title type={'danger'} level={4}> | ||
Delete schema | ||
</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 schema | ||
</Typography.Text> | ||
<Typography.Text strong>{` ${schema}`}</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,60 @@ | ||
import { DeleteOutlined, MoreOutlined } from '@ant-design/icons'; | ||
import { Button, Dropdown, MenuProps } from 'antd'; | ||
import { useMemo, useState } from 'react'; | ||
import { DeleteSchemaModal } from '../modals/DeleteSchemaModal'; | ||
|
||
interface SchemaActionDropdownProps { | ||
catalog: string; | ||
schema: string; | ||
} | ||
|
||
enum SchemaActionsEnum { | ||
Delete, | ||
} | ||
|
||
export default function SchemaActionsDropdown({ | ||
catalog, | ||
schema, | ||
}: SchemaActionDropdownProps) { | ||
const [dropdownVisible, setDropdownVisible] = useState<boolean>(false); | ||
const [action, setAction] = useState<SchemaActionsEnum | null>(null); | ||
|
||
const menuItems = useMemo( | ||
(): MenuProps['items'] => [ | ||
{ | ||
key: 'deleteSchema', | ||
label: 'Delete Schema', | ||
onClick: () => setAction(SchemaActionsEnum.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> | ||
<DeleteSchemaModal | ||
open={action === SchemaActionsEnum.Delete} | ||
closeModal={() => setAction(null)} | ||
catalog={catalog} | ||
schema={schema} | ||
/> | ||
</> | ||
); | ||
} |
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