-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Manage API tokens without page refresh or flash messages #8808
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
Conversation
htmx upgrade will disappear from this PR once #8837 is merged |
@mutantsan you mentioned a fix like https://github.com/DataShades/ckanext-collection/blob/master/ckanext/collection/assets/js/htmx-init-ckan-modules.js but that doesn't re-initialize elements that have already been initialized once. What's the link for that? |
Hey, @wardi. This is an example of such script. After an initialization, we're adding a custom attribute on an element, marking it as initialized. If there was no extra swap with HTMX, the attribute will remain there and tell us, that we don't need to initialize the CKAN module again. As about your PR:
|
While I've been thinking about the 1b, where you'd like to get some response from a server... Maybe we need to rework the notification system in CKAN a bit? For example, use something like this - https://marcelodolza.github.io/iziToast/ |
Thank you that's perfect. I've added this here https://github.com/ckan/ckan/pull/8808/files#diff-e142270f118d5903f9f1793439f0fac16469a99cc8af699ef95bc31283583120R18-R35
The revoke tokens button is now disabled until at least one token is selected.
I've fixed the confirm-actions module so it works with HTMX forms and added it back in.
This is the best approach I could think of because:
I've swapped the order so that newer tokens appear at the top right below the form (see the clip above). This way moving the focus to the new token typically doesn't have to scroll the page at all. I also think it makes more sense to see the recently created ones first.
Agreed. I've removed the error summary from the form. |
@wardi looks perfect now |
Bumping this back to a draft because I want to add some generic HTMX error display code to ckan as part of the same PR |
@amercader I've updated the error display with your feedback and used toasts based on @smotornyuk 's suggestion. Now when a standard error page is returned (e.g. via a If the message can't be found in the response we'll display the message from HTMX which includes the request URL that might be useful for users to report to the site maintainers: |
@wardi this looks good, we can merge once the typing error is fixed. I think the toasts design needs to be polished a bit but it can be done in a later PR. I have a big monitor and it wasn't very apparent at first. Perhaps we can increase the delay before they disappear. @aleeexgreeen just a heads up that we are now using this new UI element (just for errors coming from AJAX calls for now) |
Increasing the delay is a good idea. I did notice that they stay up if you hover or tap on them which is a nice touch. |
Fixes #8728
Proposed fixes:
This is an alternate approach for improving the API token UI that uses HTMX to update the page and display new tokens instead of storing a token in a flash message, redirecting and reloading the page to display it to the user. It's now also possible to revoke multiple tokens at the same time.
Screencast.from.2025-04-22.04.36.56.PM.webm
After clicking "Create API Token" one response from the server clears the form and adds the new API token to the table along with a the text that used to be a flash message at the top of the page.
This is a simple demonstration of the HTMX "Out of Band" swapping feature that lets us update multiple page elements with a single HTML response. The same out of band swap feature is used for revoking tokens: a single response sends a list of rows to delete from the table.
Also part of this PR:
confirm-actions
ckan JS module now works with HTMX forms (see revoke dialog above)Features: