Cleanup and base filter state revision

This commit is contained in:
Rachid Mrad 2024-06-27 18:36:06 -04:00
parent 65d9431ec5
commit 4ffecdd1c7
No known key found for this signature in database
7 changed files with 106 additions and 130 deletions

View file

@ -46,7 +46,7 @@ function ScrollToElement(attributeName, attributeValue) {
} else if (attributeName === 'id') { } else if (attributeName === 'id') {
targetEl = document.getElementById(attributeValue); targetEl = document.getElementById(attributeValue);
} else { } else {
console.log('Error: unknown attribute name provided.'); console.error('Error: unknown attribute name provided.');
return; // Exit the function if an invalid attributeName is provided return; // Exit the function if an invalid attributeName is provided
} }
@ -108,7 +108,7 @@ function ScrollToElement(attributeName, attributeValue) {
} else if (attributeName === 'id') { } else if (attributeName === 'id') {
targetEl = document.getElementById(attributeValue); targetEl = document.getElementById(attributeValue);
} else { } else {
console.log('Error: unknown attribute name provided.'); console.error('Error: unknown attribute name provided.');
return; // Exit the function if an invalid attributeName is provided return; // Exit the function if an invalid attributeName is provided
} }
@ -1141,26 +1141,6 @@ document.addEventListener('DOMContentLoaded', function() {
const statusIndicator = document.querySelector('.domain__filter-indicator'); const statusIndicator = document.querySelector('.domain__filter-indicator');
const statusToggle = document.querySelector('.usa-button--filter'); const statusToggle = document.querySelector('.usa-button--filter');
// Initialize the filters, but only if we're on the org domains page
const portfolioSidenav = document.querySelector('.usa-sidenav--portfolio');
if (portfolioSidenav) {
statusCheckboxes.forEach(checkbox => {
const checkboxValue = checkbox.value;
// Update currentStatus array based on checkbox state
if (checkbox.checked) {
currentStatus.push(checkboxValue);
} else {
const index = currentStatus.indexOf(checkboxValue);
if (index > -1) {
currentStatus.splice(index, 1);
}
}
});
} else {
// For non-portfolio users, disable filtering
currentStatus = ['unknown', 'ready', 'on hold', 'expired', 'deleted'];
}
/** /**
* Loads rows in the domains list, as well as updates pagination around the domains list * Loads rows in the domains list, as well as updates pagination around the domains list
* based on the supplied attributes. * based on the supplied attributes.
@ -1176,7 +1156,7 @@ document.addEventListener('DOMContentLoaded', function() {
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.error) { if (data.error) {
console.log('Error in AJAX call: ' + data.error); console.error('Error in AJAX call: ' + data.error);
return; return;
} }
@ -1305,7 +1285,7 @@ document.addEventListener('DOMContentLoaded', function() {
} }
// Manage visibility of reset filters button // Manage visibility of reset filters button
if (currentStatus.length == statusCheckboxes.length) { if (currentStatus.length == 0) {
hideElement(resetFiltersButton); hideElement(resetFiltersButton);
} else { } else {
showElement(resetFiltersButton); showElement(resetFiltersButton);
@ -1345,9 +1325,7 @@ document.addEventListener('DOMContentLoaded', function() {
function resetFilters() { function resetFilters() {
currentStatus = []; currentStatus = [];
statusCheckboxes.forEach(checkbox => { statusCheckboxes.forEach(checkbox => {
checkbox.checked = true; checkbox.checked = false;
const checkboxValue = checkbox.value;
currentStatus.push(checkboxValue);
}); });
hideElement(resetFiltersButton); hideElement(resetFiltersButton);
loadDomains(1, 'id', 'asc'); loadDomains(1, 'id', 'asc');
@ -1364,6 +1342,7 @@ document.addEventListener('DOMContentLoaded', function() {
function updateStatusIndicator() { function updateStatusIndicator() {
statusIndicator.innerHTML = ''; statusIndicator.innerHTML = '';
if (currentStatus.length)
statusIndicator.innerHTML = '(' + currentStatus.length + ')'; statusIndicator.innerHTML = '(' + currentStatus.length + ')';
} }
@ -1375,7 +1354,7 @@ document.addEventListener('DOMContentLoaded', function() {
// Instead of managing the toggle/close on the filter buttons in all edge cases (user clicks on search, user clicks on ANOTHER filter, // Instead of managing the toggle/close on the filter buttons in all edge cases (user clicks on search, user clicks on ANOTHER filter,
// user clicks on main nav...) we add a listener and close the filters whenever the focus shifts out of the dropdown menu/filter button. // user clicks on main nav...) we add a listener and close the filters whenever the focus shifts out of the dropdown menu/filter button.
// NOTE: We may need to evovle this as we add more filters. // NOTE: We may need to evolve this as we add more filters.
document.addEventListener('focusin', function(event) { document.addEventListener('focusin', function(event) {
const accordion = document.querySelector('.usa-accordion--select'); const accordion = document.querySelector('.usa-accordion--select');
const accordionIsOpen = document.querySelector('.usa-button--filter[aria-expanded="true"]'); const accordionIsOpen = document.querySelector('.usa-button--filter[aria-expanded="true"]');
@ -1481,7 +1460,7 @@ document.addEventListener('DOMContentLoaded', function() {
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.error) { if (data.error) {
console.log('Error in AJAX call: ' + data.error); console.error('Error in AJAX call: ' + data.error);
return; return;
} }

View file

@ -212,6 +212,6 @@ abbr[title] {
color: #{$dhs-dark-gray-85}; color: #{$dhs-dark-gray-85};
} }
.width-145 { .width-145px {
width: 145px; width: 145px;
} }

View file

@ -33,7 +33,7 @@
</section> </section>
</div> </div>
</div> </div>
<div class="domain-requests__table-wrapper display-none usa-table-container--scrollable" tabindex="0"> <div class="domain-requests__table-wrapper display-none usa-table-container--scrollable margin-top-0" tabindex="0">
<table class="usa-table usa-table--borderless usa-table--stacked dotgov-table dotgov-table--stacked domain-requests__table"> <table class="usa-table usa-table--borderless usa-table--stacked dotgov-table dotgov-table--stacked domain-requests__table">
<caption class="sr-only">Your domain requests</caption> <caption class="sr-only">Your domain requests</caption>
<thead> <thead>

View file

@ -34,7 +34,8 @@
</div> </div>
</div> </div>
{% if portfolio %} {% if portfolio %}
<span class="margin-right-2 text-base">Filter by</span> <div class="display-flex flex-align-center margin-top-1">
<span class="margin-right-2 margin-top-neg-1 text-base">Filter by</span>
<div class="usa-accordion usa-accordion--select margin-right-2"> <div class="usa-accordion usa-accordion--select margin-right-2">
<div class="usa-accordion__heading"> <div class="usa-accordion__heading">
<button <button
@ -43,7 +44,7 @@
aria-expanded="false" aria-expanded="false"
aria-controls="filter-status" aria-controls="filter-status"
> >
<span class="domain__filter-indicator text-bold">(5)</span> Status <span class="domain__filter-indicator text-bold"></span> Status
<svg class="usa-icon top-2px" aria-hidden="true" focusable="false" role="img" width="24"> <svg class="usa-icon top-2px" aria-hidden="true" focusable="false" role="img" width="24">
<use xlink:href="/public/img/sprite.svg#expand_more"></use> <use xlink:href="/public/img/sprite.svg#expand_more"></use>
</svg> </svg>
@ -52,7 +53,7 @@
<div id="filter-status" class="usa-accordion__content usa-prose shadow-1"> <div id="filter-status" class="usa-accordion__content usa-prose shadow-1">
<h2>Status</h2> <h2>Status</h2>
<fieldset class="usa-fieldset margin-top-0"> <fieldset class="usa-fieldset margin-top-0">
<legend class="usa-legend width-145">Select to apply <span class="sr-only">status</span> filter</legend> <legend class="usa-legend width-145px">Select to apply <span class="sr-only">status</span> filter</legend>
<div class="usa-checkbox"> <div class="usa-checkbox">
<input <input
class="usa-checkbox__input" class="usa-checkbox__input"
@ -60,7 +61,6 @@
type="checkbox" type="checkbox"
name="filter-status" name="filter-status"
value="unknown" value="unknown"
checked="checked"
/> />
<label class="usa-checkbox__label" for="filter-status-dns-needed" <label class="usa-checkbox__label" for="filter-status-dns-needed"
>DNS Needed</label >DNS Needed</label
@ -73,7 +73,6 @@
type="checkbox" type="checkbox"
name="filter-status" name="filter-status"
value="ready" value="ready"
checked="checked"
/> />
<label class="usa-checkbox__label" for="filter-status-ready" <label class="usa-checkbox__label" for="filter-status-ready"
>Ready</label >Ready</label
@ -86,7 +85,6 @@
type="checkbox" type="checkbox"
name="filter-status" name="filter-status"
value="on hold" value="on hold"
checked="checked"
/> />
<label class="usa-checkbox__label" for="filter-status-on-hold" <label class="usa-checkbox__label" for="filter-status-on-hold"
>On hold</label >On hold</label
@ -99,7 +97,6 @@
type="checkbox" type="checkbox"
name="filter-status" name="filter-status"
value="expired" value="expired"
checked="checked"
/> />
<label class="usa-checkbox__label" for="filter-status-expired" <label class="usa-checkbox__label" for="filter-status-expired"
>Expired</label >Expired</label
@ -112,7 +109,6 @@
type="checkbox" type="checkbox"
name="filter-status" name="filter-status"
value="deleted" value="deleted"
checked="checked"
/> />
<label class="usa-checkbox__label" for="filter-status-deleted" <label class="usa-checkbox__label" for="filter-status-deleted"
>Deleted</label >Deleted</label
@ -130,8 +126,9 @@
<use xlink:href="/public/img/sprite.svg#close"></use> <use xlink:href="/public/img/sprite.svg#close"></use>
</svg> </svg>
</button> </button>
</div>
{% endif %} {% endif %}
<div class="domains__table-wrapper display-none usa-table-container--scrollable" tabindex="0"> <div class="domains__table-wrapper display-none usa-table-container--scrollable margin-top-0" tabindex="0">
<table class="usa-table usa-table--borderless usa-table--stacked dotgov-table dotgov-table--stacked domains__table"> <table class="usa-table usa-table--borderless usa-table--stacked dotgov-table dotgov-table--stacked domains__table">
<caption class="sr-only">Your registered domains</caption> <caption class="sr-only">Your registered domains</caption>
<thead> <thead>

View file

@ -3,6 +3,6 @@
{% load static %} {% load static %}
{% block portfolio_content %} {% block portfolio_content %}
<h1>Domains</h1> <h1 class="margin-bottom-neg-2" id="domains-header">Domains</h1>
{% include "includes/domains_table.html" with portfolio=portfolio %} {% include "includes/domains_table.html" with portfolio=portfolio %}
{% endblock %} {% endblock %}

View file

@ -3,7 +3,7 @@
{% load static %} {% load static %}
{% block portfolio_content %} {% block portfolio_content %}
<h1>Domain requests</h1> <h1 id="domain-requests-header">Domain requests</h1>
{% comment %} {% comment %}
IMPORTANT: IMPORTANT: