Merge pull request #75 from sartography/bug/replace-file-warning

Confirm before overwriting file when uploading file with same name
This commit is contained in:
jasquat 2022-12-16 13:15:44 -05:00 committed by GitHub
commit 41c6dacbe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 12 deletions

View File

@ -362,13 +362,12 @@ export default function ProcessModelShow() {
);
};
const handleFileUploadCancel = () => {
setShowFileUploadModal(false);
setFilesToUpload(null);
};
const [fileUploadEvent, setFileUploadEvent] = useState(null);
const [duplicateFilename, setDuplicateFilename] = useState<String>('');
const [showOverwriteConfirmationPrompt, setShowOverwriteConfirmationPrompt] =
useState(false);
const handleFileUpload = (event: any) => {
if (processModel) {
const doFileUpload = (event: any) => {
event.preventDefault();
const url = `/process-models/${modifiedProcessModelId}/files`;
const formData = new FormData();
@ -380,10 +379,60 @@ export default function ProcessModelShow() {
httpMethod: 'POST',
postBody: formData,
});
}
setFilesToUpload(null);
};
const handleFileUploadCancel = () => {
setShowFileUploadModal(false);
setFilesToUpload(null);
};
const handleOverwriteFileConfirm = () => {
setShowOverwriteConfirmationPrompt(false);
doFileUpload(fileUploadEvent);
};
const handleOverwriteFileCancel = () => {
setShowOverwriteConfirmationPrompt(false);
setFilesToUpload(null);
};
const confirmOverwriteFileDialog = () => {
return (
<Modal
danger
open={showOverwriteConfirmationPrompt}
data-qa="file-overwrite-modal-confirmation-dialog"
modalHeading={`Overwrite the file: ${duplicateFilename}`}
modalLabel="Overwrite file?"
primaryButtonText="Yes"
secondaryButtonText="Cancel"
onSecondarySubmit={handleOverwriteFileCancel}
onRequestSubmit={handleOverwriteFileConfirm}
onRequestClose={handleOverwriteFileCancel}
/>
);
};
const displayOverwriteConfirmation = (filename: String) => {
setDuplicateFilename(filename);
setShowOverwriteConfirmationPrompt(true);
};
const checkDuplicateFile = (event: any) => {
if (processModel && processModel.files.length > 0) {
processModel.files.forEach((file) => {
if (file.name === filesToUpload[0].name) {
displayOverwriteConfirmation(file.name);
setFileUploadEvent(event);
}
});
}
};
const handleFileUpload = (event: any) => {
if (processModel) {
checkDuplicateFile(event);
}
setShowFileUploadModal(false);
};
const fileUploadModal = () => {
return (
@ -550,6 +599,7 @@ export default function ProcessModelShow() {
return (
<>
{fileUploadModal()}
{confirmOverwriteFileDialog()}
<ProcessBreadcrumb
hotCrumbs={[
['Process Groups', '/admin'],