leezng commented on code in PR #7972:
URL: https://github.com/apache/inlong/pull/7972#discussion_r1188250739


##########
inlong-dashboard/src/ui/components/FieldParseModule/index.tsx:
##########
@@ -85,6 +88,63 @@ const FieldParseModule: React.FC<FieldParseModuleProps> = ({
     onAppend([...previewData]);
     onHide();
   };
+  const downloadTemplate = async () => {
+    try {
+      const response = await fetch('stream/downloadExcelTemplate');
+      const blob = await response.blob();
+      const url = window.URL.createObjectURL(new Blob([blob]));
+      const link = document.createElement('a');
+      link.href = url;

Review Comment:
   Is it possible to directly set a href="url" without adding another layer of 
blob?



##########
inlong-dashboard/src/ui/components/FieldParseModule/index.tsx:
##########
@@ -85,6 +88,63 @@ const FieldParseModule: React.FC<FieldParseModuleProps> = ({
     onAppend([...previewData]);
     onHide();
   };
+  const downloadTemplate = async () => {
+    try {
+      const response = await fetch('stream/downloadExcelTemplate');
+      const blob = await response.blob();
+      const url = window.URL.createObjectURL(new Blob([blob]));
+      const link = document.createElement('a');
+      link.href = url;
+      link.setAttribute('download', 'template.xlsx');
+      document.body.appendChild(link);
+      link.click();
+      link.parentNode?.removeChild(link);
+    } catch (error) {
+      console.error(error);
+    }
+  };
+
+  const { run: doUpload } = useRequest(
+    data => ({
+      url: '/stream/parseFieldsByExcel',
+      method: 'POST',
+      requestType: 'formData',
+      data,
+      onSuccess: result => {
+        console.log('Upload result:', result);
+        setPreviewData(result);
+      },
+      onError: error => {
+        console.log('upload error!');
+        message.error(error);
+      },
+    }),
+    {
+      manual: true,
+    },
+  );
+
+  const uploadExcel = async () => {

Review Comment:
   Is it possible to directly use the underlying component library Upload 
component? No need to implement it yourself.
   
   See: https://ant.design/components/upload



##########
inlong-dashboard/src/ui/components/FieldParseModule/index.tsx:
##########
@@ -85,6 +88,63 @@ const FieldParseModule: React.FC<FieldParseModuleProps> = ({
     onAppend([...previewData]);
     onHide();
   };
+  const downloadTemplate = async () => {
+    try {
+      const response = await fetch('stream/downloadExcelTemplate');
+      const blob = await response.blob();
+      const url = window.URL.createObjectURL(new Blob([blob]));
+      const link = document.createElement('a');
+      link.href = url;
+      link.setAttribute('download', 'template.xlsx');
+      document.body.appendChild(link);
+      link.click();
+      link.parentNode?.removeChild(link);
+    } catch (error) {
+      console.error(error);
+    }
+  };
+
+  const { run: doUpload } = useRequest(
+    data => ({
+      url: '/stream/parseFieldsByExcel',
+      method: 'POST',
+      requestType: 'formData',
+      data,
+      onSuccess: result => {
+        console.log('Upload result:', result);
+        setPreviewData(result);
+      },
+      onError: error => {

Review Comment:
   There is no need to handle onError, all request errors will be handled 
uniformly, otherwise prompts will be repeated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to