From 44e3e16659f772d05a2318579629f28f63ae676a Mon Sep 17 00:00:00 2001 From: xceptance-dan <122790040+xceptance-dan@users.noreply.github.com> Date: Fri, 31 Jan 2025 12:19:03 +0100 Subject: [PATCH] #551: Fixed hashupdate issue which results sometimes in an endless loop. (#554) * #551: Fixed hashupdate issue which results sometimes in an endless loop. * #551: Restored new-line, changed debouncing variable scope, restored sort after direct hash update --------- Co-authored-by: DK --- config/testreport/js/xlt.js | 63 +++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/config/testreport/js/xlt.js b/config/testreport/js/xlt.js index 8eef58adf..6c2318f07 100644 --- a/config/testreport/js/xlt.js +++ b/config/testreport/js/xlt.js @@ -677,43 +677,49 @@ scrollTo(); }); + // Variable that prevents triggering the hash update twice because of hash modifications inside updateHash + var ignoreNextHashChange = false; + // method that is called when the hash is updated. This happens if the user clicks on local anchors (table, charts), sorts tables by sortable table rows, updates the hash // directly in the URL or if the hash is updated via code function hashChanged(event){ - - // in some cases we have create a new hash out of a combination (old + new hash). For example, clicking on a request to get to the request charts totally wipes the hash. - // therefore we have to restore the sorting option and filter if there were any provided previously - var oldHashObj = splitHash(event.oldURL); - var newHashObj = splitHash(event.newURL); - - // hashes might contain a sorting option - if(oldHashObj.sort != undefined && newHashObj.sort == undefined){ - newHashObj.sort = oldHashObj.sort; + if(ignoreNextHashChange){ + ignoreNextHashChange = false; } + else{ + // in some cases we have create a new hash out of a combination (old + new hash). For example, clicking on a request to get to the request charts totally wipes the hash. + // therefore we have to restore the sorting option and filter if there were any provided previously + var oldHashObj = splitHash(event.oldURL); + var newHashObj = splitHash(event.newURL); - // hashes might contain a filter - if(oldHashObj.filter != undefined && newHashObj.filter == undefined){ - newHashObj.filter = oldHashObj.filter; - } + // hashes might contain a sorting option + if(oldHashObj.sort != undefined && newHashObj.sort == undefined){ + newHashObj.sort = oldHashObj.sort; + } - // sometimes sorting must be triggered from the update hash function. For example, when a user directly changes the sorting option (navbar) in the url - if(newHashObj.sort != undefined){ - var sortParam = newHashObj.sort.split('='); - var sortingElem = document.getElementById(sortParam[0]); - var sortingRule = sortParam[1]; + // hashes might contain a filter + if(oldHashObj.filter != undefined && newHashObj.filter == undefined){ + newHashObj.filter = oldHashObj.filter; + } - if(sortingElem != null){ - // this checks if a sorting is required (URL manually edited and not by clicking on a table row) - if(sortingElem.classList.contains("table-sorted-" + sortingRule) == false){ - sort(sortingElem, sortingRule); + // sometimes sorting must be triggered from the update hash function. For example, when a user directly changes the sorting option (navbar) in the url + if(newHashObj.sort != undefined){ + var sortParam = newHashObj.sort.split('='); + var sortingElem = document.getElementById(sortParam[0]); + var sortingRule = sortParam[1]; + + if(sortingElem != null){ + // this checks if a sorting is required (URL manually edited and not by clicking on a table row) + if(sortingElem.classList.contains("table-sorted-" + sortingRule) == false){ + sort(sortingElem, sortingRule); + } + } + else{ + alert('No sorting element with given ID found: ' + sortParam[0]) } } - else{ - alert('No sorting element with given ID found: ' + sortParam[0]) - } + updateHash(newHashObj); } - - updateHash(newHashObj); } // splits the given hash - automatically tries to detect the current format. the returned hash object might contain a "navigation", "sort" and "filter" option @@ -793,6 +799,9 @@ // update the sorting option of the hash hashObj.sort = sortingEvent.target.id + '=' + sortingRule; + // After sorting we update the hash manually, so we disable executing the next event + ignoreNextHashChange = true; + // trigger the hash change updateHash(hashObj); }