diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/assets/javascripts/merge_request_tabs.js | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/assets/javascripts/merge_request_tabs.js')
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index 1795a0dbdf8..6c63ab7cf95 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -126,6 +126,13 @@ export default class MergeRequestTabs { bindEvents() { $('.merge-request-tabs a[data-toggle="tabvue"]').on('click', this.clickTab); + window.addEventListener('popstate', event => { + if (event.state && event.state.action) { + this.tabShown(event.state.action, event.target.location); + this.currentAction = event.state.action; + this.eventHub.$emit('MergeRequestTabChange', this.getCurrentAction()); + } + }); } // Used in tests @@ -155,6 +162,12 @@ export default class MergeRequestTabs { } else if (action) { const href = e.currentTarget.getAttribute('href'); this.tabShown(action, href); + + if (this.setUrl) { + this.setCurrentAction(action); + } + + this.eventHub.$emit('MergeRequestTabChange', this.getCurrentAction()); } } } @@ -213,11 +226,6 @@ export default class MergeRequestTabs { this.resetViewContainer(); this.destroyPipelinesView(); } - if (this.setUrl) { - this.setCurrentAction(action); - } - - this.eventHub.$emit('MergeRequestTabChange', this.getCurrentAction()); } else if (action === this.currentAction) { // ContentTop is used to handle anything at the top of the page before the main content const mainContentContainer = document.querySelector('.content-wrapper'); @@ -287,19 +295,25 @@ export default class MergeRequestTabs { // Ensure parameters and hash come along for the ride newState += location.search + location.hash; - // TODO: Consider refactoring in light of turbolinks removal. - - // Replace the current history state with the new one without breaking - // Turbolinks' history. - // - // See https://github.com/rails/turbolinks/issues/363 - window.history.replaceState( - { - url: newState, - }, - document.title, - newState, - ); + if (window.history.state && window.history.state.url && window.location.pathname !== newState) { + window.history.pushState( + { + url: newState, + action: this.currentAction, + }, + document.title, + newState, + ); + } else { + window.history.replaceState( + { + url: window.location.href, + action, + }, + document.title, + window.location.href, + ); + } return newState; } |