From 7af56a2a90f5c9cb27771ab9f367c204d600e1da Mon Sep 17 00:00:00 2001 From: Wyatt Allen Date: Fri, 20 Apr 2018 15:13:37 +0200 Subject: [PATCH] Create gr-confirm-submit-dialog component Move the confirm submit dialog's content into a component of its own and provide a new plugin endpoint to allow custom content to be added to the submit confirm dialog's message. Bug: Issue 8794 Change-Id: Ib8cf9edb5597b620eaa13846e278e053681abf70 --- Documentation/js-api.txt | 6 +- Documentation/pg-plugin-endpoints.txt | 17 +++++ .../gr-change-actions/gr-change-actions.html | 28 +++----- .../gr-change-actions_test.html | 7 +- .../gr-confirm-submit-dialog.html | 56 ++++++++++++++++ .../gr-confirm-submit-dialog.js | 65 +++++++++++++++++++ .../gr-confirm-submit-dialog_test.html | 63 ++++++++++++++++++ .../gr-confirm-dialog_test.html | 6 ++ polygerrit-ui/app/test/index.html | 1 + 9 files changed, 227 insertions(+), 22 deletions(-) create mode 100644 polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.html create mode 100644 polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.js create mode 100644 polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.html diff --git a/Documentation/js-api.txt b/Documentation/js-api.txt index 2df597115b..96b5107651 100644 --- a/Documentation/js-api.txt +++ b/Documentation/js-api.txt @@ -175,7 +175,11 @@ Supported events: and link:rest-api-changes.html#revision-info[RevisionInfo] are passed as arguments. Similar to a form submit validation, the function must return true to allow the operation to continue, or - false to prevent it. + false to prevent it. The function may be called multiple times, for + example, if submitting a change shows a confirmation dialog, this + event may be called to validate that the check whether dialog can be + shown, and called again when the submit is confirmed to check whether + the actual submission action can proceed. * `comment`: Invoked when a DOM element that represents a comment is created. This DOM element is passed as argument. This DOM element diff --git a/Documentation/pg-plugin-endpoints.txt b/Documentation/pg-plugin-endpoints.txt index b77a66b80c..ad613a57fb 100644 --- a/Documentation/pg-plugin-endpoints.txt +++ b/Documentation/pg-plugin-endpoints.txt @@ -124,3 +124,20 @@ This endpoint decorator wraps the voting buttons in the reply dialog. === header-title This endpoint wraps the title-text in the application header. + +=== confirm-submit-change +This endpoint is inside the confirm submit dialog. By default it displays a +generic confirmation message regarding submission of the change. Plugins may add +content to this message or replace it entirely. + +In addition to default parameters, the following are available: + +* `change` ++ +The change beinng potentially submitted, an instance of +link:rest-api-changes.html#change-info[ChangeInfo] + +* `action` ++ +The submit action, including the title and label, an instance of +link:rest-api-changes.html#action-info[ActionInfo] 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 f8c1ff4098..4f466f47ab 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 @@ -24,6 +24,7 @@ limitations under the License. + @@ -34,6 +35,7 @@ limitations under the License. + @@ -193,6 +195,13 @@ limitations under the License. on-confirm="_handleAbandonDialogConfirm" on-cancel="_handleConfirmDialogCancel" hidden> + - -
- Submit Change -
-
-

- Are you sure you want to to submit this change? -

-

- [[change.subject]] -

-
-
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 67d28f41a3..fa65075c86 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 @@ -252,8 +252,8 @@ limitations under the License. assert.deepEqual(result, actions); }); - test('submit change', done => { - element.$.confirmSubmitDialog.$.confirm.focus = done; + test('submit change', () => { + const showSpy = sandbox.spy(element, '_showActionDialog'); sandbox.stub(element.$.restAPI, 'getFromProjectLookup') .returns(Promise.resolve('test')); sandbox.stub(element, 'fetchChangeUpdates', @@ -270,6 +270,9 @@ limitations under the License. const submitButton = element.$$('gr-button[data-action-key="submit"]'); assert.ok(submitButton); MockInteractions.tap(submitButton); + + flushAsynchronousOperations(); + assert.isTrue(showSpy.calledWith(element.$.confirmSubmitDialog)); }); test('_handleSubmitConfirm', () => { diff --git a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.html b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.html new file mode 100644 index 0000000000..ad14a18ac2 --- /dev/null +++ b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.html @@ -0,0 +1,56 @@ + + + + + + + + + + + + diff --git a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.js new file mode 100644 index 0000000000..bda79a11b1 --- /dev/null +++ b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.js @@ -0,0 +1,65 @@ +/** + * @license + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +(function() { + 'use strict'; + + Polymer({ + is: 'gr-confirm-submit-dialog', + + /** + * Fired when the confirm button is pressed. + * + * @event confirm + */ + + /** + * Fired when the cancel button is pressed. + * + * @event cancel + */ + + properties: { + /** + * @type {{ + * subject: string, + * }} + */ + change: Object, + + /** + * @type {{ + * label: string, + * }} + */ + action: Object, + }, + + resetFocus(e) { + this.$.dialog.resetFocus(); + }, + + _handleConfirmTap(e) { + e.preventDefault(); + this.dispatchEvent(new CustomEvent('confirm', {bubbles: false})); + }, + + _handleCancelTap(e) { + e.preventDefault(); + this.dispatchEvent(new CustomEvent('cancel', {bubbles: false})); + }, + }); +})(); diff --git a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.html b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.html new file mode 100644 index 0000000000..86c15f6a6e --- /dev/null +++ b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.html @@ -0,0 +1,63 @@ + + + + +gr-confirm-submit-dialog + + + + + + + + + + + + + + + diff --git a/polygerrit-ui/app/elements/shared/gr-confirm-dialog/gr-confirm-dialog_test.html b/polygerrit-ui/app/elements/shared/gr-confirm-dialog/gr-confirm-dialog_test.html index 8300dd6179..70172122fe 100644 --- a/polygerrit-ui/app/elements/shared/gr-confirm-dialog/gr-confirm-dialog_test.html +++ b/polygerrit-ui/app/elements/shared/gr-confirm-dialog/gr-confirm-dialog_test.html @@ -73,5 +73,11 @@ limitations under the License. assert.isTrue(handleConfirmStub.called); }); + + test('resetFocus', () => { + const focusStub = sandbox.stub(element.$.confirm, 'focus'); + element.resetFocus(); + assert.isTrue(focusStub.calledOnce); + }); }); diff --git a/polygerrit-ui/app/test/index.html b/polygerrit-ui/app/test/index.html index 5a5dbcde1b..6e61c8ece5 100644 --- a/polygerrit-ui/app/test/index.html +++ b/polygerrit-ui/app/test/index.html @@ -71,6 +71,7 @@ limitations under the License. 'change/gr-confirm-move-dialog/gr-confirm-move-dialog_test.html', 'change/gr-confirm-rebase-dialog/gr-confirm-rebase-dialog_test.html', 'change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html', + 'change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.html', 'change/gr-download-dialog/gr-download-dialog_test.html', 'change/gr-file-list-header/gr-file-list-header_test.html', 'change/gr-file-list/gr-file-list_test.html',