Merge changes I7b542ddb,Ie9bea7f9
* changes: Call Gerrit.Nav.upgradeUrl from valid views Add function upgradeUrl to gr-navigation
This commit is contained in:
@@ -908,11 +908,11 @@
|
|||||||
|
|
||||||
_getChangeDetail() {
|
_getChangeDetail() {
|
||||||
return this.$.restAPI.getChangeDetail(this._changeNum,
|
return this.$.restAPI.getChangeDetail(this._changeNum,
|
||||||
this._handleGetChangeDetailError.bind(this)).then(
|
this._handleGetChangeDetailError.bind(this)).then(change => {
|
||||||
change => {
|
|
||||||
if (!change) {
|
if (!change) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
this._upgradeUrl(change, this.params);
|
||||||
// Issue 4190: Coalesce missing topics to null.
|
// Issue 4190: Coalesce missing topics to null.
|
||||||
if (!change.topic) { change.topic = null; }
|
if (!change.topic) { change.topic = null; }
|
||||||
if (!change.reviewer_updates) {
|
if (!change.reviewer_updates) {
|
||||||
@@ -945,6 +945,13 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_upgradeUrl(change, params) {
|
||||||
|
const project = change.project;
|
||||||
|
if (!params.project || project !== params.project) {
|
||||||
|
Gerrit.Nav.upgradeUrl(Object.assign({}, params, {project}));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_getComments() {
|
_getComments() {
|
||||||
return this.$.restAPI.getDiffComments(this._changeNum).then(
|
return this.$.restAPI.getDiffComments(this._changeNum).then(
|
||||||
comments => {
|
comments => {
|
||||||
|
|||||||
@@ -818,6 +818,7 @@ limitations under the License.
|
|||||||
|
|
||||||
test('topic is coalesced to null', done => {
|
test('topic is coalesced to null', done => {
|
||||||
sandbox.stub(element, '_changeChanged');
|
sandbox.stub(element, '_changeChanged');
|
||||||
|
sandbox.stub(element, '_upgradeUrl');
|
||||||
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
id: '123456789',
|
id: '123456789',
|
||||||
@@ -835,6 +836,7 @@ limitations under the License.
|
|||||||
|
|
||||||
test('commit sha is populated from getChangeDetail', done => {
|
test('commit sha is populated from getChangeDetail', done => {
|
||||||
sandbox.stub(element, '_changeChanged');
|
sandbox.stub(element, '_changeChanged');
|
||||||
|
sandbox.stub(element, '_upgradeUrl');
|
||||||
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
id: '123456789',
|
id: '123456789',
|
||||||
@@ -1236,5 +1238,31 @@ limitations under the License.
|
|||||||
element.dispatchEvent(new CustomEvent('topic-changed'));
|
element.dispatchEvent(new CustomEvent('topic-changed'));
|
||||||
assert.isTrue(element.$.relatedChanges.reload.calledOnce);
|
assert.isTrue(element.$.relatedChanges.reload.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
suite('_upgradeUrl calls', () => {
|
||||||
|
let upgradeStub;
|
||||||
|
const mockChange = {project: 'test'};
|
||||||
|
|
||||||
|
setup(() => {
|
||||||
|
upgradeStub = sandbox.stub(window.Gerrit.Nav, 'upgradeUrl');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('app.params.project undefined', () => {
|
||||||
|
element._upgradeUrl(mockChange, {});
|
||||||
|
assert.isTrue(upgradeStub.called);
|
||||||
|
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('app.params.project differs from change.project', () => {
|
||||||
|
element._upgradeUrl(mockChange, {project: 'demo'});
|
||||||
|
assert.isTrue(upgradeStub.called);
|
||||||
|
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('app.params.project === change.project', () => {
|
||||||
|
element._upgradeUrl(mockChange, {project: 'test'});
|
||||||
|
assert.isFalse(upgradeStub.called);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ limitations under the License.
|
|||||||
/** @type {Function} */
|
/** @type {Function} */
|
||||||
_generateUrl: uninitialized,
|
_generateUrl: uninitialized,
|
||||||
|
|
||||||
|
/** @type {Function} */
|
||||||
|
_upgradeUrl: uninitialized,
|
||||||
|
|
||||||
_checkPatchRange(patchNum, basePatchNum) {
|
_checkPatchRange(patchNum, basePatchNum) {
|
||||||
if (basePatchNum && !patchNum) {
|
if (basePatchNum && !patchNum) {
|
||||||
throw new Error('Cannot use base patch number without patch number.');
|
throw new Error('Cannot use base patch number without patch number.');
|
||||||
@@ -80,17 +83,20 @@ limitations under the License.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup router implementation.
|
* Setup router implementation.
|
||||||
* @param {Function} handleNavigate
|
* @param {Function} navigate
|
||||||
* @param {Function} generateUrl
|
* @param {Function} generateUrl
|
||||||
|
* @param {Function} upgradeUrl
|
||||||
*/
|
*/
|
||||||
setup(navigate, generateUrl) {
|
setup(navigate, generateUrl, upgradeUrl) {
|
||||||
this._navigate = navigate;
|
this._navigate = navigate;
|
||||||
this._generateUrl = generateUrl;
|
this._generateUrl = generateUrl;
|
||||||
|
this._upgradeUrl = upgradeUrl;
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this._navigate = uninitialized;
|
this._navigate = uninitialized;
|
||||||
this._generateUrl = uninitialized;
|
this._generateUrl = uninitialized;
|
||||||
|
this._upgradeUrl = uninitialized;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,6 +235,10 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
this._navigate(relativeUrl);
|
this._navigate(relativeUrl);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
upgradeUrl(params) {
|
||||||
|
this._upgradeUrl(params);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
})(window);
|
})(window);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -46,10 +46,18 @@
|
|||||||
page.base(base);
|
page.base(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const upgradeUrl = params => {
|
||||||
|
const url = generateUrl(params);
|
||||||
|
if (url !== window.location.pathname) {
|
||||||
|
history.replaceState(null, null, url);
|
||||||
|
app.params = params;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const restAPI = document.createElement('gr-rest-api-interface');
|
const restAPI = document.createElement('gr-rest-api-interface');
|
||||||
const reporting = getReporting();
|
const reporting = getReporting();
|
||||||
|
|
||||||
Gerrit.Nav.setup(url => { page.show(url); }, generateUrl);
|
Gerrit.Nav.setup(url => { page.show(url); }, generateUrl, upgradeUrl);
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
page((ctx, next) => {
|
page((ctx, next) => {
|
||||||
@@ -311,7 +319,7 @@
|
|||||||
if (params.basePatchNum &&
|
if (params.basePatchNum &&
|
||||||
patchNumEquals(params.basePatchNum, params.patchNum)) {
|
patchNumEquals(params.basePatchNum, params.patchNum)) {
|
||||||
params.basePatchNum = null;
|
params.basePatchNum = null;
|
||||||
history.replaceState(null, null, generateUrl(params));
|
upgradeUrl(params);
|
||||||
} else if (params.basePatchNum && !params.patchNum) {
|
} else if (params.basePatchNum && !params.patchNum) {
|
||||||
params.patchNum = params.basePatchNum;
|
params.patchNum = params.basePatchNum;
|
||||||
params.basePatchNum = null;
|
params.basePatchNum = null;
|
||||||
@@ -333,10 +341,9 @@
|
|||||||
path: ctx.params[8],
|
path: ctx.params[8],
|
||||||
view: ctx.params[8] ? Gerrit.Nav.View.DIFF : Gerrit.Nav.View.CHANGE,
|
view: ctx.params[8] ? Gerrit.Nav.View.DIFF : Gerrit.Nav.View.CHANGE,
|
||||||
};
|
};
|
||||||
|
|
||||||
normalizePatchRangeParams(params);
|
normalizePatchRangeParams(params);
|
||||||
app.params = params;
|
app.params = params;
|
||||||
history.replaceState(null, null, generateUrl(params));
|
upgradeUrl(params);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Matches /c/<changeNum>/[<basePatchNum>..][<patchNum>][/].
|
// Matches /c/<changeNum>/[<basePatchNum>..][<patchNum>][/].
|
||||||
|
|||||||
@@ -161,12 +161,19 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getChangeDetail(changeNum) {
|
_getChangeDetail(changeNum) {
|
||||||
return this.$.restAPI.getDiffChangeDetail(changeNum).then(
|
return this.$.restAPI.getDiffChangeDetail(changeNum).then(change => {
|
||||||
change => {
|
|
||||||
this._change = change;
|
this._change = change;
|
||||||
|
this._upgradeUrl(change, this.params);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_upgradeUrl(change, params) {
|
||||||
|
const project = change.project;
|
||||||
|
if (!params.project || project !== params.project) {
|
||||||
|
Gerrit.Nav.upgradeUrl(Object.assign({}, params, {project}));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_getFiles(changeNum, patchRangeRecord) {
|
_getFiles(changeNum, patchRangeRecord) {
|
||||||
const patchRange = patchRangeRecord.base;
|
const patchRange = patchRangeRecord.base;
|
||||||
return this.$.restAPI.getChangeFilePathsAsSpeciallySortedArray(
|
return this.$.restAPI.getChangeFilePathsAsSpeciallySortedArray(
|
||||||
|
|||||||
@@ -463,6 +463,7 @@ limitations under the License.
|
|||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getDiffComments() { return Promise.resolve({}); },
|
getDiffComments() { return Promise.resolve({}); },
|
||||||
});
|
});
|
||||||
|
sandbox.stub(element, '_upgradeUrl');
|
||||||
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
||||||
() => Promise.resolve());
|
() => Promise.resolve());
|
||||||
sandbox.stub(element.$.diff, 'reload');
|
sandbox.stub(element.$.diff, 'reload');
|
||||||
@@ -497,6 +498,7 @@ limitations under the License.
|
|||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getDiffComments() { return Promise.resolve({}); },
|
getDiffComments() { return Promise.resolve({}); },
|
||||||
});
|
});
|
||||||
|
sandbox.stub(element, '_upgradeUrl');
|
||||||
sandbox.stub(element.$.diff, 'reload');
|
sandbox.stub(element.$.diff, 'reload');
|
||||||
sandbox.stub(element, '_loadHash');
|
sandbox.stub(element, '_loadHash');
|
||||||
|
|
||||||
@@ -734,5 +736,31 @@ limitations under the License.
|
|||||||
assert.isNull(result.next);
|
assert.isNull(result.next);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
suite('_upgradeUrl calls', () => {
|
||||||
|
let upgradeStub;
|
||||||
|
const mockChange = {project: 'test'};
|
||||||
|
|
||||||
|
setup(() => {
|
||||||
|
upgradeStub = sandbox.stub(window.Gerrit.Nav, 'upgradeUrl');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('app.params.project undefined', () => {
|
||||||
|
element._upgradeUrl(mockChange, {});
|
||||||
|
assert.isTrue(upgradeStub.called);
|
||||||
|
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('app.params.project differs from change.project', () => {
|
||||||
|
element._upgradeUrl(mockChange, {project: 'demo'});
|
||||||
|
assert.isTrue(upgradeStub.called);
|
||||||
|
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('app.params.project === change.project', () => {
|
||||||
|
element._upgradeUrl(mockChange, {project: 'test'});
|
||||||
|
assert.isFalse(upgradeStub.called);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user