Skip to content

Commit

Permalink
support rename oollection on the schema page
Browse files Browse the repository at this point in the history
Signed-off-by: shanghaikid <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid committed Dec 21, 2024
1 parent a8b17ce commit 797e35e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
33 changes: 31 additions & 2 deletions client/src/pages/databases/collections/schema/Schema.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down Expand Up @@ -275,6 +278,32 @@ const Overview = () => {
<p title={collection.collection_name}>
{collection.collection_name}
</p>
<RefreshButton
className={classes.extraBtn}
onClick={async () => {
setDialog({
open: true,
type: 'custom',
params: {
component: (
<RenameCollectionDialog
collection={collection}
cb={async newName => {
await fetchCollection(newName);

// update collection name in the route url;
navigate(
`/databases/${database}/${newName}/schema`
);
}}
/>
),
},
});
}}
tooltip={btnTrans('rename')}
icon={<Icons.edit />}
/>
<CopyButton
className={classes.extraBtn}
label={collection.collection_name}
Expand Down
12 changes: 10 additions & 2 deletions client/src/pages/databases/tree/TreeContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { rootContext, dataContext } from '@/context';
import CreateCollectionDialog from '@/pages/dialogs/CreateCollectionDialog';
import LoadCollectionDialog from '@/pages/dialogs/LoadCollectionDialog';
Expand All @@ -20,7 +21,9 @@ export const TreeContextMenu = (props: {
}) => {
// 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;
Expand Down Expand Up @@ -114,7 +117,12 @@ export const TreeContextMenu = (props: {
component: (
<RenameCollectionDialog
collection={contextMenu.object as CollectionObject}
cb={async () => {}}
cb={async newName => {
await fetchCollection(newName);

// update collection name in the route url;
navigate(`/databases/${database}/${newName}/schema`);
}}
/>
),
},
Expand Down

0 comments on commit 797e35e

Please sign in to comment.