Browse Source

fix schema page UI rendering issue

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 year ago
parent
commit
84eaacba6f
1 changed files with 77 additions and 64 deletions
  1. 77 64
      client/src/pages/schema/Schema.tsx

+ 77 - 64
client/src/pages/schema/Schema.tsx

@@ -68,6 +68,8 @@ const Schema = () => {
   const [fields, setFields] = useState<FieldHttp[]>([]);
   const [fields, setFields] = useState<FieldHttp[]>([]);
   const [loading, setLoading] = useState<boolean>(true);
   const [loading, setLoading] = useState<boolean>(true);
 
 
+  const KeyIcon = icons.key;
+
   const {
   const {
     pageSize,
     pageSize,
     handlePageSize,
     handlePageSize,
@@ -82,76 +84,18 @@ const Schema = () => {
 
 
   const fetchFields = useCallback(
   const fetchFields = useCallback(
     async (collectionName: string) => {
     async (collectionName: string) => {
-      const KeyIcon = icons.key;
-
       try {
       try {
         const collection = await Collection.getCollectionWithIndexInfo(
         const collection = await Collection.getCollectionWithIndexInfo(
           collectionName
           collectionName
         );
         );
+
+        // add custom fields
         const fields = collection.fieldWithIndexInfo.map(f =>
         const fields = collection.fieldWithIndexInfo.map(f =>
           Object.assign(f, {
           Object.assign(f, {
-            _fieldNameElement: (
-              <div className={classes.nameWrapper}>
-                {f.name}
-                {f.isPrimaryKey ? (
-                  <div
-                    className={classes.iconTitle}
-                    title={collectionTrans('idFieldName')}
-                  >
-                    <KeyIcon classes={{ root: 'key' }} />
-                  </div>
-                ) : null}
-                {f.is_partition_key ? (
-                  <Chip
-                    className={classes.chip}
-                    size="small"
-                    label="Partition key"
-                    variant="outlined"
-                  />
-                ) : null}
-                {f.autoID ? (
-                  <Chip
-                    className={classes.chip}
-                    size="small"
-                    label="auto id"
-                    variant="outlined"
-                  />
-                ) : null}
-              </div>
-            ),
-            // Array<VarChar(64)>[Capacity]
-            _fieldTypeElement: formatFieldType(f),
-            _indexParamElement: (
-              <div className={classes.paramWrapper}>
-                {f.indexParameterPairs?.length > 0 ? (
-                  f.indexParameterPairs.map(p =>
-                    p.value ? (
-                      <>
-                        <span key={p.key + p.value} className="param">
-                          <Typography variant="body1" className="key">
-                            {`${p.key}:`}
-                          </Typography>
-                          <Typography variant="body1" className="value">
-                            {p.value}
-                          </Typography>
-                        </span>
-                      </>
-                    ) : (
-                      ''
-                    )
-                  )
-                ) : (
-                  <>--</>
-                )}
-              </div>
-            ),
-            _indexTypeElement: (
-              <IndexTypeElement
-                data={f}
-                collectionName={collectionName}
-                cb={fetchFields}
-              />
-            ),
+            _fieldNameElement: f,
+            _fieldTypeElement: f,
+            _indexParamElement: f,
+            _indexTypeElement: f,
           })
           })
         );
         );
 
 
@@ -174,6 +118,37 @@ const Schema = () => {
       id: '_fieldNameElement',
       id: '_fieldNameElement',
       align: 'left',
       align: 'left',
       disablePadding: true,
       disablePadding: true,
+      formatter(f) {
+        return (
+          <div className={classes.nameWrapper}>
+            {f.name}
+            {f.isPrimaryKey ? (
+              <div
+                className={classes.iconTitle}
+                title={collectionTrans('idFieldName')}
+              >
+                <KeyIcon classes={{ root: 'key' }} />
+              </div>
+            ) : null}
+            {f.is_partition_key ? (
+              <Chip
+                className={classes.chip}
+                size="small"
+                label="Partition key"
+                variant="outlined"
+              />
+            ) : null}
+            {f.autoID ? (
+              <Chip
+                className={classes.chip}
+                size="small"
+                label="auto id"
+                variant="outlined"
+              />
+            ) : null}
+          </div>
+        );
+      },
       label: collectionTrans('fieldName'),
       label: collectionTrans('fieldName'),
       sortBy: 'name',
       sortBy: 'name',
     },
     },
@@ -181,6 +156,9 @@ const Schema = () => {
       id: '_fieldTypeElement',
       id: '_fieldTypeElement',
       align: 'left',
       align: 'left',
       disablePadding: false,
       disablePadding: false,
+      formatter(f) {
+        return formatFieldType(f);
+      },
       label: collectionTrans('fieldType'),
       label: collectionTrans('fieldType'),
     },
     },
     {
     {
@@ -195,6 +173,15 @@ const Schema = () => {
       disablePadding: true,
       disablePadding: true,
       label: indexTrans('type'),
       label: indexTrans('type'),
       sortBy: 'indexType',
       sortBy: 'indexType',
+      formatter(f) {
+        return (
+          <IndexTypeElement
+            data={f}
+            collectionName={collectionName}
+            cb={fetchFields}
+          />
+        );
+      },
     },
     },
     {
     {
       id: '_indexParamElement',
       id: '_indexParamElement',
@@ -202,6 +189,32 @@ const Schema = () => {
       disablePadding: false,
       disablePadding: false,
       label: indexTrans('param'),
       label: indexTrans('param'),
       notSort: true,
       notSort: true,
+      formatter(f) {
+        return (
+          <div className={classes.paramWrapper}>
+            {f.indexParameterPairs?.length > 0 ? (
+              f.indexParameterPairs.map((p: any) =>
+                p.value ? (
+                  <>
+                    <span key={p.key + p.value} className="param">
+                      <Typography variant="body1" className="key">
+                        {`${p.key}:`}
+                      </Typography>
+                      <Typography variant="body1" className="value">
+                        {p.value}
+                      </Typography>
+                    </span>
+                  </>
+                ) : (
+                  ''
+                )
+              )
+            ) : (
+              <>--</>
+            )}
+          </div>
+        );
+      },
     },
     },
     {
     {
       id: 'desc',
       id: 'desc',