Hide all edit control dialogs before opening

Some dialogs may not fire their on-close event when closed in certain
ways (e.g. by clicking outside the dialog body). This call prevents
multiple edit control dialogs from being shown in the same overlay.

Bug: Issue 8405
Change-Id: I562be3f2203a5d0b2ab94868fdf32b8e53adf18f
diff --git a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.js b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.js
index 20ef8f4..e3b3494 100644
--- a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.js
+++ b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.js
@@ -133,6 +133,11 @@
     },
 
     _showDialog(dialog) {
+      // Some dialogs may not fire their on-close event when closed in certain
+      // ways (e.g. by clicking outside the dialog body). This call prevents
+      // multiple dialogs from being shown in the same overlay.
+      this._hideAllDialogs();
+
       return this.$.overlay.open().then(() => {
         dialog.classList.toggle('invisible', false);
         const autocomplete = dialog.querySelector('gr-autocomplete');
@@ -141,6 +146,11 @@
       });
     },
 
+    _hideAllDialogs() {
+      const dialogs = Polymer.dom(this.root).querySelectorAll('.dialog');
+      for (const dialog of dialogs) { this._closeDialog(dialog); }
+    },
+
     /**
      * @param {Element|undefined} dialog
      * @param {boolean=} clearInputs
diff --git a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html
index 00c8a3c..bbb5111 100644
--- a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html
+++ b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html
@@ -45,6 +45,7 @@
     element.change = {_number: '42'};
     showDialogSpy = sandbox.spy(element, '_showDialog');
     closeDialogSpy = sandbox.spy(element, '_closeDialog');
+    sandbox.stub(element, '_hideAllDialogs');
     queryStub = sandbox.stub(element.$.restAPI, 'queryChangeFiles')
         .returns(Promise.resolve([]));
     flushAsynchronousOperations();
@@ -79,6 +80,7 @@
       MockInteractions.tap(element.$$('#open'));
       element.patchNum = 1;
       return showDialogSpy.lastCall.returnValue.then(() => {
+        assert.isTrue(element._hideAllDialogs.called);
         assert.isTrue(element.$.openDialog.disabled);
         assert.isFalse(queryStub.called);
         element.$.openDialog.querySelector('gr-autocomplete').text =