Await plugin load before auto-opening revert dialog

The `?revert` query parameter will automatically open the revert dialog
when the change view loads, but would sometimes do so before plugins had
a chance to bind listeners for the revert event. With this change, the
revert dialog is not automatically opened until all plugins have loaded.

Bug: Issue 5189
Change-Id: Id731c2d140e01236175142ea9d3b88d53e3c4709
This commit is contained in:
Wyatt Allen
2016-12-21 16:56:34 -08:00
parent 03a690b6e8
commit a7835bc061
2 changed files with 16 additions and 9 deletions

View File

@@ -445,15 +445,18 @@
}, },
_maybeShowRevertDialog: function() { _maybeShowRevertDialog: function() {
this._getLoggedIn().then(function(loggedIn) { Gerrit.awaitPluginsLoaded()
if (!loggedIn || this._change.status !== this.ChangeStatus.MERGED) { .then(this._getLoggedIn.bind(this))
// Do not display dialog if not logged-in or the change is not merged. .then(function(loggedIn) {
return; if (!loggedIn || this._change.status !== this.ChangeStatus.MERGED) {
} // Do not display dialog if not logged-in or the change is not
if (!!this._getUrlParameter('revert')) { // merged.
this.$.actions.showRevertDialog(); return;
} }
}.bind(this)); if (!!this._getUrlParameter('revert')) {
this.$.actions.showRevertDialog();
}
}.bind(this));
}, },
_maybeShowReplyDialog: function() { _maybeShowReplyDialog: function() {

View File

@@ -612,6 +612,9 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getLoggedIn', function() { sandbox.stub(element.$.restAPI, 'getLoggedIn', function() {
return Promise.resolve(true); return Promise.resolve(true);
}); });
sandbox.stub(Gerrit, 'awaitPluginsLoaded', function() {
return Promise.resolve();
});
element._patchRange = { element._patchRange = {
basePatchNum: 'PARENT', basePatchNum: 'PARENT',
@@ -638,6 +641,7 @@ limitations under the License.
done); done);
element._maybeShowRevertDialog(); element._maybeShowRevertDialog();
assert.isTrue(Gerrit.awaitPluginsLoaded.called);
}); });
suite('scroll related tests', function() { suite('scroll related tests', function() {