Browse Source

update field http

tumao 4 years ago
parent
commit
1eccae1d27

+ 4 - 24
client/src/http/Field.ts

@@ -1,16 +1,16 @@
 import { DataType } from '../pages/collections/Types';
-import { FieldView } from '../pages/structure/Types';
+import { FieldData } from '../pages/structure/Types';
 import { IndexState } from '../types/Milvus';
 import BaseModel from './BaseModel';
-import { IndexHttp } from './Index';
 
-export class FieldHttp extends BaseModel implements FieldView {
+export class FieldHttp extends BaseModel implements FieldData {
   data_type!: DataType;
   fieldID!: string;
   type_params!: { key: string; value: string }[];
   is_primary_key!: true;
   name!: string;
-  // data from index http
+
+  // index
   _indexType!: string;
   _indexParameterPairs!: { key: string; value: string }[];
   _indexStatus!: IndexState;
@@ -32,26 +32,6 @@ export class FieldHttp extends BaseModel implements FieldView {
     return res.schema.fields.map((f: any) => new this(f));
   }
 
-  static async getStructureListWithIndex(
-    collectionName: string
-  ): Promise<FieldHttp[]> {
-    const vectorTypes: DataType[] = ['BinaryVector', 'FloatVector'];
-    const indexList = await IndexHttp.getIndexInfo(collectionName);
-    const structureList = [...(await this.getFields(collectionName))];
-    let fields: FieldHttp[] = [];
-    for (const structure of structureList) {
-      if (vectorTypes.includes(structure.data_type)) {
-        const index = indexList.find(i => i._fieldName === structure.name);
-        structure._indexParameterPairs = index?._indexParameterPairs || [];
-        structure._indexType = index?._indexType || '';
-        structure._createIndexDisabled = indexList.length > 0;
-      }
-
-      fields = [...fields, structure];
-    }
-    return fields;
-  }
-
   get _fieldId() {
     return this.fieldID;
   }

+ 24 - 2
client/src/pages/structure/Structure.tsx

@@ -9,6 +9,8 @@ import CustomToolTip from '../../components/customToolTip/CustomToolTip';
 import { FieldHttp } from '../../http/Field';
 import { FieldView } from './Types';
 import IndexTypeElement from './IndexTypeElement';
+import { DataType } from '../collections/Types';
+import { IndexHttp } from '../../http/Index';
 
 const useStyles = makeStyles((theme: Theme) => ({
   wrapper: {
@@ -65,18 +67,38 @@ const Structure: FC<{
     data: structureList,
   } = usePaginationHook(fields);
 
+  const fetchStructureListWithIndex = async (
+    collectionName: string
+  ): Promise<FieldView[]> => {
+    const vectorTypes: DataType[] = ['BinaryVector', 'FloatVector'];
+    const indexList = await IndexHttp.getIndexInfo(collectionName);
+    const structureList = [...(await FieldHttp.getFields(collectionName))];
+    let fields: FieldView[] = [];
+    for (const structure of structureList) {
+      if (vectorTypes.includes(structure.data_type)) {
+        const index = indexList.find(i => i._fieldName === structure.name);
+        structure._indexParameterPairs = index?._indexParameterPairs || [];
+        structure._indexType = index?._indexType || '';
+        structure._createIndexDisabled = indexList.length > 0;
+      }
+
+      fields = [...fields, structure];
+    }
+    return fields;
+  };
+
   const fetchFields = useCallback(
     async (collectionName: string) => {
       const KeyIcon = icons.key;
 
       try {
-        const list = await FieldHttp.getStructureListWithIndex(collectionName);
+        const list = await fetchStructureListWithIndex(collectionName);
         const fields: FieldView[] = list.map(f =>
           Object.assign(f, {
             _fieldNameElement: (
               <div className={classes.nameWrapper}>
                 {f._fieldName}
-                {f.is_primary_key && <KeyIcon classes={{ root: 'key' }} />}
+                {f._isPrimaryKey && <KeyIcon classes={{ root: 'key' }} />}
               </div>
             ),
             _indexParamElement: (

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

@@ -13,14 +13,17 @@ export enum INDEX_TYPES_ENUM {
   RNSG = 'RNSG',
 }
 
-export interface FieldView extends IndexView {
+export interface FieldData {
   _fieldId: string;
   _isPrimaryKey: boolean;
   _fieldName: string;
   _fieldNameElement?: ReactElement;
   _fieldType: DataType;
   _dimension: string;
-  _createIndexDisabled: boolean;
+}
+
+export interface FieldView extends FieldData, IndexView {
+  _createIndexDisabled?: boolean;
 }
 
 export interface Index {