Browse Source

new schema view

Signed-off-by: shanghaikid <jiangruiyi@gmail.com>
shanghaikid 2 years ago
parent
commit
8b8a86aa9a
2 changed files with 76 additions and 41 deletions
  1. 2 2
      client/src/http/Field.ts
  2. 74 39
      client/src/pages/schema/Schema.tsx

+ 2 - 2
client/src/http/Field.ts

@@ -57,12 +57,12 @@ export class FieldHttp extends BaseModel implements FieldData {
   }
   }
 
 
   get _dimension() {
   get _dimension() {
-    return this.type_params.find(item => item.key === 'dim')?.value || '--';
+    return this.type_params.find(item => item.key === 'dim')?.value || '';
   }
   }
 
 
   get _maxLength() {
   get _maxLength() {
     return (
     return (
-      this.type_params.find(item => item.key === 'max_length')?.value || '--'
+      this.type_params.find(item => item.key === 'max_length')?.value || ''
     );
     );
   }
   }
 }
 }

+ 74 - 39
client/src/pages/schema/Schema.tsx

@@ -1,15 +1,15 @@
-import { makeStyles, Theme, Typography } from '@material-ui/core';
+import { makeStyles, Theme, Typography, Chip } from '@material-ui/core';
 import { FC, useCallback, useEffect, useState } from 'react';
 import { FC, useCallback, useEffect, useState } from 'react';
 import AttuGrid from '../../components/grid/Grid';
 import AttuGrid from '../../components/grid/Grid';
 import { ColDefinitionsType } from '../../components/grid/Types';
 import { ColDefinitionsType } from '../../components/grid/Types';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import { usePaginationHook } from '../../hooks/Pagination';
 import { usePaginationHook } from '../../hooks/Pagination';
 import icons from '../../components/icons/Icons';
 import icons from '../../components/icons/Icons';
-import CustomToolTip from '../../components/customToolTip/CustomToolTip';
 import { FieldHttp } from '../../http/Field';
 import { FieldHttp } from '../../http/Field';
 import { FieldView } from './Types';
 import { FieldView } from './Types';
 import IndexTypeElement from './IndexTypeElement';
 import IndexTypeElement from './IndexTypeElement';
 import { IndexHttp } from '../../http/Index';
 import { IndexHttp } from '../../http/Index';
