-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
Add django-tables2 and utils, example, docs for usage with HTMX #35470
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bc2bbd5
add django_tables2
biyeun 6c3991e
add render_header template tag (to hq_tables_tags)
biyeun ce5dc40
add base bootstrap5 and bootstrap5 (with HTMX) templates for django t…
biyeun 7739c24
add saved, selectable pagination support to django tables
biyeun 89a8925
add styling for sortable headers with django tables
biyeun cbf36e8
trigger additional custom loading states with hq-hx-loading
biyeun 8b89672
add the hq-hx-refresh HTMX plugin
biyeun 0d6eeed
update hq_hx_refresh to be a little clearer
biyeun c22f690
add hq-hx loading and refresh plugins to base HTMX/Alpine entry point
biyeun 8462408
fix spacing
biyeun 798e0bb
add more fake data generators
biyeun 9ac7666
add BaseHtmxTable class
biyeun 0ca8a1d
css_id should be container_id
biyeun ff017a7
make sure clicking on table headers triggers the loading indicator fo…
biyeun 0813758
update util to use fake_data from prototype
biyeun 5a80d6a
add fake data for pagination example
biyeun eb3e897
add pagination example and documentation for HTMX + django-tables2
biyeun 09338eb
update docs for htmx and alpine
biyeun f9c29d7
"Bootstrap 5 Migration - Rebuilt diffs"
biyeun 615aaea
cleanup column sorting variables in render_header
biyeun 0161947
make sure to include a space between first and last names
biyeun 24853e4
simplify -- address PR feedback
biyeun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
corehq/apps/hqwebapp/static/hqwebapp/js/htmx_utils/hq_hx_loading.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Adds an `is-loading` class to the element with ID specified in the `hq-hx-loading` attribute. | ||
This `is-loading` class is applied when to that ID before an HTMX request begins, and is | ||
removed after an HTMX swap is completed. | ||
|
||
This is useful for adding loading indicators to elements outside the parent heirarchy available | ||
through using `hx-indicator` alone. Right now, this is used to add an `is-loading` style to a django tables | ||
table, which overlays a loading indicator across the entire table (seen in hqwebapp/tables/bootstrap5_htmx.html) | ||
*/ | ||
document.body.addEventListener('htmx:beforeRequest', (evt) => { | ||
if (evt.detail.elt.hasAttribute('hq-hx-loading')) { | ||
let loadingElt = document.getElementById(evt.detail.elt.getAttribute('hq-hx-loading')); | ||
if (loadingElt) { | ||
loadingElt.classList.add('is-loading'); | ||
} | ||
} | ||
}); | ||
document.body.addEventListener('htmx:afterSwap', (evt) => { | ||
if (evt.detail.elt.hasAttribute('hq-hx-loading')) { | ||
let loadingElt = document.getElementById(evt.detail.elt.getAttribute('hq-hx-loading')); | ||
if (loadingElt && loadingElt.classList.contains('is-loading')) { | ||
loadingElt.classList.remove('is-loading'); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that an error or similar outcome to the HTMX request could cause this loading indicator to not be removed? That seems like it could be disruptive to page interactions.
For usability it would be preferable to limit the scope of interactivity barriers to the smallest area possible. Any chance the scope could be reduced to a single table cell or row?
Caveat: I have not seen this in type of disable whole table workflow in real life before, so maybe it's not as bad as I am imagining?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's important for paginating the table that this workflow is in place, as clicking on an edit button, select row, etc during pagination would result in issues. Similarly during the whole table refresh process when filters are applied. I think if you see the data cleaning example on staging https://staging.commcarehq.org/prototype/dc/ (you need the FF enabled), then that will give you the interactive example.
TL;DR Cell-specific actions are already limited. The whole-table barrier is intentional and necessary.
I believe an error would still fire that event. Regardless, if there is an error on pagination, I think we have bigger issues...I would want a disruptive behavior. In any case, a page refresh is always possible.