Confirm before overwriting file when uploading file with same name

This commit is contained in:
mike cullerton 2022-12-09 17:44:25 -05:00
parent 3800389e4c
commit 4c882a84b6
1 changed files with 62 additions and 12 deletions

View File

@ -360,13 +360,12 @@ export default function ProcessModelShow() {
); );
}; };
const handleFileUploadCancel = () => { const [fileUploadEvent, setFileUploadEvent] = useState(null);
setShowFileUploadModal(false); const [duplicateFilename, setDuplicateFilename] = useState<String>('');
setFilesToUpload(null); const [showOverwriteConfirmationPrompt, setShowOverwriteConfirmationPrompt] =
}; useState(false);
const handleFileUpload = (event: any) => { const doFileUpload = (event: any) => {
if (processModel) {
event.preventDefault(); event.preventDefault();
const url = `/process-models/${modifiedProcessModelId}/files`; const url = `/process-models/${modifiedProcessModelId}/files`;
const formData = new FormData(); const formData = new FormData();
@ -378,10 +377,60 @@ export default function ProcessModelShow() {
httpMethod: 'POST', httpMethod: 'POST',
postBody: formData, postBody: formData,
}); });
} setFilesToUpload(null);
};
const handleFileUploadCancel = () => {
setShowFileUploadModal(false); setShowFileUploadModal(false);
setFilesToUpload(null); 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) {
for (const file in processModel.files) {
if (processModel.files[file].name === filesToUpload[0].name) {
displayOverwriteConfirmation(processModel.files[file].name);
setFileUploadEvent(event);
}
}
}
};
const handleFileUpload = (event: any) => {
if (processModel) {
checkDuplicateFile(event);
}
setShowFileUploadModal(false);
};
const fileUploadModal = () => { const fileUploadModal = () => {
return ( return (
@ -548,6 +597,7 @@ export default function ProcessModelShow() {
return ( return (
<> <>
{fileUploadModal()} {fileUploadModal()}
{confirmOverwriteFileDialog()}
<ProcessBreadcrumb <ProcessBreadcrumb
hotCrumbs={[ hotCrumbs={[
['Process Groups', '/admin'], ['Process Groups', '/admin'],