Skip to content

Commit

Permalink
🐛 Handle upload state for binary upload (#1467)
Browse files Browse the repository at this point in the history
-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 <ibolton@redhat.com>
  • Loading branch information
ibolton336 authored Oct 12, 2023
1 parent 5cfcdbe commit 53ecc75
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export const UploadBinary: React.FC = () => {
title: "Uploaded binary file.",
variant: "success",
});
setFileUploadStatus("success");
setFileUploadProgress(100);
};

const failedUpload = (error: AxiosError) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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");
});
}
};

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 53ecc75

Please sign in to comment.