Skip to content
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

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

Samk13
Copy link
Member

@Samk13 Samk13 commented Aug 27, 2024

❤️ Thank you for your contribution!

Description

upload-empty-files

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:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@Samk13 Samk13 changed the title WIP: handle empty files and upload non-empty files WIP: handle upload empty files Aug 27, 2024
@Samk13 Samk13 force-pushed the fix-empty-files-error branch 4 times, most recently from 400d2c8 to d94136e Compare August 28, 2024 10:50
@Samk13 Samk13 changed the title WIP: handle upload empty files UI: Handle empty file uploads in FileUploader Aug 28, 2024
@Samk13 Samk13 changed the title UI: Handle empty file uploads in FileUploader UI: Handle Empty File Uploads in FileUploader Aug 28, 2024
Samk13 added a commit to Samk13/invenio-app-rdm that referenced this pull request Aug 28, 2024
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
* Related to: inveniosoftware/invenio-rdm-records#1802
@Samk13 Samk13 force-pushed the fix-empty-files-error branch 5 times, most recently from f50bb40 to 2bc83b4 Compare August 29, 2024 15:19
@Samk13 Samk13 marked this pull request as ready for review August 29, 2024 15:19
Copy link
Contributor

@ntarocco ntarocco left a 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!

Comment on lines 84 to 85
const emptyFiles = acceptedFiles.filter((file) => file.size === 0);
const nonEmptyFiles = acceptedFiles.filter((file) => file.size > 0);
Copy link
Contributor

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?

Suggested change
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;
}
}

Copy link
Member Author

@Samk13 Samk13 Sep 13, 2024

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.

Samk13 added a commit to Samk13/invenio-app-rdm that referenced this pull request Sep 13, 2024
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
* Related to: inveniosoftware/invenio-rdm-records#1802
@Samk13 Samk13 force-pushed the fix-empty-files-error branch 2 times, most recently from 2b84f65 to 80bde7a Compare September 14, 2024 00:10
Samk13 added a commit to Samk13/invenio-app-rdm that referenced this pull request Sep 14, 2024
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
* Related to: inveniosoftware/invenio-rdm-records#1802
Samk13 added a commit to Samk13/invenio-app-rdm that referenced this pull request Sep 14, 2024
* 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.
* 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.
@Samk13
Copy link
Member Author

Samk13 commented Sep 14, 2024

@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.
So you can review this commit separately.
Screenshot from 2024-09-14 21-57-04

Copy link
Contributor

@ntarocco ntarocco left a 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 👏🏼

@ntarocco ntarocco merged commit 6d226ce into inveniosoftware:master Sep 19, 2024
4 checks passed
ntarocco pushed a commit to inveniosoftware/invenio-app-rdm that referenced this pull request Sep 19, 2024
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
* Related to: inveniosoftware/invenio-rdm-records#1802
Samk13 added a commit to inveniosoftware/invenio-app-rdm that referenced this pull request Sep 19, 2024
* Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
* Related to: inveniosoftware/invenio-rdm-records#1802
slint added a commit to slint/zenodo-rdm that referenced this pull request Sep 25, 2024
📁 invenio-accounts (5.1.1 -> 5.1.2 🐛)

    release: v5.1.2
    security: filter out current session if it's set to `None`

    * also, rename it to avoid controversial terminology
    dependencies: bump flask-security-invenio minimum

📁 invenio-app-rdm (13.0.0b1.dev3 -> 13.0.0b1.dev5 🌈)

    📦 release: v13.0.0b1.dev5
    deposit: Add allow-empty-files config available for deposit page

    * Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
    * Related to: inveniosoftware/invenio-rdm-records#1802
    deposit: provide permissions to publish button
    config: add group resolver for notifications
    admin-records: add reference to gh issue
    admin-records: account for system owned records
    migration: account for deleted communities and draft concept DOI
    css: added class for padding removal
    theme: fix accordion rotation
    template: mathjax remove from javascript block
    templates: add mathjax only to parent template
    landing page: support different MathJax delimeters
    search-result: namespace overridable id for community search results
    search-result: provide key to part of community array element
    fix: the following / prevents rspack from building
    release: v13.0.0b1.dev4
    config: make OAI-PMH record index dynamic
    modal: fix record adding to a community
    * closes inveniosoftware/invenio-app-rdm#2821

📁 invenio-banners (3.1.0 -> 3.1.1 🐛)

    📦 release: v3.1.1
    admin: adjust descriptions of fields

