Skip to content
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 22 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bc2bbd5
add django_tables2
biyeun Nov 19, 2024
6c3991e
add render_header template tag (to hq_tables_tags)
biyeun Nov 19, 2024
ce5dc40
add base bootstrap5 and bootstrap5 (with HTMX) templates for django t…
biyeun Nov 19, 2024
7739c24
add saved, selectable pagination support to django tables
biyeun Nov 19, 2024
89a8925
add styling for sortable headers with django tables
biyeun Nov 20, 2024
cbf36e8
trigger additional custom loading states with hq-hx-loading
biyeun Nov 20, 2024
8b89672
add the hq-hx-refresh HTMX plugin
biyeun Nov 21, 2024
0d6eeed
update hq_hx_refresh to be a little clearer
biyeun Dec 3, 2024
c22f690
add hq-hx loading and refresh plugins to base HTMX/Alpine entry point
biyeun Dec 3, 2024
8462408
fix spacing
biyeun Dec 3, 2024
798e0bb
add more fake data generators
biyeun Dec 3, 2024
9ac7666
add BaseHtmxTable class
biyeun Dec 3, 2024
0ca8a1d
css_id should be container_id
biyeun Dec 3, 2024
ff017a7
make sure clicking on table headers triggers the loading indicator fo…
biyeun Dec 3, 2024
0813758
update util to use fake_data from prototype
biyeun Dec 3, 2024
5a80d6a
add fake data for pagination example
biyeun Dec 3, 2024
eb3e897
add pagination example and documentation for HTMX + django-tables2
biyeun Dec 3, 2024
09338eb
update docs for htmx and alpine
biyeun Dec 3, 2024
f9c29d7
"Bootstrap 5 Migration - Rebuilt diffs"
biyeun Dec 9, 2024
615aaea
cleanup column sorting variables in render_header
biyeun Dec 17, 2024
0161947
make sure to include a space between first and last names
biyeun Dec 17, 2024
24853e4
simplify -- address PR feedback
biyeun Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensures nothing in the table can be interacted with until the HTMX request is complete

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?

Copy link
Member Author

@biyeun biyeun Dec 17, 2024

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.

*/
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');
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,43 @@
background-color: $blue-700;
}
}

.table-container {
position: relative;

.table-loading-indicator {
z-index: 1000;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(255, 255, 255, 0.25);
display: none;

&.is-loading {
display: block;
}

.spinner-border {
position: absolute;
border-width: $table-loading-spinner-border-width;
color: rgba(0, 0, 0, 0.25);
width: $table-loading-spinner-size;
height: $table-loading-spinner-size;
$_offset: $table-loading-spinner-size / 2;
left: calc(50% - $_offset);
top: calc(50% - $_offset);
}

.table-loading-progress {
z-index: 1000;
position: absolute;
top: 0;
left: 0;
width: 100%;
background-color: $white;
font-weight: bold;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,7 @@ $form-validation-states: (
// Make pagination-lg the same height as other lg inputs
$pagination-padding-x-lg: 1.0rem;
$pagination-padding-y-lg: 0.5rem;

// Table loading indicator
$table-loading-spinner-size: 150px;
$table-loading-spinner-border-width: 20px;