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:
commit
41c6dacbe2
|
@ -362,27 +362,76 @@ export default function ProcessModelShow() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [fileUploadEvent, setFileUploadEvent] = useState(null);
|
||||||
|
const [duplicateFilename, setDuplicateFilename] = useState<String>('');
|
||||||
|
const [showOverwriteConfirmationPrompt, setShowOverwriteConfirmationPrompt] =
|
||||||
|
useState(false);
|
||||||
|
|
||||||
|
const doFileUpload = (event: any) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const url = `/process-models/${modifiedProcessModelId}/files`;
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', filesToUpload[0]);
|
||||||
|
formData.append('fileName', filesToUpload[0].name);
|
||||||
|
HttpService.makeCallToBackend({
|
||||||
|
path: url,
|
||||||
|
successCallback: onUploadedCallback,
|
||||||
|
httpMethod: 'POST',
|
||||||
|
postBody: formData,
|
||||||
|
});
|
||||||
|
setFilesToUpload(null);
|
||||||
|
};
|
||||||
|
|
||||||
const handleFileUploadCancel = () => {
|
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) {
|
||||||
|
processModel.files.forEach((file) => {
|
||||||
|
if (file.name === filesToUpload[0].name) {
|
||||||
|
displayOverwriteConfirmation(file.name);
|
||||||
|
setFileUploadEvent(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleFileUpload = (event: any) => {
|
const handleFileUpload = (event: any) => {
|
||||||
if (processModel) {
|
if (processModel) {
|
||||||
event.preventDefault();
|
checkDuplicateFile(event);
|
||||||
const url = `/process-models/${modifiedProcessModelId}/files`;
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', filesToUpload[0]);
|
|
||||||
formData.append('fileName', filesToUpload[0].name);
|
|
||||||
HttpService.makeCallToBackend({
|
|
||||||
path: url,
|
|
||||||
successCallback: onUploadedCallback,
|
|
||||||
httpMethod: 'POST',
|
|
||||||
postBody: formData,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
setShowFileUploadModal(false);
|
setShowFileUploadModal(false);
|
||||||
setFilesToUpload(null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileUploadModal = () => {
|
const fileUploadModal = () => {
|
||||||
|
@ -550,6 +599,7 @@ export default function ProcessModelShow() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{fileUploadModal()}
|
{fileUploadModal()}
|
||||||
|
{confirmOverwriteFileDialog()}
|
||||||
<ProcessBreadcrumb
|
<ProcessBreadcrumb
|
||||||
hotCrumbs={[
|
hotCrumbs={[
|
||||||
['Process Groups', '/admin'],
|
['Process Groups', '/admin'],
|
||||||
|
|
Loading…
Reference in New Issue