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 ability to edit catalog description (#63)
* Add ability to edit catalog description edit modal is made to support more fields in the future if we want to edit more than just description * lint * feedback Co-authored-by: Shawn Chen <[email protected]> --------- Co-authored-by: Shawn Chen <[email protected]>
- Loading branch information
Showing
4 changed files
with
162 additions
and
31 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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { Typography } from 'antd'; | ||
import { Button, Typography } from 'antd'; | ||
import { EditOutlined } from '@ant-design/icons'; | ||
|
||
interface DescriptionBoxProps { | ||
comment: string; | ||
onEdit?: () => void; | ||
} | ||
|
||
export default function DescriptionBox({ comment }: DescriptionBoxProps) { | ||
export default function DescriptionBox({ | ||
comment, | ||
onEdit, | ||
}: DescriptionBoxProps) { | ||
return ( | ||
<div> | ||
<Typography.Title level={5}>Description</Typography.Title> | ||
<Typography.Title level={5}> | ||
Description {comment && <EditOutlined onClick={onEdit} />} | ||
</Typography.Title> | ||
<Typography.Text type="secondary">{comment}</Typography.Text> | ||
{!comment && <Button onClick={onEdit}>Add description</Button>} | ||
</div> | ||
); | ||
} |
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 { UpdateCatalogMutationParams } from '../../hooks/catalog'; | ||
|
||
interface EditCatalogDescriptionModalProps { | ||
open: boolean; | ||
catalog: UpdateCatalogMutationParams; | ||
closeModal: () => void; | ||
onSubmit: (comment: UpdateCatalogMutationParams) => void; | ||
loading: boolean; | ||
} | ||
|
||
export function EditCatalogDescriptionModal({ | ||
open, | ||
catalog, | ||
closeModal, | ||
onSubmit, | ||
loading, | ||
}: EditCatalogDescriptionModalProps) { | ||
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"> | ||
Catalog description | ||
</Typography.Paragraph> | ||
<Form<UpdateCatalogMutationParams> | ||
layout="vertical" | ||
onFinish={(values) => { | ||
onSubmit(values); | ||
}} | ||
name="Edit description form" | ||
initialValues={{ comment: catalog.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,50 +1,83 @@ | ||
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 { useGetCatalog } from '../hooks/catalog'; | ||
import { useGetCatalog, useUpdateCatalog } from '../hooks/catalog'; | ||
import SchemasList from '../components/schemas/SchemasList'; | ||
import DescriptionBox from '../components/DescriptionBox'; | ||
import CatalogSidebar from '../components/catalogs/CatalogSidebar'; | ||
import { ProductOutlined } from '@ant-design/icons'; | ||
import CreateSchemaAction from '../components/schemas/CreateSchemaAction'; | ||
import CatalogActionDropdown from '../components/catalogs/CatalogActionDropdown'; | ||
import { EditCatalogDescriptionModal } from '../components/modals/EditCatalogDescriptionModal'; | ||
import { useNotification } from '../utils/NotificationContext'; | ||
|
||
export default function CatalogDetails() { | ||
const { catalog } = useParams(); | ||
if (!catalog) throw new Error('Catalog name is required'); | ||
|
||
const { data } = useGetCatalog({ catalog }); | ||
const [open, setOpen] = useState<boolean>(false); | ||
const { setNotification } = useNotification(); | ||
const mutation = useUpdateCatalog(); | ||
|
||
if (!data) return null; | ||
|
||
return ( | ||
<DetailsLayout | ||
title={ | ||
<Flex justify="space-between" align="flex-start" gap="middle"> | ||
<Typography.Title level={3}> | ||
<ProductOutlined /> {catalog} | ||
</Typography.Title> | ||
<Flex gap="middle"> | ||
<CatalogActionDropdown catalog={catalog} /> | ||
<CreateSchemaAction catalog={catalog} /> | ||
<> | ||
<DetailsLayout | ||
title={ | ||
<Flex justify="space-between" align="flex-start" gap="middle"> | ||
<Typography.Title level={3}> | ||
<ProductOutlined /> {catalog} | ||
</Typography.Title> | ||
<Flex gap="middle"> | ||
<CatalogActionDropdown catalog={catalog} /> | ||
<CreateSchemaAction catalog={catalog} /> | ||
</Flex> | ||
</Flex> | ||
</Flex> | ||
} | ||
breadcrumbs={[ | ||
{ title: <Link to="/">Catalogs</Link>, key: '_home' }, | ||
{ title: catalog, key: '_catalog' }, | ||
]} | ||
> | ||
<DetailsLayout.Content> | ||
<Flex vertical gap="middle"> | ||
<DescriptionBox comment={data.comment} /> | ||
<SchemasList catalog={catalog} /> | ||
</Flex> | ||
</DetailsLayout.Content> | ||
<DetailsLayout.Aside> | ||
<CatalogSidebar catalog={catalog} /> | ||
</DetailsLayout.Aside> | ||
</DetailsLayout> | ||
} | ||
breadcrumbs={[ | ||
{ title: <Link to="/">Catalogs</Link>, key: '_home' }, | ||
{ title: catalog, key: '_catalog' }, | ||
]} | ||
> | ||
<DetailsLayout.Content> | ||
<Flex vertical gap="middle"> | ||
<DescriptionBox | ||
comment={data.comment} | ||
onEdit={() => setOpen(true)} | ||
/> | ||
<SchemasList catalog={catalog} /> | ||
</Flex> | ||
</DetailsLayout.Content> | ||
<DetailsLayout.Aside> | ||
<CatalogSidebar catalog={catalog} /> | ||
</DetailsLayout.Aside> | ||
</DetailsLayout> | ||
<EditCatalogDescriptionModal | ||
open={open} | ||
catalog={data} | ||
closeModal={() => setOpen(false)} | ||
onSubmit={(values) => | ||
mutation.mutate( | ||
{ ...values, name: data.name }, | ||
{ | ||
onError: (error: Error) => { | ||
setNotification(error.message, 'error'); | ||
}, | ||
onSuccess: (catalog) => { | ||
setNotification( | ||
`${catalog.name} catalog successfully updated`, | ||
'success', | ||
); | ||
setOpen(false); | ||
}, | ||
}, | ||
) | ||
} | ||
loading={mutation.isPending} | ||
/> | ||
</> | ||
); | ||
} |