+import { DataTypeStringEnum } from '../collections/Types';
 
 
 const useStyles = makeStyles((theme: Theme) => ({
 const useStyles = makeStyles((theme: Theme) => ({
   wrapper: {
   wrapper: {
@@ -25,6 +25,10 @@ const useStyles = makeStyles((theme: Theme) => ({
     top: '3px',
     top: '3px',
     color: 'grey',
     color: 'grey',
   },
   },
+  chip: {
+    marginLeft: theme.spacing(0.5),
+    marginRight: theme.spacing(0.5),
+  },
   nameWrapper: {
   nameWrapper: {
     display: 'flex',
     display: 'flex',
     alignItems: 'center',
     alignItems: 'center',
@@ -62,7 +66,6 @@ const Schema: FC<{
   const classes = useStyles();
   const classes = useStyles();
   const { t: collectionTrans } = useTranslation('collection');
   const { t: collectionTrans } = useTranslation('collection');
   const { t: indexTrans } = useTranslation('index');
   const { t: indexTrans } = useTranslation('index');
-  const InfoIcon = icons.info;
 
 
   const [fields, setFields] = useState<FieldView[]>([]);
   const [fields, setFields] = useState<FieldView[]>([]);
   const [loading, setLoading] = useState<boolean>(true);
   const [loading, setLoading] = useState<boolean>(true);
@@ -104,7 +107,6 @@ const Schema: FC<{
   const fetchFields = useCallback(
   const fetchFields = useCallback(
     async (collectionName: string) => {
     async (collectionName: string) => {
       const KeyIcon = icons.key;
       const KeyIcon = icons.key;
-      const PartitionIcon = icons.filter;
 
 
       try {
       try {
         const list = await fetchSchemaListWithIndex(collectionName);
         const list = await fetchSchemaListWithIndex(collectionName);
@@ -113,22 +115,51 @@ const Schema: FC<{
             _fieldNameElement: (
             _fieldNameElement: (
               <div className={classes.nameWrapper}>
               <div className={classes.nameWrapper}>
                 {f._fieldName}
                 {f._fieldName}
-                {f._isPrimaryKey && (
+                {f._isPrimaryKey ? (
                   <div
                   <div
                     className={classes.iconTitle}
                     className={classes.iconTitle}
                     title={collectionTrans('idFieldName')}
                     title={collectionTrans('idFieldName')}
                   >
                   >
                     <KeyIcon classes={{ root: 'key' }} />
                     <KeyIcon classes={{ root: 'key' }} />
                   </div>
                   </div>
-                )}
-                {f.is_partition_key && (
-                  <div
-                    className={classes.iconTitle}
-                    title={collectionTrans('partitionKey')}
-                  >
-                    <PartitionIcon classes={{ root: 'key' }} />
-                  </div>
-                )}
+                ) : null}
+                {f.is_partition_key ? (
+                  <Chip
+                    className={classes.chip}
+                    size="small"
+                    label="Partition key"
+                    variant="outlined"
+                  />
+                ) : null}
+                {f._isAutoId ? (
+                  <Chip
+                    className={classes.chip}
+                    size="small"
+                    label="auto id"
+                    variant="outlined"
+                  />
+                ) : null}
+              </div>
+            ),
+            _fieldTypeElement: (
+              <div className={classes.nameWrapper}>
+                {f._fieldType}
+                {f._dimension ? (
+                  <Chip
+                    className={classes.chip}
+                    size="small"
+                    label={`dim: ${f._dimension}`}
+                    variant="outlined"
+                  />
+                ) : null}
+                {f._maxLength && f._maxLength !== 'null' ? (
+                  <Chip
+                    className={classes.chip}
+                    size="small"
+                    label={`max: ${f._maxLength}`}
+                    variant="outlined"
+                  />
+                ) : null}
               </div>
               </div>
             ),
             ),
             _indexParamElement: (
             _indexParamElement: (
@@ -150,11 +181,15 @@ const Schema: FC<{
               </div>
               </div>
             ),
             ),
             _indexTypeElement: (
             _indexTypeElement: (
-              <IndexTypeElement
-                data={f}
-                collectionName={collectionName}
-                cb={fetchFields}
-              />
+              <>
+                {f._fieldType !== DataTypeStringEnum.JSON ? (
+                  <IndexTypeElement
+                    data={f}
+                    collectionName={collectionName}
+                    cb={fetchFields}
+                  />
+                ) : null}
+              </>
             ),
             ),
           })
           })
         );
         );
@@ -182,30 +217,30 @@ const Schema: FC<{
       sortBy: '_fieldName',
       sortBy: '_fieldName',
     },
     },
     {
     {
-      id: '_fieldType',
+      id: '_fieldTypeElement',
       align: 'left',
       align: 'left',
       disablePadding: false,
       disablePadding: false,
       label: collectionTrans('fieldType'),
       label: collectionTrans('fieldType'),
     },
     },
-    {
-      id: '_dimension',
-      align: 'left',
-      disablePadding: false,
-      label: (
-        <span className="flex-center">
-          {collectionTrans('dimension')}
-          <CustomToolTip title={collectionTrans('dimensionTooltip')}>
-            <InfoIcon classes={{ root: classes.icon }} />
-          </CustomToolTip>
-        </span>
-      ),
-    },
-    {
-      id: '_maxLength',
-      align: 'left',
-      disablePadding: true,
-      label: collectionTrans('maxLength'),
-    },
+    // {
+    //   id: '_dimension',
+    //   align: 'left',
+    //   disablePadding: false,
+    //   label: (
+    //     <span className="flex-center">
+    //       {collectionTrans('dimension')}
+    //       <CustomToolTip title={collectionTrans('dimensionTooltip')}>
+    //         <InfoIcon classes={{ root: classes.icon }} />
+    //       </CustomToolTip>
+    //     </span>
+    //   ),
+    // },
+    // {
+    //   id: '_maxLength',
+    //   align: 'left',
+    //   disablePadding: true,
+    //   label: collectionTrans('maxLength'),
+    // },
     {
     {
       id: '_indexName',
       id: '_indexName',
       align: 'left',
       align: 'left',