📁 invenio-files-rest (2.2.0 -> 2.2.1 🐛)

    release: v2.2.1
    fix: fix downloading for some weird filenames

    the following filenames couldn't be downloaded before:
    - is not `latin-1` encodable, ...
    - ...and contains a comma (`,`) character
    fix: apply invenio-accounts api changes

📁 invenio-jobs (0.5.0 -> 0.5.1 🐛)

    release: v0.5.1
    fix: add compatibility layer to move to flask>=3
    * flask-sqlalchemy moved pagination.
    * this change has been added to have a smooth migration to flask>=3.0.0
      without creating a hard cut and major versions release.

📁 invenio-oaiserver (2.2.1 -> 2.2.2 🐛)

    📦 release: v2.2.2
    percolator: allow lazy strings from config

📁 invenio-oauthclient (4.0.0 -> 4.0.2 🐛)

    release: v4.0.2
    views: fix boolean logic for checking remote app visibility
    release: v4.0.1
    global: explicitly set and use hide attribute for config
    fix: add flag for auth in keycloak realm url

📁 invenio-pages (4.1.0 -> 4.1.1 🐛)

    release: v4.1.1
    fix: add compatibility layer to move to flask>=3
    * flask-sqlalchemy moved pagination.
    * this change has been added to have a smooth migration to flask>=3.0.0
      without creating a hard cut and major versions release.

📁 invenio-rdm-records (12.1.0 -> 12.2.1 🌈)

    release: v12.2.1
    deposit: check permission and set disable tooltip for publish button
    Refactor: Enhance Warnings Handling
    * 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.
    UI: Handle empty file uploads in FileUploader
    * 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.
    serializers: ensure values are not None before access
    release: v12.1.1
    fixtures: allow to load new vocab
    resource: fix add record to community
    * Removes response_handler to avoid allowing
      to process the response with the schema
    * closes inveniosoftware/invenio-app-rdm#2821
    controls: refactored isDisabled function
    * Refactored isDisabled function in PublishButton and SubmitReviewButton components to check if all files are finished uploading before enabling the button.
    * Passed filesState instead of just the number of files to the function.
    * Added a check for non-finished files.
    * Added early returns to avoid unnecessary checks on possible large objects / arrays.

📁 invenio-requests (5.0.0 -> 5.1.0 🌈)

    release: v5.1.0
    assets: optimise detection if timeline was updated
    timeline feed: render mathematical content in the request comments

📁 invenio-theme (3.3.0 -> 3.4.0 🌈)

    release: v3.4.0
    config: add MathJax support
    navbar: fix logo size in non-desktop devices
    css: updated table border style

📁 invenio-users-resources (6.0.0 -> 6.1.0 🌈)

    release: v6.1.0
    users: services: Add can_read_all permission for admin search
    services: permissions: Use search_all config for admin user search
    CI: Switch To Centralised Workflows
    * Change branches type from string to array
    * Switch to centralised workflows

📁 invenio-vocabularies (5.0.2 -> 5.0.3 🐛)

    📦 release: v5.0.3
    services: skip index rebuilding
slint added a commit to slint/zenodo-rdm that referenced this pull request Sep 25, 2024
📁 invenio-accounts (5.1.1 -> 5.1.2 🐛)

    release: v5.1.2
    security: filter out current session if it's set to `None`

    * also, rename it to avoid controversial terminology
    dependencies: bump flask-security-invenio minimum

📁 invenio-app-rdm (13.0.0b1.dev3 -> 13.0.0b1.dev5 🌈)

    📦 release: v13.0.0b1.dev5
    deposit: Add allow-empty-files config available for deposit page

    * Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
    * Related to: inveniosoftware/invenio-rdm-records#1802
    deposit: provide permissions to publish button
    config: add group resolver for notifications
    admin-records: add reference to gh issue
    admin-records: account for system owned records
    migration: account for deleted communities and draft concept DOI
    css: added class for padding removal
    theme: fix accordion rotation
    template: mathjax remove from javascript block
    templates: add mathjax only to parent template
    landing page: support different MathJax delimeters
    search-result: namespace overridable id for community search results
    search-result: provide key to part of community array element
    fix: the following / prevents rspack from building
    release: v13.0.0b1.dev4
    config: make OAI-PMH record index dynamic
    modal: fix record adding to a community
    * closes inveniosoftware/invenio-app-rdm#2821

📁 invenio-banners (3.1.0 -> 3.1.1 🐛)

    📦 release: v3.1.1
    admin: adjust descriptions of fields

