Bug 1396855 - about:telemetry : Added search terms in the URL fragment. r=chutten

Implementation of the search terms in the url fragment was done as concisely as possible(considering the various conditions required, with the underscore when other hash terms are present). To implement search through hashes in URL, the function urlStateRestore() was changed. To make the changes more aesthetic, another function urlSectionRestore() performs the tasks earlier performed by urlStateRestore(), and urlStateRestore() now implements the search parsing and a call to urlSectionRestore().

MozReview-Commit-ID: 9vgjNUpJkQG

--HG--
extra : rebase_source : c2cdb79e74faffa50bfd6636f0877f541f4f6ddf
This commit is contained in:
Vedant Chakravadhanula 2017-09-30 09:07:50 +05:30
Родитель b8af9874fd
Коммит ecc5186a64
1 изменённых файлов: 50 добавлений и 4 удалений

Просмотреть файл

@ -1275,6 +1275,8 @@ var Histogram = {
var Search = {
HASH_SEARCH: "search=",
// A list of ids of sections that do not support search.
blacklist: [
"raw-payload-section"
@ -1419,6 +1421,8 @@ var Search = {
}
}
changeUrlSearch(text);
if (!sectionParam) { // If we are not searching in all section.
this.updateNoResults(text, noSearchResults);
}
@ -1452,6 +1456,7 @@ var Search = {
},
homeSearch(text) {
changeUrlSearch(text);
if (text === "") {
this.resetHome();
return;
@ -1917,6 +1922,29 @@ function changeUrlPath(selectedSection, subSection) {
}
}
/**
* Change the url according to the current search text
*/
function changeUrlSearch(searchText) {
let currentHash = window.location.hash;
let hashWithoutSearch = currentHash.split(Search.HASH_SEARCH)[0];
let hash = "";
if (!currentHash && !searchText) {
return;
}
if (!currentHash.includes(Search.HASH_SEARCH) && hashWithoutSearch) {
hashWithoutSearch += "_";
}
if (searchText) {
hash = hashWithoutSearch + Search.HASH_SEARCH + searchText.replace(/ /g, "+");
} else if (hashWithoutSearch) {
hash = hashWithoutSearch.slice(0, hashWithoutSearch.length - 1);
}
window.location.hash = hash;
}
/**
* Change the section displayed
*/
@ -2072,10 +2100,10 @@ function setupListeners() {
});
}
// Restore sections states
function urlStateRestore() {
if (window.location.hash) {
let section = window.location.hash.slice(1).replace("-tab", "-section");
// Restores the sections states
function urlSectionRestore(hash) {
if (hash) {
let section = hash.replace("-tab", "-section");
let subsection = section.split("_")[1];
section = section.split("_")[0];
let category = document.querySelector(".category[value=" + section + "]");
@ -2090,6 +2118,24 @@ function urlStateRestore() {
}
}
// Restore sections states and search terms
function urlStateRestore() {
let hash = window.location.hash;
let searchQuery = "";
if (hash) {
hash = hash.slice(1);
if (hash.includes(Search.HASH_SEARCH)) {
searchQuery = hash.split(Search.HASH_SEARCH)[1].replace(/[+]/g, " ");
hash = hash.split(Search.HASH_SEARCH)[0];
}
urlSectionRestore(hash);
}
if (searchQuery) {
let search = document.getElementById("search");
search.value = searchQuery;
}
}
function openJsonInFirefoxJsonViewer(json) {
json = unescape(encodeURIComponent(json));
try {