Browse Source

asave file copy in insert dialog

nameczz 4 years ago
parent
commit
4ef08896d6

+ 10 - 0
client/src/components/insert/Container.tsx

@@ -72,6 +72,8 @@ const InsertContainer: FC<InsertContentProps> = ({
   const [isContainFieldNames, setIsContainFieldNames] = useState<number>(1);
   // uploaded file name
   const [fileName, setFileName] = useState<string>('');
+  const [file, setFile] = useState<File | null>(null);
+
   // uploaded csv data (type: string)
   const [csvData, setCsvData] = useState<any[]>([]);
 
@@ -225,6 +227,7 @@ const InsertContainer: FC<InsertContentProps> = ({
       openSnackBar(insertTrans('uploadFieldNamesLenWarning'), 'error');
       // reset uploader value and filename
       setFileName('');
+      setFile(null);
       uploader.value = null;
       return;
     }
@@ -272,6 +275,11 @@ const InsertContainer: FC<InsertContentProps> = ({
     }
   };
 
+  const handleUploadFileChange = (file: File, upload: HTMLFormElement) => {
+    console.log(file);
+    setFile(file);
+  };
+
   const handleBack = () => {
     switch (activeStep) {
       case InsertStepperEnum.import:
@@ -299,6 +307,7 @@ const InsertContainer: FC<InsertContentProps> = ({
             handleCollectionChange={handleCollectionChange}
             handlePartitionChange={setPartitionValue}
             handleUploadedData={handleUploadedData}
+            handleUploadFileChange={handleUploadFileChange}
             fileName={fileName}
             setFileName={setFileName}
           />
@@ -311,6 +320,7 @@ const InsertContainer: FC<InsertContentProps> = ({
             tableHeads={tableHeads}
             setTableHeads={setTableHeads}
             isContainFieldNames={isContainFieldNames}
+            file={file}
             handleIsContainedChange={setIsContainFieldNames}
           />
         );

+ 2 - 0
client/src/components/insert/Import.tsx

@@ -102,6 +102,7 @@ const InsertImport: FC<InsertImportProps> = ({
   handlePartitionChange,
 
   handleUploadedData,
+  handleUploadFileChange,
   fileName,
   setFileName,
 }) => {
@@ -162,6 +163,7 @@ const InsertImport: FC<InsertImportProps> = ({
             handleUploadedData={handleUploadedData}
             maxSize={parseByte('150m')}
             overSizeWarning={insertTrans('overSizeWarning')}
+            handleUploadFileChange={handleUploadFileChange}
           />
           <Typography className="text">
             {fileName || insertTrans('fileNamePlaceHolder')}

+ 1 - 0
client/src/components/insert/Preview.tsx

@@ -91,6 +91,7 @@ const InsertPreview: FC<InsertPreviewProps> = ({
   handleIsContainedChange,
   tableHeads,
   setTableHeads,
+  file,
 }) => {
   const classes = getStyles();
   const { t: insertTrans } = useTranslation('insert');

+ 2 - 0
client/src/components/insert/Types.ts

@@ -54,6 +54,7 @@ export interface InsertImportProps {
   handlePartitionChange: (partitionName: string) => void;
   // handle uploaded data
   handleUploadedData: (data: string, uploader: HTMLFormElement) => void;
+  handleUploadFileChange: (file: File, uploader: HTMLFormElement) => void;
   fileName: string;
   setFileName: (fileName: string) => void;
 }
@@ -67,6 +68,7 @@ export interface InsertPreviewProps {
 
   isContainFieldNames: number;
   handleIsContainedChange: (isContained: number) => void;
+  file: File | null; // csv file
 }
 
 export interface InsertStatusProps {

+ 0 - 1
client/src/pages/schema/Schema.tsx

@@ -99,7 +99,6 @@ const Schema: FC<{
 
       try {
         const list = await fetchSchemaListWithIndex(collectionName);
-        console.log(list);
         const fields: FieldView[] = list.map(f =>
           Object.assign(f, {
             _fieldNameElement: (