Browse Source

add delete index

tumao 4 years ago
parent
commit
809466e338

+ 1 - 1
client/public/index.html

@@ -30,7 +30,7 @@
       work correctly both with client-side routing and a non-root public URL.
       Learn how to configure a non-root public URL by running `npm run build`.
     -->
-    <title>Milvus Admin</title>
+    <title>Milvus Insight</title>
   </head>
 
   <body>

+ 11 - 1
client/src/http/Index.ts

@@ -1,8 +1,10 @@
 import {
   IndexCreateParam,
+  IndexManageParam,
   IndexView,
   ParamPair,
 } from '../pages/structure/Types';
+import { ManageRequestMethods } from '../types/Common';
 import { IndexState } from '../types/Milvus';
 import BaseModel from './BaseModel';
 
@@ -40,13 +42,21 @@ export class IndexHttp extends BaseModel implements IndexView {
 
   static async createIndex(param: IndexCreateParam) {
     const path = this.BASE_URL;
+    const type: ManageRequestMethods = ManageRequestMethods.CREATE;
 
     return super.create({
       path,
-      data: { ...param },
+      data: { ...param, type },
     });
   }
 
+  static async deleteIndex(param: IndexManageParam) {
+    const path = this.BASE_URL;
+    const type: ManageRequestMethods = ManageRequestMethods.DELETE;
+
+    return super.batchDelete({ path, data: { ...param, type } });
+  }
+
   get _indexType() {
     return this.params.find(p => p.key === 'index_type')?.value || '';
   }

+ 2 - 0
client/src/i18n/cn/index.ts

@@ -7,6 +7,8 @@ const indexTrans = {
   metric: 'Metric Type',
 
   createSuccess: 'Creating index successfully',
+  deleteWarning:
+    'You are trying to delete a index. This action cannot be undone.',
 };
 
 export default indexTrans;

+ 2 - 0
client/src/i18n/en/index.ts

@@ -7,6 +7,8 @@ const indexTrans = {
 
   metric: 'Metric Type',
   createSuccess: 'Creating index successfully',
+  deleteWarning:
+    'You are trying to delete a index. This action cannot be undone.',
 };
 
 export default indexTrans;

+ 42 - 7
client/src/pages/structure/IndexTypeElement.tsx

@@ -3,7 +3,12 @@ import Chip from '@material-ui/core/Chip';
 import CustomButton from '../../components/customButton/CustomButton';
 import { IndexHttp } from '../../http/Index';
 import { IndexState } from '../../types/Milvus';
-import { FieldView, IndexCreateParam, ParamPair } from './Types';
+import {
+  FieldView,
+  IndexCreateParam,
+  IndexManageParam,
+  ParamPair,
+} from './Types';
 import StatusIcon from '../../components/status/StatusIcon';
 import { ChildrenStatusType } from '../../components/status/Types';
 import { useTranslation } from 'react-i18next';
@@ -11,7 +16,7 @@ import { makeStyles, Theme } from '@material-ui/core';
 import icons from '../../components/icons/Icons';
 import { rootContext } from '../../context/Root';
 import CreateIndex from './Create';
-import { ManageRequestMethods } from '../../types/Common';
+import DeleteTemplate from '../../components/customDialog/DeleteDialogTemplate';
 
 const useStyles = makeStyles((theme: Theme) => ({
   item: {
@@ -31,12 +36,16 @@ const useStyles = makeStyles((theme: Theme) => ({
 const IndexTypeElement: FC<{
   data: FieldView;
   collectionName: string;
-  createCb: (collectionName: string) => void;
-}> = ({ data, collectionName, createCb }) => {
+  cb: (collectionName: string) => void;
+}> = ({ data, collectionName, cb }) => {
   const classes = useStyles();
 
   const [status, setStatus] = useState<string>('');
+
   const { t } = useTranslation('index');
+  const { t: btnTrans } = useTranslation('btn');
+  const { t: dialogTrans } = useTranslation('dialog');
+  const { t: successTrans } = useTranslation('success');
 
   const { setDialog, handleCloseDialog, openSnackBar } =
     useContext(rootContext);
@@ -60,7 +69,6 @@ const IndexTypeElement: FC<{
 
   const requestCreateIndex = async (params: ParamPair[]) => {
     const indexCreateParam: IndexCreateParam = {
-      type: ManageRequestMethods.CREATE,
       collection_name: collectionName,
       field_name: data._fieldName,
       extra_params: params,
@@ -68,7 +76,7 @@ const IndexTypeElement: FC<{
     await IndexHttp.createIndex(indexCreateParam);
     handleCloseDialog();
     openSnackBar(t('createSuccess'));
-    createCb(collectionName);
+    cb(collectionName);
   };
 
   const handleCreate = () => {
@@ -88,7 +96,34 @@ const IndexTypeElement: FC<{
     });
   };
 
-  const handleDelete = () => {};
+  const requestDeleteIndex = async () => {
+    const indexDeleteParam: IndexManageParam = {
+      collection_name: collectionName,
+      field_name: data._fieldName,
+    };
+
+    await IndexHttp.deleteIndex(indexDeleteParam);
+    handleCloseDialog();
+    openSnackBar(successTrans('delete', { name: t('index') }));
+    cb(collectionName);
+  };
+
+  const handleDelete = () => {
+    setDialog({
+      open: true,
+      type: 'custom',
+      params: {
+        component: (
+          <DeleteTemplate
+            label={btnTrans('delete')}
+            title={dialogTrans('deleteTitle', { type: t('index') })}
+            text={t('deleteWarning')}
+            handleDelete={requestDeleteIndex}
+          />
+        ),
+      },
+    });
+  };
 
   const generateElement = () => {
     if (

+ 1 - 1
client/src/pages/structure/Structure.tsx

@@ -130,7 +130,7 @@ const Structure: FC<{
               <IndexTypeElement
                 data={f}
                 collectionName={collectionName}
-                createCb={fetchFields}
+                cb={fetchFields}
               />
             ),
           })

+ 4 - 2
client/src/pages/structure/Types.ts

@@ -48,10 +48,12 @@ export type IndexType =
   | 'HNSW'
   | 'ANNOY';
 
-export interface IndexCreateParam {
-  type: ManageRequestMethods;
+export interface IndexManageParam {
   collection_name: string;
   field_name: string;
+}
+
+export interface IndexCreateParam extends IndexManageParam {
   extra_params: ParamPair[];
 }
 

+ 1 - 1
server/package.json

@@ -30,7 +30,7 @@
     "@nestjs/swagger": "^4.8.0",
     "@types/passport-jwt": "^3.0.5",
     "@types/passport-local": "^1.0.33",
-    "@zilliz/milvus-sdk-node-dev": "^0.1.2",
+    "@zilliz/milvus-sdk-node-dev": "^0.1.4",
     "class-transformer": "^0.4.0",
     "class-validator": "^0.13.1",
     "passport": "^0.4.1",

+ 4 - 4
server/yarn.lock

@@ -1287,10 +1287,10 @@
   resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
   integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
 
-"@zilliz/milvus-sdk-node-dev@^0.1.2":
-  version "0.1.2"
-  resolved "https://registry.yarnpkg.com/@zilliz/milvus-sdk-node-dev/-/milvus-sdk-node-dev-0.1.2.tgz#be5d546afec4e6a87732beadce2bd8f3261dac58"
-  integrity sha512-WScOEWG0Y9va5JBRoQsh1vfH9W0LOjl5HIZVwP/vcT7Kh0pC1E4N6iwaEpnSkne055D9SxJA7FhN23udrHTrMQ==
+"@zilliz/milvus-sdk-node-dev@^0.1.4":
+  version "0.1.4"
+  resolved "https://registry.yarnpkg.com/@zilliz/milvus-sdk-node-dev/-/milvus-sdk-node-dev-0.1.4.tgz#858e83b0ba0a309cbdf0b87e313b3b41de0052a4"
+  integrity sha512-4REU6TxqjsIZ7a7mL1M19IPg3oBBfE9kJmC7XUmcFz1+F2fYWpl7Iw4R8g69trpzUNnaFIBgwjAnSb0oVrRLeQ==
   dependencies:
     "@grpc/grpc-js" "^1.2.12"
     "@grpc/proto-loader" "^0.6.0"