Merge "Add host to change list URL generation"

This commit is contained in:
Wyatt Allen 2018-07-11 21:16:48 +00:00 committed by Gerrit Code Review
commit b87ac165db
4 changed files with 42 additions and 9 deletions

View File

@ -171,10 +171,10 @@ limitations under the License.
</td>
<td class="cell project"
hidden$="[[isColumnHidden('Project', visibleChangeTableColumns)]]">
<a class="fullProject" href$="[[_computeProjectURL(change.project)]]">
<a class="fullProject" href$="[[_computeProjectURL(change)]]">
[[change.project]]
</a>
<a class="truncatedProject" href$="[[_computeProjectURL(change.project)]]">
<a class="truncatedProject" href$="[[_computeProjectURL(change)]]">
[[_computeTruncatedProject(change.project)]]
</a>
</td>

View File

@ -122,17 +122,19 @@
return '';
},
_computeProjectURL(project) {
return Gerrit.Nav.getUrlForProjectChanges(project, true);
_computeProjectURL(change) {
return Gerrit.Nav.getUrlForProjectChanges(change.project, true,
change.internalHost);
},
_computeProjectBranchURL(change) {
return Gerrit.Nav.getUrlForBranch(change.branch, change.project);
return Gerrit.Nav.getUrlForBranch(change.branch, change.project, null,
change.internalHost);
},
_computeTopicURL(change) {
if (!change.topic) { return ''; }
return Gerrit.Nav.getUrlForTopic(change.topic);
return Gerrit.Nav.getUrlForTopic(change.topic, change.internalHost);
},
_computeTruncatedProject(project) {

View File

@ -37,8 +37,10 @@ limitations under the License.
<script>
suite('gr-change-list-item tests', () => {
let element;
let sandbox;
setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
getConfig() { return Promise.resolve({}); },
getLoggedIn() { return Promise.resolve(false); },
@ -46,6 +48,8 @@ limitations under the License.
element = fixture('basic');
});
teardown(() => { sandbox.restore(); });
test('computed fields', () => {
assert.equal(element._computeLabelClass({labels: {}}),
'cell label u-gray-background');
@ -249,5 +253,25 @@ limitations under the License.
deletions: 999,
}), 'XL');
});
test('change params passed to gr-navigation', () => {
sandbox.stub(Gerrit.Nav);
const change = {
internalHost: 'test-host',
project: 'test-repo',
topic: 'test-topic',
branch: 'test-branch',
};
element.change = change;
flushAsynchronousOperations();
assert.deepEqual(Gerrit.Nav.getUrlForChange.lastCall.args, [change]);
assert.deepEqual(Gerrit.Nav.getUrlForProjectChanges.lastCall.args,
[change.project, true, change.internalHost]);
assert.deepEqual(Gerrit.Nav.getUrlForBranch.lastCall.args,
[change.branch, change.project, null, change.internalHost]);
assert.deepEqual(Gerrit.Nav.getUrlForTopic.lastCall.args,
[change.topic, change.internalHost]);
});
});
</script>

View File

@ -177,13 +177,15 @@ limitations under the License.
* @param {!string} project The name of the project.
* @param {boolean=} opt_openOnly When true, only search open changes in
* the project.
* @param {string=} opt_host The host in which to search.
* @return {string}
*/
getUrlForProjectChanges(project, opt_openOnly) {
getUrlForProjectChanges(project, opt_openOnly, opt_host) {
return this._getUrlFor({
view: Gerrit.Nav.View.SEARCH,
project,
statuses: opt_openOnly ? ['open'] : [],
host: opt_host,
});
},
@ -191,26 +193,30 @@ limitations under the License.
* @param {string} branch The name of the branch.
* @param {string} project The name of the project.
* @param {string=} opt_status The status to search.
* @param {string=} opt_host The host in which to search.
* @return {string}
*/
getUrlForBranch(branch, project, opt_status) {
getUrlForBranch(branch, project, opt_status, opt_host) {
return this._getUrlFor({
view: Gerrit.Nav.View.SEARCH,
branch,
project,
statuses: opt_status ? [opt_status] : undefined,
host: opt_host,
});
},
/**
* @param {string} topic The name of the topic.
* @param {string=} opt_host The host in which to search.
* @return {string}
*/
getUrlForTopic(topic) {
getUrlForTopic(topic, opt_host) {
return this._getUrlFor({
view: Gerrit.Nav.View.SEARCH,
topic,
statuses: ['open', 'merged'],
host: opt_host,
});
},
@ -267,6 +273,7 @@ limitations under the License.
patchNum: opt_patchNum,
basePatchNum: opt_basePatchNum,
edit: opt_isEdit,
host: change.internalHost || undefined,
});
},