-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Handle Empty File Uploads in FileUploader #1802
UI: Handle Empty File Uploads in FileUploader #1802
Conversation
400d2c8
to
d94136e
Compare
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control * Related to: inveniosoftware/invenio-rdm-records#1802
f50bb40
to
2bc83b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM! Just a few comments to make it a bit more readable!
...ds/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js
Outdated
Show resolved
Hide resolved
const emptyFiles = acceptedFiles.filter((file) => file.size === 0); | ||
const nonEmptyFiles = acceptedFiles.filter((file) => file.size > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor optimization... we ended up having 3 times filter
, maybe we can loop once?
const emptyFiles = acceptedFiles.filter((file) => file.size === 0); | |
const nonEmptyFiles = acceptedFiles.filter((file) => file.size > 0); | |
const filesNames = _map(filesList, "name"); | |
let hasEmptyFiles = false; | |
let hasNonEmptyFiles = false; | |
let hasDuplicatedFiles = false; | |
let nonEmptyFiles = []; | |
for (const file of acceptedFiles) { | |
if (file.size === 0) { | |
hasEmptyFiles = true; | |
} else { | |
hasNonEmptyFiles = true; | |
nonEmptyFiles.push(file); | |
} | |
if (filesNames.includes(file.name)) { | |
hasDuplicatedFiles = true; | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to use reduce to accumulate duplicate, empty, and non-empty files in a single pass. This allows us to track file names for warnings while maintaining efficiency and flexibility, as booleans alone can't e.g track file names.
Let me know if this works or if there's a better approach.
...ds/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js
Outdated
Show resolved
Hide resolved
...ds/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploader.js
Outdated
Show resolved
Hide resolved
...m_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/index.js
Outdated
Show resolved
Hide resolved
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control * Related to: inveniosoftware/invenio-rdm-records#1802
2b84f65
to
80bde7a
Compare
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control * Related to: inveniosoftware/invenio-rdm-records#1802
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control * Related to: inveniosoftware/invenio-rdm-records#1802
* Display a warning for empty files, indicating they won't be included and listing file names. * Feature controlled by `records-resources-allow-empty-files` config value. * Continue uploading other files while showing the warning message.
80bde7a
to
d6aab12
Compare
* Add the missing translation tags. * Refactor the logic to display multiple warning messages, while allowing other files to upload, except for case where exceeding the file size limit.
@ntarocco Since you wanted to improve readability, I've added a separate commit where I refactored the component. Now, the uploader continues uploading the rest of the files while showing warnings for duplicate files or empty files (was not possible before). I've also added other missing translations and small fixes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic improvement and very nice and readable implementation 👏🏼
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control * Related to: inveniosoftware/invenio-rdm-records#1802
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control * Related to: inveniosoftware/invenio-rdm-records#1802
❤️ Thank you for your contribution!
Description
records-resources-allow-empty-files
config value.Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Frontend
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: