Refactor root navigation to generated URL

Change-Id: If969604814d3f2e859932f8a3bc26d14d22eac73
This commit is contained in:
Kasper Nilsson
2018-08-14 12:28:11 -07:00
parent a09d962867
commit 1c831a0fb6
4 changed files with 21 additions and 4 deletions

View File

@@ -961,9 +961,10 @@
},
_determinePageBack() {
// Default backPage to '/' if user came to change view page
// Default backPage to root if user came to change view page
// via an email link, etc.
Gerrit.Nav.navigateToRelativeUrl(this.backPage || '/');
Gerrit.Nav.navigateToRelativeUrl(this.backPage ||
Gerrit.Nav.getUrlForRoot());
},
_handleLabelRemoved(splices, path) {

View File

@@ -89,12 +89,13 @@ limitations under the License.
assert(starStub.called);
});
test('U should navigate to / if no backPage set', () => {
test('U should navigate to root if no backPage set', () => {
const relativeNavStub = sandbox.stub(Gerrit.Nav,
'navigateToRelativeUrl');
MockInteractions.pressAndReleaseKeyOn(element, 85, null, 'u');
assert.isTrue(relativeNavStub.called);
assert.isTrue(relativeNavStub.lastCall.calledWithExactly('/'));
assert.isTrue(relativeNavStub.lastCall.calledWithExactly(
Gerrit.Nav.getUrlForRoot()));
});
test('U should navigate to backPage if set', () => {

View File

@@ -70,6 +70,9 @@ limitations under the License.
// - `repoName`, required, String: the name of the repo
// - `detail`, optional, String: the name of the repo detail view.
// Takes any value from Gerrit.Nav.RepoDetailView.
//
// - Gerrit.Nav.View.ROOT:
// - no possible parameters.
window.Gerrit = window.Gerrit || {};
@@ -96,6 +99,7 @@ limitations under the License.
GROUP: 'group',
PLUGIN_SCREEN: 'plugin-screen',
REPO: 'repo',
ROOT: 'root',
SEARCH: 'search',
SETTINGS: 'settings',
},
@@ -411,6 +415,15 @@ limitations under the License.
});
},
/**
* @return {string}
*/
getUrlForRoot() {
return this._getUrlFor({
view: Gerrit.Nav.View.ROOT,
});
},
/**
* @param {string} repo The name of the repo.
* @param {!Array} sections The sections to display in the dashboard

View File

@@ -248,6 +248,8 @@
url = this._generateGroupUrl(params);
} else if (params.view === Views.REPO) {
url = this._generateRepoUrl(params);
} else if (params.view === Views.ROOT) {
url = '/';
} else if (params.view === Views.SETTINGS) {
url = this._generateSettingsUrl(params);
} else {