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
Feat/delete schema #61
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I just captured this.
You don't need to do create a new prop here to handle on success.
You can just simply do onSuccess in the caller
Can we have follow-up PRs to remove this pattern on other deletion hooks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to move the
invalidateQueries
to the caller as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, keep
invalidateQueries
in the mutation hook.It would works for both cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar example at L39 and L83 from official github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok got it, but we don't need to pass in
onSuccessCallback
. I will do a follow-on PR to remove all those. Thanks @yc-shawn 👍