Skip to content

Conversation

@bellitabellota
Copy link
Contributor

@bellitabellota bellitabellota commented Dec 2, 2025

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_to ui 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 of disable_with via the parameters of the download_button_to helper 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

  • Currently, if the Ajax request completes quickly, displaying the "Please wait ..." text and disabling the button only occurs for less than a second. Through human eyes, this is just perceived as a flickering. So users with fast internet might not see that text and they might not be prevented from downloading the file twice through a double click.

(A possible solution might be setting a timeout in the cleanup function to delay the re-activation of the button.)

  • Downloading the csv via an Ajax request complicates testing.

Additional remarks

I implemented the Stimulus controller in a way that should make it easy to reuse it. By disabling the use of disable_with and adding the controller via the parameters of the download_button_to helper 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

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

How Has This Been Tested?

Currently the Stimulus controller was only tested manually. The manual testing involved:

  • checking if the errors in the fetch request are logged to the console if they are triggered
  • verifying that when the button is clicked:
    - 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

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.

Fix user feedback on clicking Audit CSV export button

1 participant