Skip to content

Commit

Permalink
#551: Fixed hashupdate issue which results sometimes in an endless lo…
Browse files Browse the repository at this point in the history
…op. (#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 <[email protected]>
  • Loading branch information
xceptance-dan and DK authored Jan 31, 2025
1 parent ce38045 commit 44e3e16
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions config/testreport/js/xlt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 44e3e16

Please sign in to comment.