Browse Source

Auto select default partition when collection selected during insert

tumao 3 years ago
parent
commit
9223bd6276
1 changed files with 5 additions and 2 deletions
  1. 5 2
      client/src/components/insert/Container.tsx

+ 5 - 2
client/src/components/insert/Container.tsx

@@ -116,6 +116,7 @@ const InsertContainer: FC<InsertContentProps> = ({
     setTableHeads(heads);
   }, [previewData, isContainFieldNames]);
 
+  // every time selected collection value change, partition options and default value will change
   const fetchPartition = useCallback(async () => {
     if (collectionValue) {
       const partitions = await PartitionHttp.getPartitions(collectionValue);
@@ -124,6 +125,10 @@ const InsertContainer: FC<InsertContentProps> = ({
         value: p._name,
       }));
       setPartitionOptions(partitionOptions);
+
+      // set first partition option value as default value
+      const [{ value: defaultPartitionValue }] = partitionOptions;
+      setPartitionValue(defaultPartitionValue as string);
     }
   }, [collectionValue]);
 
@@ -310,8 +315,6 @@ const InsertContainer: FC<InsertContentProps> = ({
 
   const handleCollectionChange = (name: string) => {
     setCollectionValue(name);
-    // reset partition
-    setPartitionValue('');
   };
 
   const handleNext = () => {