Set projectLookup values in diff and change views

Moving this call from the router to the diff and change views helps
dedupe getChange calls when PolyGerrit is using a navigation component
other than gr-router, like in the embedded view scenario.

Change-Id: I41aff794af510d217792fc4d409d8d7d2dacab3d
This commit is contained in:
Kasper Nilsson
2018-04-11 11:10:53 -07:00
parent 2f90615543
commit 34a5d89e70
5 changed files with 35 additions and 2 deletions

View File

@@ -618,6 +618,10 @@
return;
}
if (value.changeNum && value.project) {
this.$.restAPI.setInProjectLookup(value.changeNum, value.project);
}
const patchChanged = this._patchRange &&
(value.patchNum !== undefined && value.basePatchNum !== undefined) &&
(this._patchRange.patchNum !== value.patchNum ||

View File

@@ -1729,5 +1729,18 @@ limitations under the License.
});
});
});
test('_paramsChanged sets in projectLookup', () => {
sandbox.stub(element.$.relatedChanges, 'reload');
sandbox.stub(element, '_reload').returns(Promise.resolve());
const setStub = sandbox.stub(element.$.restAPI, 'setInProjectLookup');
element._paramsChanged({
view: Gerrit.Nav.View.CHANGE,
changeNum: 101,
project: 'test-project',
});
assert.isTrue(setStub.calledOnce);
assert.isTrue(setStub.calledWith(101, 'test-project'));
});
});
</script>

View File

@@ -1316,8 +1316,6 @@
this._redirect(this._generateUrl(params));
} else {
this._setParams(params);
this.$.restAPI.setInProjectLookup(params.changeNum,
params.project);
}
},

View File

@@ -552,6 +552,10 @@
_paramsChanged(value) {
if (value.view !== Gerrit.Nav.View.DIFF) { return; }
if (value.changeNum && value.project) {
this.$.restAPI.setInProjectLookup(value.changeNum, value.project);
}
this.$.diff.lineOfInterest = this._getLineOfInterest(this.params);
this._initCursor(this.params);

View File

@@ -1041,5 +1041,19 @@ limitations under the License.
assert.isFalse(isVisible(element.$.reviewed));
});
});
test('_paramsChanged sets in projectLookup', () => {
sandbox.stub(element, '_getLineOfInterest');
sandbox.stub(element, '_initCursor');
const setStub = sandbox.stub(element.$.restAPI, 'setInProjectLookup');
element._paramsChanged({
view: Gerrit.Nav.View.DIFF,
changeNum: 101,
project: 'test-project',
path: '',
});
assert.isTrue(setStub.calledOnce);
assert.isTrue(setStub.calledWith(101, 'test-project'));
});
});
</script>