5444 fix user feedback on clicking audit csv export button #5460
+56
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #5444
Description
Issue 5444 describes that after clicking the 'Export Audits' button, the button remains disabled, displaying "Please wait ...".
This button was disabled using
disable_with(from the_link_toui helper).In order to handle the state of the button, I added a stimulus controller. Furthermore, as it seems not possible to re-enable a button from the Stimulus controller that was disabled with
disable_with, I disabled the use ofdisable_withvia the parameters of thedownload_button_tohelper in the audits#index view in order to let the Stimulus controller handle the deactivation of the button as well.Although Turbo is enabled on that page, it does not seem to handle that request (probably because it is requesting a csv format rather than HTML?).
--> The Stimulus controller adds a 'click' EventListener to prevent the default behaviour and request the csv via AJAX. After downloading the csv, the cleanup function re-enables the button.
Caveats
(A possible solution might be setting a timeout in the cleanup function to delay the re-activation of the button.)
Additional remarks
I implemented the Stimulus controller in a way that should make it easy to reuse it. By disabling the use of
disable_withand adding the controller via the parameters of thedownload_button_tohelper that is placed in the view, it should work. In the Stimulus controller, I provided a default filename in case the filename received via the response cannot be correctly processed.(In case the Stimulus controller should be also reusable with other file downloads some refactoring would need to be done.)
Type of change
How Has This Been Tested?
Currently the Stimulus controller was only tested manually. The manual testing involved:
- that the button gets disabled until the download starts and then gets enabled again (see caveats)
- that the csv download works and the file receives the filename sent by the controller or a default name