diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js index d829b63b8..eb787e306 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js @@ -88,9 +88,7 @@ export const FileUploaderComponent = ({ (accumulators, file) => { if (filesNamesSet.has(file.name)) { accumulators.duplicateFiles.push(file); - } - - if (file.size === 0) { + } else if (file.size === 0) { accumulators.emptyFiles.push(file); } else { accumulators.nonEmptyFiles.push(file); @@ -102,7 +100,7 @@ export const FileUploaderComponent = ({ ); const hasEmptyFiles = !_isEmpty(emptyFiles); - const hasNonEmptyFiles = !_isEmpty(nonEmptyFiles); + const hasDuplicateFiles = !_isEmpty(duplicateFiles); if (maxFileNumberReached) { setWarningMsg( @@ -110,10 +108,12 @@ export const FileUploaderComponent = ({ ); @@ -123,7 +123,7 @@ export const FileUploaderComponent = ({ {i18next.t("Uploading the selected files would result in")}{" "} @@ -138,35 +138,43 @@ export const FileUploaderComponent = ({ /> ); - } else if (!_isEmpty(duplicateFiles)) { - setWarningMsg( -
+ } else { + let warnings = []; + + if (hasDuplicateFiles) { + warnings.push( -
- ); - } else { + ); + } + if (!allowEmptyFiles && hasEmptyFiles) { - setWarningMsg( -
- -
+ warnings.push( + ); } - // Proceed with uploading the non-empty files or all files if empty files are allowed - if (allowEmptyFiles || hasNonEmptyFiles) { - uploadFiles(formikDraft, allowEmptyFiles ? acceptedFiles : nonEmptyFiles); + if (!_isEmpty(warnings)) { + setWarningMsg(
{warnings}
); + } + + const filesToUpload = allowEmptyFiles + ? [...nonEmptyFiles, ...emptyFiles] + : nonEmptyFiles; + + // Proceed with uploading files if there are any to upload + if (!_isEmpty(filesToUpload)) { + uploadFiles(formikDraft, filesToUpload); } } },