Skip to content

Commit 3319032

Browse files
committed
Show info box if no results
1 parent 331746f commit 3319032

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pytest_mpl/summary/templates/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{navbar}
1313
<div class="album bg-light">
1414
<div class="container-fluid">
15+
<div id="noResultsAlert"></div>
1516
<div class="row list">
1617
{cards}
1718
</div>

pytest_mpl/summary/templates/extra.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ if (window.location.search.length > 0) {
3333
resultsList.sort('status-sort', {order: "desc"});
3434
}
3535

36+
// Show a message if no tests match current filters
37+
var alertPlaceholder = document.getElementById('noResultsAlert');
38+
warnIfNone(); // Initialize
39+
resultsList.on('updated', function () {
40+
warnIfNone();
41+
})
42+
3643
// Record URL parameters after new sort (but do not update URL yet)
3744
resultsList.on('sortComplete', function updateSortURL() {
3845
var sortElements = document.getElementsByClassName('sort');
@@ -184,3 +191,24 @@ function countClasses() {
184191
badge.innerHTML = count.toString();
185192
}
186193
}
194+
195+
function warnIfNone() {
196+
if (resultsList.visibleItems.length === 0) { // Show info box
197+
alertPlaceholder.innerHTML = '<div class="alert alert-info" role="alert">' +
198+
'<h4 class="alert-heading">No tests found</h4>' +
199+
'<p class="m-0">Try adjusting any active filters or searches, or ' +
200+
'<a href="javascript:clearAll()" class="alert-link">clear all</a>.</p>' +
201+
'</div>';
202+
} else { // Remove info box
203+
alertPlaceholder.innerHTML = '';
204+
}
205+
}
206+
207+
// Clear active search and filters
208+
function clearAll() {
209+
document.getElementsByClassName('search')[0].value = '';
210+
resultsList.search('');
211+
searchParams.delete('q');
212+
resetFilters();
213+
updateURL();
214+
}

0 commit comments

Comments
 (0)