Jelajahi Sumber

use DataTypeStringEnum instead of specified type

czhen 3 tahun lalu
induk
melakukan
0d8417de5e

+ 11 - 4
client/src/components/advancedSearch/Condition.tsx

@@ -10,6 +10,7 @@ import CloseIcon from '@material-ui/icons/Close';
 import { ConditionProps, Field } from './Types';
 import CustomSelector from '../customSelector/CustomSelector';
 import { LOGICAL_OPERATORS } from '../../consts/Util';
+import { DataTypeStringEnum } from '../../pages/collections/Types';
 
 const Condition: FC<ConditionProps> = props => {
   const {
@@ -48,17 +49,23 @@ const Condition: FC<ConditionProps> = props => {
     const conditionValueWithNoSpace = conditionValue.replaceAll(' ', '');
 
     switch (type) {
-      case 'int':
+      case DataTypeStringEnum.Int8:
+      case DataTypeStringEnum.Int16:
+      case DataTypeStringEnum.Int32:
+      case DataTypeStringEnum.Int64:
+        // case DataTypeStringEnum:
         isLegal = isIn
           ? regIntInterval.test(conditionValueWithNoSpace)
           : regInt.test(conditionValueWithNoSpace);
         break;
-      case 'float':
+      case DataTypeStringEnum.Float:
+      case DataTypeStringEnum.Double:
+      case DataTypeStringEnum.FloatVector:
         isLegal = isIn
           ? regFloatInterval.test(conditionValueWithNoSpace)
           : regFloat.test(conditionValueWithNoSpace);
         break;
-      case 'bool':
+      case DataTypeStringEnum.Bool:
         const legalValues = ['false', 'true'];
         isLegal = legalValues.includes(conditionValueWithNoSpace);
         break;
@@ -81,7 +88,7 @@ const Condition: FC<ConditionProps> = props => {
   const classes = useStyles();
 
   const logicalOperators = useMemo(() => {
-    if (conditionField.type === 'bool') {
+    if (conditionField.type === DataTypeStringEnum.Bool) {
       const data = LOGICAL_OPERATORS.filter(v => v.value === '==');
       setOperator(data[0].value);
       // bool only support ==

+ 2 - 2
client/src/components/advancedSearch/Types.ts

@@ -1,4 +1,4 @@
-// import { ReactElement } from 'react';
+import { DataTypeStringEnum } from '../../pages/collections/Types';
 
 export interface ConditionProps {
   others?: object;
@@ -12,7 +12,7 @@ export interface ConditionProps {
 
 export interface Field {
   name: string;
-  type: 'int' | 'float' | 'bool';
+  type: DataTypeStringEnum;
 }
 
 export interface TriggerChangeData {

+ 5 - 7
client/src/pages/query/Query.tsx

@@ -21,6 +21,7 @@ import CustomToolBar from '../../components/grid/ToolBar';
 // import { CustomDatePicker } from '../../components/customDatePicker/CustomDatePicker';
 import { saveAs } from 'file-saver';
 import { generateCsvData } from '../../utils/Format';
+import { DataTypeStringEnum } from '../collections/Types';
 
 const Query: FC<{
   collectionName: string;
@@ -107,20 +108,17 @@ const Query: FC<{
 
   const getFields = async (collectionName: string) => {
     const schemaList = await FieldHttp.getFields(collectionName);
-    const generateDataType = (rawType: string) => {
-      if (rawType.includes('Int')) return 'int';
-      if (rawType.includes('Bool')) return 'bool';
-      return 'float';
-    };
     const nameList = schemaList.map(v => ({
       name: v.name,
-      type: generateDataType(v.data_type),
+      type: v.data_type,
     }));
     const primaryKey =
       schemaList.find(v => v._isPrimaryKey === true)?._fieldName || '';
     setPrimaryKey(primaryKey);
     // Temporarily hide bool field due to incorrect return from SDK.
-    const fieldWithoutBool = nameList.filter(i => i.type !== 'bool');
+    const fieldWithoutBool = nameList.filter(
+      i => i.type !== DataTypeStringEnum.Bool
+    );
     setFields(fieldWithoutBool);
   };
 

+ 1 - 11
client/src/utils/search.ts

@@ -112,18 +112,8 @@ export const getVectorFieldOptions = (
 };
 
 export const getNonVectorFieldsForFilter = (fields: FieldData[]): Field[] => {
-  const intTypes: DataTypeStringEnum[] = [
-    DataTypeStringEnum.Int8,
-    DataTypeStringEnum.Int16,
-    DataTypeStringEnum.Int32,
-    DataTypeStringEnum.Int64,
-  ];
   return fields.map(f => ({
     name: f._fieldName,
-    type: intTypes.includes(f._fieldType)
-      ? 'int'
-      : f._fieldType === 'Bool'
-      ? 'bool'
-      : 'float',
+    type: f._fieldType,
   }));
 };