From 53ecc750002b8fedc4bc30a2efe6441c332ee89d Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Thu, 12 Oct 2023 17:34:47 +0000 Subject: [PATCH] :bug: Handle upload state for binary upload (#1467) -Set form state once the file is read in rather than when the api returns a 200 for the upload post request Resolves https://issues.redhat.com/browse/MTA-1420 Signed-off-by: ibolton336 --- .../components/upload-binary.tsx | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/client/src/app/pages/applications/analysis-wizard/components/upload-binary.tsx b/client/src/app/pages/applications/analysis-wizard/components/upload-binary.tsx index 48148a394c..254e10b9ea 100644 --- a/client/src/app/pages/applications/analysis-wizard/components/upload-binary.tsx +++ b/client/src/app/pages/applications/analysis-wizard/components/upload-binary.tsx @@ -46,8 +46,6 @@ export const UploadBinary: React.FC = () => { title: "Uploaded binary file.", variant: "success", }); - setFileUploadStatus("success"); - setFileUploadProgress(100); }; const failedUpload = (error: AxiosError) => { @@ -66,9 +64,6 @@ export const UploadBinary: React.FC = () => { title: "Removed binary file.", variant: "success", }); - setFileUploadStatus(undefined); - setFileUploadProgress(undefined); - setValue("artifact", null); }; const failedRemove = (error: AxiosError) => { @@ -135,7 +130,19 @@ export const UploadBinary: React.FC = () => { file: droppedFiles[0], }); } - setValue("artifact", droppedFiles[0]); + readFile(droppedFiles[0]) + .then((data) => { + if (data) { + setFileUploadProgress(100); + setFileUploadStatus("success"); + setValue("artifact", droppedFiles[0]); + } + }) + .catch((error) => { + setValue("artifact", undefined); + setFileUploadProgress(0); + setFileUploadStatus("danger"); + }); } }; @@ -206,12 +213,14 @@ export const UploadBinary: React.FC = () => { key={artifact.name} customFileHandler={handleFile} onClearClick={() => { + setFileUploadStatus(undefined); + setFileUploadProgress(undefined); + setValue("artifact", null); taskGroup?.id && removeFile({ id: taskGroup?.id, path: `binary/${artifact}`, }); - setValue("artifact", null); }} progressAriaLabel={"text"} progressValue={fileUploadProgress}