Keep download buttons enabled after the file downloads (Resolves #5691) - #5725
costajohnt wants to merge 4 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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?
|
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 |
Resolves #5691
Description
download_button_torenders a GET link to asend_dataendpoint, so clicking it downloads a file without loading a new page. rails-ujs'data-disable-withswaps 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 waymodal_button_towas 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_tois 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_witha 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
How Has This Been Tested?
spec/helpers/ui_helper_spec.rb:download_button_tono longer emitsdata-disable-with, and caller-supplieddata: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...".spec/helpers/ui_helper_spec.rbandspec/system/annual_reports_system_spec.rbpass (17 examples).bundle exec rubocopis clean on the changed files.