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

Add 'Download' button to record set attachment viewer #6052

Open
wants to merge 18 commits into
base: production
Choose a base branch
from

Conversation

alesan99
Copy link
Contributor

@alesan99 alesan99 commented Jan 8, 2025

Fixes #609

image

This PR adds two new features to speed up attachment downloading.

  1. When viewing the attachment gallery for a record set, a 'download all' button is now available. Clicking it should start downloading a zip file containing all the attachments.
  2. I also added new small download buttons to each individual attachment, which speeds up downloading a selection of attachments. This was applied universally.

Additional Notes:
The URL to download all the attachments is attachment_gw/download_all/. Couldn't come up with a better name, so if you have a better name let me know!
If you download multiple attachments with the same name they will be renamed to OriginalName_AssetServerName.EXT. I can also change this if it doesn't seem good enough.

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add automated tests
  • Add relevant issue to release milestone
  • Add relevant documentation (Tester - Dev)

Testing instructions

Test 'Download All' button:

  • Use a database that has a lot of attachments
  • In QB, run a Query on Collection Objects that have attachments
  • Browse in Forms
  • Click the attachment gallery icon on the header
  • Click the 'Download All' button
  • Download is successful
  • Verify that the zip file contains all the requested attachments with the correct filenames.
  • Make sure the download all button is only enabled when there are multiple attachments to download.
  • With many attachments, make sure the download all button doesn't break when not all attachments have been loaded yet.
  • Try out the button in different attachments galleries, like in individual records or in record sets.
  • Try to download multiple attachments with the same file name. Make sure they all get downloaded correctly. They should be named fileName_2.EXT and so on.
    Test small download buttons:
  • Verify that the download button works in different contexts (Attachment viewer, Record set attachment gallery, etc.)

@alesan99 alesan99 changed the title Add 'Download All' button to record set attachment viewer Add 'Download' button to record set attachment viewer Jan 8, 2025
@grantfitzsimmons
Copy link
Member

🐐

Fix trying to download unavailable attachments
WIP checkboxes?
Fix translations
Fix downloading files with the same filename
Add ability to recieve and download binary files on the frontend
@alesan99 alesan99 marked this pull request as ready for review January 15, 2025 19:40
@alesan99 alesan99 requested a review from a team January 15, 2025 19:40
@alesan99
Copy link
Contributor Author

Looking for feedback on these👇! This PR ended up being a bit bigger than I thought so I want to make sure everything is right,

Dev Note:
To my dismay, it looks like receiving zip files with a POST request wasn't possible with the existing utilities :(. The zip file would get turned into a string at multiple points of the process.
I had to change the ajax fetch utility a bit (and downloadFile). Once a response is read with response.text(), it can no longer be read with response.blob(), so I couldn't extract the original binary data further in the process.
I prioritized minimizing code impact mainly, but the code still might not be ideal.
I'm not comfortable messing with such important code, so I am looking on feedback on those changes especially.

Additional Notes:
The URL to download all the attachments is attachment_gw/download_all/. Couldn't come up with a better name, so if you have a better name let me know!
If you download multiple attachments with the same name they will be renamed to OriginalName_AssetServerName.EXT. I can also change this if it doesn't seem good enough.

Copy link
Member

@maxpatiiuk maxpatiiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job on a complex feature!

the changes in ajax() look good - this is exactly how I would have done it 🤗

<Button.DialogClose>{commonText.close()}</Button.DialogClose>
<>
<Button.Info
disabled={fetchedCount.current !== records.length || records.length <= 1}
Copy link
Member

@maxpatiiuk maxpatiiuk Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may not be clear to user that all attachments need to be bulked fetched by front-end for them to be downloadable
could you add a title={} with explanation to this button when it is disabled?

OR, call back-end API with record set id and let back-end retrieve list of attachments

specifyweb/frontend/js_src/lib/utils/ajax/index.ts Outdated Show resolved Hide resolved
Triggered by f8a5f8f on branch refs/heads/issue-609
WIP add tool tip to download all button when disabled
WIP use record set name as file name
Triggered by e598352 on branch refs/heads/issue-609
@CarolineDenis CarolineDenis requested a review from a team January 22, 2025 00:02
@CarolineDenis CarolineDenis added this to the 7.9.11.1 milestone Jan 22, 2025
Copy link
Contributor

@sharadsw sharadsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Good job!

Improve handling of files with same file name
Triggered by 8b1dea4 on branch refs/heads/issue-609
Copy link
Contributor

@pashiav pashiav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Download is successful
  • Verify that the zip file contains all the requested attachments with the correct filenames.
  • Make sure the download all button is only enabled when there are multiple attachments to download.
  • With many attachments, make sure the download all button doesn't break when not all attachments have been loaded yet.
  • Try to download multiple attachments with the same file name. Make sure they all get downloaded correctly. They should be named OriginalFileName_InternalFileName.EXT.
    Test small download buttons:
  • Verify that the download button works in different contexts (Attachment viewer, Record set attachment gallery, etc.)

Great work so far!

For:

  • Make sure the download all button is only enabled when there are multiple attachments to download.

The Download All button is a little confusing because it's disabled for a singular attachment/record. It says it downloads all attachments when you hover over it, so I think it should include and work for singular attachments too. Removing the button when there is only one attachment could work as well. @specify/ux-testing what do you think?

Screenshot 2025-01-22 at 8 43 03 AM



Also I found that if you have 1 record with 1 attachment, but select multiple records which do not have any attachments, the Download All button is functional and will create a zip file of only 1 attachment.

To reproduce:

  1. Select a record with 1 attachment in QB
  2. Select other records with no attachments in addition to it
  3. Click Browse in Forms -> Attachment Gallery icon -> Download All
  4. See a zip file has been downloaded with 1 attachment
Screen.Recording.2025-01-22.at.11.43.30.AM.mov

@pashiav pashiav requested a review from a team January 22, 2025 17:52
Copy link
Contributor

@Areyes42 Areyes42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Download is successful
  • Verify that the zip file contains all the requested attachments with the correct filenames.
  • Make sure the download all button is only enabled when there are multiple attachments to download.
  • With many attachments, make sure the download all button doesn't break when not all attachments have been loaded yet.
  • Try out the button in different attachments galleries, like in individual records or in record sets.
  • Try to download multiple attachments with the same file name. Make sure they all get downloaded correctly. They should be named fileName_2.EXT and so on.
    Test small download buttons:
  • Verify that the download button works in different contexts (Attachment viewer, Record set attachment gallery, etc.)

Great work so far, Alejandro!

For #6052 (review), I agree that keeping the Download All option for records with only one attachment is more consistent, even if it feels redundant. I also noticed that when browsing a single form with multiple attachments, the Download All button is also disabled.

Screenshot 2025-01-22 at 1 42 05 PM

Additionally, I kept running into a crash dialog while using the Download All button on the KUFish databases. Initially, I thought it might be related to the asset server configuration, preventing it from properly fetching the assets. However, I was able to download each asset individually without issues, so I'm thinking it might be another issue. The errors only occurred when trying to download all attachments at once.

Screen.Recording.2025-01-22.at.2.10.14.PM.mov

Specify 7 Crash Report - 2025-01-22T20_11_48.389Z.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Dev Attention Needed
Development

Successfully merging this pull request may close these issues.

Add ability to download multiple attachments
7 participants