diff options
author | Dmitrii Filippov <dmfilippov@google.com> | 2019-07-09 22:10:16 +0200 |
---|---|---|
committer | Dmitrii Filippov <dmfilippov@google.com> | 2019-08-01 13:38:49 +0000 |
commit | 9edee6c312515d301b46584fec42abe62da01abb (patch) | |
tree | 5ad8a8a85dc1dd5f2bb8fee71e10ef6fb54e3bbf | |
parent | b4739721d3efccf2d57706c0cacad96256e4f042 (diff) |
Fix timeout waiting for endpoint properties initialization
gr-confirm-dialog contains gr-endpoint-decorator. gr-endpoint-param
with the name action is bound to gr-confirm-dialog.action property.
During the initialization, gr-endpoint-decorator waits while all
properties are assigned. If a server returns revisionActions without
submit property, then thr binding is not updated and
gr-endpoint-decorator doesn't receive the notification when
initialization is complete.
Bug: Issue 11120
Change-Id: I529812c45edecf584897a4168fde28835feb316e
3 files changed, 84 insertions, 2 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html index e69d48f13f..1e50e4bfba 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html @@ -176,7 +176,7 @@ limitations under the License. on-cancel="_handleConfirmDialogCancel" branch="[[change.branch]]" has-parent="[[hasParent]]" - rebase-on-current="[[revisionActions.rebase.rebaseOnCurrent]]" + rebase-on-current="[[_revisionRebaseAction.rebaseOnCurrent]]" hidden></gr-confirm-rebase-dialog> <gr-confirm-cherrypick-dialog id="confirmCherrypick" class="confirmDialog" @@ -216,7 +216,7 @@ limitations under the License. id="confirmSubmitDialog" class="confirmDialog" change="[[change]]" - action="[[revisionActions.submit]]" + action="[[_revisionSubmitAction]]" on-cancel="_handleConfirmDialogCancel" on-confirm="_handleSubmitConfirm" hidden></gr-confirm-submit-dialog> <gr-dialog id="createFollowUpDialog" diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js index 83a454b20b..02bf783772 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js @@ -271,6 +271,20 @@ type: Object, value() { return {}; }, }, + // If property binds directly to [[revisionActions.submit]] it is not + // updated when revisionActions doesn't contain submit action. + /** @type {?} */ + _revisionSubmitAction: { + type: Object, + computed: '_getSubmitAction(revisionActions)', + }, + // If property binds directly to [[revisionActions.rebase]] it is not + // updated when revisionActions doesn't contain rebase action. + /** @type {?} */ + _revisionRebaseAction: { + type: Object, + computed: '_getRebaseAction(revisionActions)', + }, privateByDefault: String, _loading: { @@ -415,6 +429,28 @@ this._handleLoadingComplete(); }, + _getSubmitAction(revisionActions) { + return this._getRevisionAction(revisionActions, 'submit', null); + }, + + _getRebaseAction(revisionActions) { + return this._getRevisionAction(revisionActions, 'rebase', + {rebaseOnCurrent: null} + ); + }, + + _getRevisionAction(revisionActions, actionName, emptyActionValue) { + if (!revisionActions) { + return undefined; + } + if (revisionActions[actionName] === undefined) { + // Return null to fire an event when reveisionActions was loaded + // but doesn't contain actionName. undefined doesn't fire an event + return emptyActionValue; + } + return revisionActions[actionName]; + }, + reload() { if (!this.changeNum || !this.latestPatchNum) { return Promise.resolve(); diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html index 184e175419..b88e06b3d8 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html @@ -1513,4 +1513,50 @@ limitations under the License. assert.equal(reportStub.lastCall.args[0], 'type-key'); }); }); + + suite('getChangeRevisionActions returns only some actions', () => { + let element; + let sandbox; + let changeRevisionActions; + + setup(() => { + stub('gr-rest-api-interface', { + getChangeRevisionActions() { + return Promise.resolve(changeRevisionActions); + }, + send(method, url, payload) { + return Promise.reject(new Error('error')); + }, + getProjectConfig() { return Promise.resolve({}); }, + }); + + sandbox = sinon.sandbox.create(); + sandbox.stub(Gerrit, 'awaitPluginsLoaded').returns(Promise.resolve()); + + element = fixture('basic'); + // getChangeRevisionActions is not called without + // set the following properies + element.change = {}; + element.changeNum = '42'; + element.latestPatchNum = '2'; + + + sandbox.stub(element.$.confirmCherrypick.$.restAPI, + 'getRepoBranches').returns(Promise.resolve([])); + sandbox.stub(element.$.confirmMove.$.restAPI, + 'getRepoBranches').returns(Promise.resolve([])); + return element.reload(); + }); + + teardown(() => { + sandbox.restore(); + }); + + test('confirmSubmitDialog and confirmRebase properties are changed', () => { + changeRevisionActions = {}; + element.reload(); + assert.strictEqual(element.$.confirmSubmitDialog.action, null); + assert.strictEqual(element.$.confirmRebase.rebaseOnCurrent, null); + }); + }); </script> |