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 support to edit volume description (#68)
- Loading branch information
Showing
3 changed files
with
175 additions
and
38 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,60 @@ | ||
import { Button, Form, Modal, Typography } from 'antd'; | ||
import React, { useCallback, useRef } from 'react'; | ||
import TextArea from 'antd/es/input/TextArea'; | ||
import { UpdateVolumeMutationParams } from '../../hooks/volumes'; | ||
|
||
interface EditVolumeDescriptionModalProps { | ||
open: boolean; | ||
volume: UpdateVolumeMutationParams; | ||
closeModal: () => void; | ||
onSubmit: (comment: UpdateVolumeMutationParams) => void; | ||
loading: boolean; | ||
} | ||
|
||
export function EditVolumeDescriptionModal({ | ||
open, | ||
volume, | ||
closeModal, | ||
onSubmit, | ||
loading, | ||
}: EditVolumeDescriptionModalProps) { | ||
const submitRef = useRef<HTMLButtonElement>(null); | ||
|
||
const handleSubmit = useCallback(() => { | ||
submitRef.current?.click(); | ||
}, []); | ||
|
||
return ( | ||
<Modal | ||
title={<Typography.Title level={4}>Edit description</Typography.Title>} | ||
okText="Save" | ||
cancelText="Cancel" | ||
open={open} | ||
destroyOnClose | ||
onCancel={closeModal} | ||
onOk={handleSubmit} | ||
okButtonProps={{ loading: loading }} | ||
> | ||
<Typography.Paragraph type="secondary"> | ||
Volume description | ||
</Typography.Paragraph> | ||
<Form<UpdateVolumeMutationParams> | ||
layout="vertical" | ||
onFinish={(values) => { | ||
onSubmit(values); | ||
}} | ||
name="Edit description form" | ||
initialValues={{ comment: volume.comment }} | ||
> | ||
<Form.Item name="comment"> | ||
<TextArea /> | ||
</Form.Item> | ||
<Form.Item hidden> | ||
<Button type="primary" htmlType="submit" ref={submitRef}> | ||
Create | ||
</Button> | ||
</Form.Item> | ||
</Form> | ||
</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
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 |
---|---|---|
@@ -1,59 +1,92 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { Link, useParams } from 'react-router-dom'; | ||
import DetailsLayout from '../components/layouts/DetailsLayout'; | ||
import { Flex, Typography } from 'antd'; | ||
import DescriptionBox from '../components/DescriptionBox'; | ||
import { useGetVolume } from '../hooks/volumes'; | ||
import { useGetVolume, useUpdateVolume } from '../hooks/volumes'; | ||
import VolumeSidebar from '../components/volumes/VolumeSidebar'; | ||
import { FolderOutlined } from '@ant-design/icons'; | ||
import VolumeActionsDropdown from '../components/volumes/VolumeActionsDropdown'; | ||
import { EditVolumeDescriptionModal } from '../components/modals/EditVolumeDescriptionModal'; | ||
import { useNotification } from '../utils/NotificationContext'; | ||
|
||
export default function VolumeDetails() { | ||
const { catalog, schema, volume } = useParams(); | ||
if (!catalog) throw new Error('Catalog name is required'); | ||
if (!schema) throw new Error('Schema name is required'); | ||
if (!volume) throw new Error('Table name is required'); | ||
if (!volume) throw new Error('Volume name is required'); | ||
|
||
const { data } = useGetVolume({ catalog, schema, volume }); | ||
const [open, setOpen] = useState<boolean>(false); | ||
const { setNotification } = useNotification(); | ||
const mutation = useUpdateVolume({ catalog, schema, volume }); | ||
|
||
if (!data) return null; | ||
|
||
const volumeFullName = [catalog, schema, volume].join('.'); | ||
return ( | ||
<DetailsLayout | ||
title={ | ||
<Flex justify="space-between" align="flex-start" gap="middle"> | ||
<Typography.Title level={3}> | ||
<FolderOutlined /> {volumeFullName} | ||
</Typography.Title> | ||
<VolumeActionsDropdown | ||
catalog={catalog} | ||
schema={schema} | ||
volume={volume} | ||
/> | ||
</Flex> | ||
} | ||
breadcrumbs={[ | ||
{ title: <Link to="/">Catalogs</Link>, key: '_home' }, | ||
{ | ||
title: <Link to={`/data/${catalog}`}>{catalog}</Link>, | ||
key: '_catalog', | ||
}, | ||
{ | ||
title: <Link to={`/data/${catalog}/${schema}`}>{schema}</Link>, | ||
key: '_schema', | ||
}, | ||
{ title: volume, key: '_volume' }, | ||
]} | ||
> | ||
<DetailsLayout.Content> | ||
<Flex vertical gap="middle"> | ||
<DescriptionBox comment={data.comment} /> | ||
</Flex> | ||
</DetailsLayout.Content> | ||
<DetailsLayout.Aside> | ||
<VolumeSidebar catalog={catalog} schema={schema} volume={volume} /> | ||
</DetailsLayout.Aside> | ||
</DetailsLayout> | ||
<> | ||
<DetailsLayout | ||
title={ | ||
<Flex justify="space-between" align="flex-start" gap="middle"> | ||
<Typography.Title level={3}> | ||
<FolderOutlined /> {volumeFullName} | ||
</Typography.Title> | ||
<VolumeActionsDropdown | ||
catalog={catalog} | ||
schema={schema} | ||
volume={volume} | ||
/> | ||
</Flex> | ||
} | ||
breadcrumbs={[ | ||
{ title: <Link to="/">Catalogs</Link>, key: '_home' }, | ||
{ | ||
title: <Link to={`/data/${catalog}`}>{catalog}</Link>, | ||
key: '_catalog', | ||
}, | ||
{ | ||
title: <Link to={`/data/${catalog}/${schema}`}>{schema}</Link>, | ||
key: '_schema', | ||
}, | ||
{ title: volume, key: '_volume' }, | ||
]} | ||
> | ||
<DetailsLayout.Content> | ||
<Flex vertical gap="middle"> | ||
<DescriptionBox | ||
comment={data.comment} | ||
onEdit={() => setOpen(true)} | ||
/> | ||
</Flex> | ||
</DetailsLayout.Content> | ||
<DetailsLayout.Aside> | ||
<VolumeSidebar catalog={catalog} schema={schema} volume={volume} /> | ||
</DetailsLayout.Aside> | ||
</DetailsLayout> | ||
<EditVolumeDescriptionModal | ||
open={open} | ||
volume={data} | ||
closeModal={() => setOpen(false)} | ||
onSubmit={(values) => | ||
mutation.mutate( | ||
{ ...values, name: volume }, | ||
{ | ||
onError: (error: Error) => { | ||
setNotification(error.message, 'error'); | ||
}, | ||
onSuccess: (volume) => { | ||
setNotification( | ||
`${volume.name} volume successfully updated`, | ||
'success', | ||
); | ||
setOpen(false); | ||
}, | ||
}, | ||
) | ||
} | ||
loading={mutation.isPending} | ||
/> | ||
</> | ||
); | ||
} |