📁 invenio-files-rest (2.2.0 -> 2.2.1 🐛)

    release: v2.2.1
    fix: fix downloading for some weird filenames

    the following filenames couldn't be downloaded before:
    - is not `latin-1` encodable, ...
    - ...and contains a comma (`,`) character
    fix: apply invenio-accounts api changes

📁 invenio-jobs (0.5.0 -> 0.5.1 🐛)

    release: v0.5.1
    fix: add compatibility layer to move to flask>=3
    * flask-sqlalchemy moved pagination.
    * this change has been added to have a smooth migration to flask>=3.0.0
      without creating a hard cut and major versions release.

📁 invenio-oaiserver (2.2.1 -> 2.2.2 🐛)

    📦 release: v2.2.2
    percolator: allow lazy strings from config

📁 invenio-oauthclient (4.0.0 -> 4.0.2 🐛)

    release: v4.0.2
    views: fix boolean logic for checking remote app visibility
    release: v4.0.1
    global: explicitly set and use hide attribute for config
    fix: add flag for auth in keycloak realm url

📁 invenio-pages (4.1.0 -> 4.1.1 🐛)

    release: v4.1.1
    fix: add compatibility layer to move to flask>=3
    * flask-sqlalchemy moved pagination.
    * this change has been added to have a smooth migration to flask>=3.0.0
      without creating a hard cut and major versions release.

📁 invenio-rdm-records (12.1.0 -> 12.2.1 🌈)

    release: v12.2.1
    deposit: check permission and set disable tooltip for publish button
    Refactor: Enhance Warnings Handling
    * 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.
    UI: Handle empty file uploads in FileUploader
    * 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.
    serializers: ensure values are not None before access
    release: v12.1.1
    fixtures: allow to load new vocab
    resource: fix add record to community
    * Removes response_handler to avoid allowing
      to process the response with the schema
    * closes inveniosoftware/invenio-app-rdm#2821
    controls: refactored isDisabled function
    * Refactored isDisabled function in PublishButton and SubmitReviewButton components to check if all files are finished uploading before enabling the button.
    * Passed filesState instead of just the number of files to the function.
    * Added a check for non-finished files.
    * Added early returns to avoid unnecessary checks on possible large objects / arrays.

📁 invenio-requests (5.0.0 -> 5.1.0 🌈)

    release: v5.1.0
    assets: optimise detection if timeline was updated
    timeline feed: render mathematical content in the request comments

📁 invenio-theme (3.3.0 -> 3.4.0 🌈)

    release: v3.4.0
    config: add MathJax support
    navbar: fix logo size in non-desktop devices
    css: updated table border style

📁 invenio-users-resources (6.0.0 -> 6.1.0 🌈)

    release: v6.1.0
    users: services: Add can_read_all permission for admin search
    services: permissions: Use search_all config for admin user search
    CI: Switch To Centralised Workflows
    * Change branches type from string to array
    * Switch to centralised workflows

📁 invenio-vocabularies (5.0.2 -> 5.0.3 🐛)

    📦 release: v5.0.3
    services: skip index rebuilding
slint added a commit to slint/zenodo-rdm that referenced this pull request Sep 25, 2024
📁 invenio-accounts (5.1.1 -> 5.1.2 🐛)

    release: v5.1.2
    security: filter out current session if it's set to `None`

    * also, rename it to avoid controversial terminology
    dependencies: bump flask-security-invenio minimum

    This is for v12 as invenio-users-resources at least needs it https://github.com/inveniosoftware/invenio-users-resources/blob/master/invenio_users_resources/resources/users/resource.py#L15 and invenio-accounts is the controlling distribution package for that dependency.

📁 invenio-app-rdm (13.0.0b1.dev3 -> 13.0.0b1.dev5 🌈)

    📦 release: v13.0.0b1.dev5
    deposit: Add allow-empty-files config available for deposit page

    * Expose `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` for UI control
    * Related to: inveniosoftware/invenio-rdm-records#1802
    deposit: provide permissions to publish button
    config: add group resolver for notifications
    admin-records: add reference to gh issue
    admin-records: account for system owned records
    migration: account for deleted communities and draft concept DOI
    css: added class for padding removal
    theme: fix accordion rotation
    template: mathjax remove from javascript block
    templates: add mathjax only to parent template
    landing page: support different MathJax delimeters

    * closes CERNDocumentServer/cds-rdm#133
    search-result: namespace overridable id for community search results
    search-result: provide key to part of community array element
    fix: the following / prevents rspack from building
    release: v13.0.0b1.dev4
    config: make OAI-PMH record index dynamic
    modal: fix record adding to a community

    * closes inveniosoftware/invenio-app-rdm#2821

