From 0a4879a8f50701e37cdc5d3e3dde82c9cd182c76 Mon Sep 17 00:00:00 2001 From: Ivo Leist Date: Sun, 10 Dec 2023 12:49:19 +0100 Subject: [PATCH] it is no longer possible to upload a file multiple times --- .../submissionForms/SubmissionForms.jsx | 1 + .../inputFilesPond/InputFilesPond.jsx | 47 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/SubmissionForms.jsx b/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/SubmissionForms.jsx index ee1e9947..c9691b84 100644 --- a/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/SubmissionForms.jsx +++ b/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/SubmissionForms.jsx @@ -90,6 +90,7 @@ export default function SubmissionForms(props) { if (["redcap", "cdisc"].includes(inputFormat)) { if (Object.keys(uploadedFiles).length < 3) { toast.error("Please upload all required files"); + console.log(uploadedFiles); return; } diff --git a/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx b/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx index a64bdaaa..16950021 100644 --- a/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx +++ b/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx @@ -105,22 +105,21 @@ export default function InputFilesPond(props) { */ const returnedFileName = JSON.parse(file.serverId).tempFilename; - const fileName = file.filename; + const {filename, fileExtension} = file; - if (fileName in uploadedFiles) { + if (filename in uploadedFiles) { toast.error("File already uploaded"); - file.abortProcessing() + file.setMetadata("processingAborted", true) + file.abortProcessing(); return; } - const extension = fileName.split(".").pop(); - let fileType = "input-file"; - if (fileName.includes("dictionary") && extension === "csv") { + if (filename.includes("dictionary") && fileExtension === "csv") { fileType = "redcap-dictionary"; } else if ( - fileName.includes("mapping") && - ["yaml", "yml", "json"].includes(extension) + filename.includes("mapping") && + ["yaml", "yml", "json"].includes(fileExtension) ) { fileType = "mapping-file"; } @@ -128,7 +127,7 @@ export default function InputFilesPond(props) { setUploadedFiles((prev) => { return { ...prev, - [fileName]: [fileType, returnedFileName], + [filename]: [fileType, returnedFileName], }; }); }; @@ -274,29 +273,25 @@ export default function InputFilesPond(props) { setFilesUploadFinished(false); const fileName = file.filename; - // Not sure if below is working as expected - setUploadedFiles((prev) => { - const prevCopy = { ...prev }; - delete prevCopy[fileName]; - return prevCopy; - }); + // only update state if the file processing was finished (status 2 = IDLE) + // for reference see + // github.com/pqina/filepond-docs/blob/master/content/patterns/API/filepond-object.md#filestatus-enum + if (file.status === 2 && file.getMetadata("processingAborted") !== true) { + console.log("onremovefile") + console.log(uploadedFiles) + + setUploadedFiles((prev) => { + const prevCopy = { ...prev }; + delete prevCopy[fileName]; + return prevCopy; + }); + } }} // option provided by plugins acceptedFileTypes={acceptedFileTypesMapping[inputFormat]} fileValidateTypeLabelExpectedTypes={ expectedFileExtensionsMapping[inputFormat] } - // TODO - // when showing an error message increase the size of the filepond component - - // fileValidateTypeDetectType={ ( source, type ) => - // { - // console.log( source, type ); - // resolve( type ); - // } } - - // better get this from the server - // this should be a prop // so large file are only expected for OMOP (sqls) maxFileSize="1000MB"