Skip to content

Commit 05a4b50

Browse files
committed
fix: address code review feedback on category filter pills
- Add aria-pressed to category pill toggle buttons for screen readers - Eliminate double render on page load by deferring buildCatPills() until after loadFromHash() populates activeCategories - Fix URL round-trip for category names containing commas by encoding each value individually rather than encoding the joined string - Filter hash-restored categories against known categories to prevent silent zero-result state from stale/invalid URLs - Make category tags in test detail panels toggle (not add-only) to match the pill button behavior
1 parent 9ec4a25 commit 05a4b50

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

TUnit.Engine/Reporters/Html/HtmlReportGenerator.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,10 @@ function buildCatPills(){
12771277
var showing = catExpanded ? catNames : catNames.slice(0, catLimit);
12781278
showing.forEach(function(c){
12791279
var btn = document.createElement('button');
1280-
btn.className = 'pill cat-pill' + (activeCategories.has(c) ? ' active' : '');
1280+
var isActive = activeCategories.has(c);
1281+
btn.className = 'pill cat-pill' + (isActive ? ' active' : '');
12811282
btn.setAttribute('data-category', c);
1283+
btn.setAttribute('aria-pressed', isActive ? 'true' : 'false');
12821284
btn.textContent = c + ' ';
12831285
var cnt = document.createElement('span');
12841286
cnt.className='cat-count';
@@ -1301,7 +1303,6 @@ function buildCatPills(){
13011303
}
13021304
catRow.classList.add('visible');
13031305
}
1304-
if(catNames.length > 0) buildCatPills();
13051306
13061307
const spansByTrace = {};
13071308
const bySpanId = {};
@@ -1776,7 +1777,7 @@ function syncHash() {
17761777
if (sortMode !== 'default') p.push('sort=' + encodeURIComponent(sortMode));
17771778
if (searchText) p.push('search=' + encodeURIComponent(searchText));
17781779
if (groupMode !== 'class') p.push('group=' + encodeURIComponent(groupMode));
1779-
if (activeCategories.size > 0) p.push('category=' + encodeURIComponent(Array.from(activeCategories).join(',')));
1780+
if (activeCategories.size > 0) p.push('category=' + Array.from(activeCategories).map(encodeURIComponent).join(','));
17801781
history.replaceState(null, '', p.length ? '#' + p.join('&') : location.pathname);
17811782
}
17821783
@@ -1790,12 +1791,16 @@ function loadFromHash() {
17901791
const eq = pair.indexOf('=');
17911792
if (eq < 0) return;
17921793
const k = decodeURIComponent(pair.substring(0, eq));
1793-
const v = decodeURIComponent(pair.substring(eq + 1));
1794-
if (k === 'filter') activeFilter = v;
1795-
else if (k === 'sort') sortMode = v;
1796-
else if (k === 'search') { searchText = v; searchInput.value = v; clearBtn.style.display = v ? 'block' : 'none'; }
1797-
else if (k === 'group') groupMode = v;
1798-
else if (k === 'category') { v.split(',').forEach(function(c){ if(c) activeCategories.add(c); }); }
1794+
const rawV = pair.substring(eq + 1);
1795+
if (k === 'category') {
1796+
rawV.split(',').forEach(function(c){ c = decodeURIComponent(c); if(c && catCounts[c]) activeCategories.add(c); });
1797+
} else {
1798+
const v = decodeURIComponent(rawV);
1799+
if (k === 'filter') activeFilter = v;
1800+
else if (k === 'sort') sortMode = v;
1801+
else if (k === 'search') { searchText = v; searchInput.value = v; clearBtn.style.display = v ? 'block' : 'none'; }
1802+
else if (k === 'group') groupMode = v;
1803+
}
17991804
});
18001805
// Sync button active states
18011806
filterBtns.querySelectorAll('.pill').forEach(function(b) {
@@ -1813,7 +1818,6 @@ function loadFromHash() {
18131818
b.classList.toggle('active', isActive);
18141819
b.setAttribute('aria-checked', isActive ? 'true' : 'false');
18151820
});
1816-
if(activeCategories.size > 0) buildCatPills();
18171821
}
18181822
18191823
let lazyObs = null;
@@ -1889,7 +1893,8 @@ function ensureDetailRendered(det) {
18891893
if(catLink){
18901894
e.stopPropagation();
18911895
var cat=catLink.getAttribute('data-category');
1892-
if(!activeCategories.has(cat)) activeCategories.add(cat);
1896+
if(activeCategories.has(cat)) activeCategories.delete(cat);
1897+
else activeCategories.add(cat);
18931898
buildCatPills();renderLimit=20;render();syncHash();
18941899
return;
18951900
}
@@ -2000,6 +2005,7 @@ function ensureDetailRendered(det) {
20002005
document.getElementById('globalTimeline').innerHTML = renderGlobalTimeline();
20012006
20022007
loadFromHash();
2008+
if(catNames.length > 0) buildCatPills();
20032009
render();
20042010
renderFailedSection();
20052011
renderFailureClusters();

0 commit comments

Comments
 (0)