Bug 1393478 - Fix Search on home r?chutten
Display when no data is found for the current filter.
MozReview-Commit-ID: Fqaso0MrHUP
--- a/toolkit/content/aboutTelemetry.js
+++ b/toolkit/content/aboutTelemetry.js
@@ -1402,24 +1402,26 @@ var Search = {
searchHandler(e) {
if (this.idleTimeout) {
clearTimeout(this.idleTimeout);
}
this.idleTimeout = setTimeout(() => Search.search(e.target.value), FILTER_IDLE_TIMEOUT);
},
- search(text, section = null) {
+ search(text, sectionParam = null) {
+ let section = sectionParam;
if (!section) {
let sectionId = document.querySelector(".category.selected").getAttribute("value");
section = document.getElementById(sectionId);
}
- let noSearchResults;
+ let noSearchResults = true;
if (section.id === "home-section") {
- return this.homeSearch(text);
+ this.homeSearch(text);
+ return;
} else if (section.id === "histograms-section") {
let histograms = section.getElementsByClassName("histogram");
noSearchResults = this.filterElements(histograms, text);
} else if (section.id === "keyed-histograms-section") {
let keyedElements = [];
let keyedHistograms = section.getElementsByClassName("keyed-histogram");
for (let key of keyedHistograms) {
let datas = key.getElementsByClassName("histogram");
@@ -1446,17 +1448,21 @@ var Search = {
let tables = section.querySelectorAll("table");
for (let table of tables) {
noSearchResults = this.filterElements(table.rows, text);
if (table.caption) {
table.caption.hidden = noSearchResults;
}
}
}
- this.updateNoResults(text, noSearchResults);
+
+ if (!sectionParam) { // If we are not searching in all section.
+ this.updateNoResults(text, noSearchResults);
+ }
+ return noSearchResults;
},
updateNoResults(text, noSearchResults) {
document.getElementById("no-search-results").classList.toggle("hidden", !noSearchResults);
if (noSearchResults) {
let section = document.querySelector(".category.selected > span");
let selectedTitle = section.textContent.trim();
if (section.parentElement.id === "category-home") {
@@ -1465,30 +1471,32 @@ var Search = {
let format = [selectedTitle, text];
let searchStatus = bundle.formatStringFromName("noSearchResults", format, 2);
document.getElementById("no-search-results-text").textContent = searchStatus;
}
},
resetHome() {
document.getElementById("main").classList.remove("search");
+ document.getElementById("no-search-results").classList.add("hidden");
adjustHeaderState();
Array.from(document.querySelectorAll("section")).forEach((section) => {
section.classList.toggle("active", section.id == "home-section");
});
},
homeSearch(text) {
if (text === "") {
this.resetHome();
return;
}
document.getElementById("main").classList.add("search");
let title = bundle.formatStringFromName("resultsForSearch", [text], 1);
adjustHeaderState(title);
+ let noSearchResults = true;
Array.from(document.querySelectorAll("section")).forEach((section) => {
if (section.id == "home-section" || section.id == "raw-payload-section") {
section.classList.remove("active");
return;
}
section.classList.add("active");
let sectionHidden = this.search(text, section);
if (noSearchResults && !sectionHidden) {