diff --git a/client/src/pages/databases/collections/schema/Schema.tsx b/client/src/pages/databases/collections/schema/Schema.tsx index 01d1601f..1b4a5edb 100644 --- a/client/src/pages/databases/collections/schema/Schema.tsx +++ b/client/src/pages/databases/collections/schema/Schema.tsx @@ -1,6 +1,6 @@ import { Typography, Chip, Tooltip } from '@mui/material'; import { useContext } from 'react'; -import { useParams } from 'react-router-dom'; +import { useParams, useNavigate } from 'react-router-dom'; import AttuGrid from '@/components/grid/Grid'; import { ColDefinitionsType } from '@/components/grid/Types'; import { useTranslation } from 'react-i18next'; @@ -15,16 +15,19 @@ import { FieldObject } from '@server/types'; import { useStyles } from './Styles'; import CustomIconButton from '@/components/customButton/CustomIconButton'; import LoadCollectionDialog from '@/pages/dialogs/LoadCollectionDialog'; +import RenameCollectionDialog from '@/pages/dialogs/RenameCollectionDialog'; import CopyButton from '@/components/advancedSearch/CopyButton'; import RefreshButton from '@/components/customButton/RefreshButton'; import { CollectionService } from '@/http'; const Overview = () => { - const { fetchCollection, collections, loading } = useContext(dataContext); + const { fetchCollection, collections, loading, database } = + useContext(dataContext); const { data } = useContext(systemContext); const { setDialog } = useContext(rootContext); const { collectionName = '' } = useParams<{ collectionName: string }>(); + const navigate = useNavigate(); const classes = useStyles(); const { t: collectionTrans } = useTranslation('collection'); const { t: indexTrans } = useTranslation('index'); @@ -275,6 +278,32 @@ const Overview = () => {

{collection.collection_name}

+ { + setDialog({ + open: true, + type: 'custom', + params: { + component: ( + { + await fetchCollection(newName); + + // update collection name in the route url; + navigate( + `/databases/${database}/${newName}/schema` + ); + }} + /> + ), + }, + }); + }} + tooltip={btnTrans('rename')} + icon={} + /> { // hooks const { setDialog } = useContext(rootContext); - const { fetchCollection } = useContext(dataContext); + const { fetchCollection, database } = useContext(dataContext); + const navigate = useNavigate(); + const classes = useStyles(); // props const { contextMenu, onClick } = props; @@ -114,7 +117,12 @@ export const TreeContextMenu = (props: { component: ( {}} + cb={async newName => { + await fetchCollection(newName); + + // update collection name in the route url; + navigate(`/databases/${database}/${newName}/schema`); + }} /> ), },