Fix link generation in gr-repo-dashboards

Previously, link generation called a function that navigates, causing
the page to navigate to the first item in the list.

Instead, use existing attributes to generate the url rather than
navigate.

Bug: Issue 8730
Change-Id: Ic94f37fc8656f4be598f2c9dcc07c5d3b1238bbc
This commit is contained in:
Becky Siegel 2018-04-24 13:06:16 -07:00
parent 942a8fe8cf
commit 0f429c827b
4 changed files with 20 additions and 7 deletions

View File

@ -53,7 +53,7 @@ limitations under the License.
</tr>
<template is="dom-repeat" items="[[item.dashboards]]">
<tr class="table">
<td class="name"><a href$="[[_getUrl(item.url)]]">[[item.path]]</a></td>
<td class="name"><a href$="[[_getUrl(item.project, item.sections)]]">[[item.path]]</a></td>
<td class="title">[[item.title]]</td>
<td class="desc">[[item.description]]</td>
<td class="inherited">[[_computeInheritedFrom(item.project, item.defining_project)]]</td>

View File

@ -68,10 +68,10 @@
});
},
_getUrl(url) {
if (!url) { return ''; }
_getUrl(project, sections) {
if (!project || !sections) { return ''; }
return Gerrit.Nav.navigateToRelativeUrl(url);
return Gerrit.Nav.getUrlForCustomDashboard(project, sections);
},
_computeLoadingClass(loading) {

View File

@ -245,12 +245,12 @@ limitations under the License.
suite('test url', () => {
test('_getUrl', () => {
sandbox.stub(Gerrit.Nav, 'navigateToRelativeUrl',
sandbox.stub(Gerrit.Nav, 'getUrlForCustomDashboard',
() => '/r/dashboard/test');
assert.equal(element._getUrl('/dashboard/test'), '/r/dashboard/test');
assert.equal(element._getUrl('/dashboard/test', {}), '/r/dashboard/test');
assert.equal(element._getUrl(undefined), '');
assert.equal(element._getUrl(undefined, undefined), '');
});
});

View File

@ -404,6 +404,19 @@ limitations under the License.
});
},
/**
* @param {string} repo The name of the repo.
* @param {!Array} sections The sections to display in the dashboard
* @return {string}
*/
getUrlForCustomDashboard(repo, sections) {
return this._getUrlFor({
repo,
view: Gerrit.Nav.View.DASHBOARD,
sections,
});
},
/**
* Navigate to an arbitrary relative URL.
* @param {string} relativeUrl