Skip to content

Keep download buttons enabled after the file downloads (Resolves #5691) - #5725

Open
costajohnt wants to merge 4 commits into
rubyforgood:mainfrom
costajohnt:5691-download-button-stuck-please-wait
Open

costajohnt wants to merge 4 commits into
rubyforgood:mainfrom
costajohnt:5691-download-button-stuck-please-wait

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Resolves #5691

Description

download_button_to renders a GET link to a send_data endpoint, so clicking it downloads a file without loading a new page. rails-ujs' data-disable-with swaps the label to "Please wait..." on click and only restores it on the next page load, which never comes, so the button stays stuck.

This opts download buttons out of data-disable-with, the same way modal_button_to was fixed for #5632. It covers the annual report export and every other CSV export rendered through the helper (donations, purchases, vendors, audits, product drives, adjustments, donation sites). print_button_to is left alone: its PDFs are served inline, so the tab navigates and nothing gets stuck.

One side effect worth knowing: the "Export Yearly Reports" button on the annual reports index recalculates each year on the way out, and without disable_with a second click during that wait starts a second recalculation. It only duplicates work (the recalculation writes the same data), and the previous behaviour was the button being dead after the first click on every export, so I left it as is. If throttling is ever wanted there it belongs server side.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • spec/helpers/ui_helper_spec.rb: download_button_to no longer emits data-disable-with, and caller-supplied data: still merges in.
  • spec/system/annual_reports_system_spec.rb: clicks "Export Report" on a year's annual report, waits for the CSV download, and asserts the button still reads "Export Report" rather than "Please wait...".
  • With the helper change reverted, the two helper examples and the system example fail; with it, spec/helpers/ui_helper_spec.rb and spec/system/annual_reports_system_spec.rb pass (17 examples). bundle exec rubocop is clean on the changed files.

download_button_to renders a GET link to a send_data endpoint, so clicking
it downloads a file without loading a new page. rails-ujs' data-disable-with
only re-enables the link on the next page load, which never comes, and the
button stays stuck showing "Please wait...".

Opt download buttons out of data-disable-with, the same way modal_button_to
was fixed for rubyforgood#5632. This covers the annual report export and every other
CSV export button rendered through the helper.

Resolves rubyforgood#5691

@dorner dorner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This fixes the bug by introducing a worse bug, I'm afraid. The debouncing is important because some of these reports can be really beefy. If we have to choose between debouncing (and forcing a page reload) or not (and going without) I'd stick with debouncing.

Can you see if there's a way to keep the debounce but also fix the stuck behavior?

@costajohnt

Copy link
Copy Markdown
Contributor Author

Good point, I hadn't thought through the double-click case on the heavy reports. I put the debounce back: the button still switches to "Please wait..." on click, and a small Stimulus controller turns it back on 5 seconds later. rails-ujs only re-enables on the next page load, and a file download never triggers one. So a double-click during generation is still blocked, and the button doesn't stay stuck. If you'd rather re-enable when the file actually arrives, I can switch to a fetch-and-blob download like csv_download_controller.js. That's a bigger change across the ~20 download buttons, since a few endpoints redirect instead of sending a file.

This branch has not been deployed

No deployments
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.

Export button on annual report should revert to "Export Report" from "Please Wait..." once report generated.

2 participants