📁 invenio-banners (3.1.0 -> 3.1.1 🐛)

    📦 release: v3.1.1
    admin: adjust descriptions of fields

📁 invenio-files-rest (2.2.0 -> 2.2.1 🐛)

    release: v2.2.1
    fix: fix downloading for some weird filenames

    the following filenames couldn't be downloaded before:
    - is not `latin-1` encodable, ...
    - ...and contains a comma (`,`) character
    fix: apply invenio-accounts api changes

    * This commit addresses compatibility issues caused by the recent API changes in the invenio-accounts module that is introduced in [this commit](inveniosoftware/invenio-accounts@5e1c583). It removes the usage of accounts_blueprint from invenio_files_rest and related tests, as it is no longer required and causes failures in the continuous integration (CI) tests. The change is aligned with the new release notes of invenio-accounts where this modification has been documented.

    * Upgrades Sphinx to >=5.0.0,<6.0.0 to address compatibility issues with Python 3.11. Removes deprecated 'formatargspec' from inspect, critical for Python 3.11 support and stability in our Invenio platform.

📁 invenio-jobs (0.5.0 -> 0.5.1 🐛)

    release: v0.5.1
    fix: add compatibility layer to move to flask>=3

    * flask-sqlalchemy moved pagination.

    * this change has been added to have a smooth migration to flask>=3.0.0
      without creating a hard cut and major versions release.

📁 invenio-oaiserver (2.2.1 -> 2.2.2 🐛)

    📦 release: v2.2.2
    percolator: allow lazy strings from config

📁 invenio-oauthclient (4.0.0 -> 4.0.2 🐛)

    release: v4.0.2
    views: fix boolean logic for checking remote app visibility
    release: v4.0.1
    global: explicitly set and use hide attribute for config
    fix: add flag for auth in keycloak realm url

📁 invenio-pages (4.1.0 -> 4.1.1 🐛)

    release: v4.1.1
    fix: add compatibility layer to move to flask>=3

    * flask-sqlalchemy moved pagination.

    * this change has been added to have a smooth migration to flask>=3.0.0
      without creating a hard cut and major versions release.

📁 invenio-rdm-records (12.1.0 -> 12.2.1 🌈)

    release: v12.2.1
    deposit: check permission and set disable tooltip for publish button
    Refactor: Enhance Warnings Handling

    * 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.
    UI: Handle empty file uploads in FileUploader

    * 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.
    serializers: ensure values are not None before access
    release: v12.1.1
    fixtures: allow to load new vocab
    resource: fix add record to community

    * Removes response_handler to avoid allowing
      to process the response with the schema
    * closes inveniosoftware/invenio-app-rdm#2821
    controls: refactored isDisabled function

    * Refactored isDisabled function in PublishButton and SubmitReviewButton components to check if all files are finished uploading before enabling the button.
    * Passed filesState instead of just the number of files to the function.
    * Added a check for non-finished files.
    * Added early returns to avoid unnecessary checks on possible large objects / arrays.

📁 invenio-requests (5.0.0 -> 5.1.0 🌈)

    release: v5.1.0
    assets: optimise detection if timeline was updated
    timeline feed: render mathematical content in the request comments

    * closes CERNDocumentServer/cds-rdm#133

📁 invenio-theme (3.3.0 -> 3.4.0 🌈)

    release: v3.4.0
    config: add MathJax support

    * closes CERNDocumentServer/cds-rdm#133
    navbar: fix logo size in non-desktop devices
    css: updated table border style

📁 invenio-users-resources (6.0.0 -> 6.1.0 🌈)

    release: v6.1.0
    users: services: Add can_read_all permission for admin search
    services: permissions: Use search_all config for admin user search
    CI: Switch To Centralised Workflows

    * Change branches type from string to array
    * Switch to centralised workflows

📁 invenio-vocabularies (5.0.2 -> 5.1.0 🌈)

    📦 release: v5.1.0
    funders: tune search boost for acronyms

    * Add and `acronym.keyword` field to the funders mapping.
    * Apply to funders the same field boosting as in affiliations.
    📦 release: v5.0.3
    services: skip index rebuilding
@Samk13 Samk13 deleted the fix-empty-files-error branch September 30, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backend errors not shown in record file upload screen and failed files cannot remove
3 participants