Merge changes from topic "gr-confirm-revert-submission-dialog-to-ts"
* changes:
Convert gr-confirm-revert-submission-dialog to typescript
Rename files to preserve history
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 acafa25..0285f26 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
@@ -989,8 +989,7 @@
this.$.restAPI.getChanges('', query)
.then(changes => {
this.$.confirmRevertSubmissionDialog.
- _populateRevertSubmissionMessage(
- this.commitMessage, this.change, changes);
+ _populateRevertSubmissionMessage(this.change, changes);
this._showActionDialog(this.$.confirmRevertSubmissionDialog);
});
}
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.js
deleted file mode 100644
index a639a61..0000000
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.js
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * @license
- * Copyright (C) 2019 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.
- */
-import '../../shared/gr-dialog/gr-dialog.js';
-import '../../../styles/shared-styles.js';
-import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
-import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
-import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
-import {PolymerElement} from '@polymer/polymer/polymer-element.js';
-import {htmlTemplate} from './gr-confirm-revert-submission-dialog_html.js';
-
-const ERR_COMMIT_NOT_FOUND =
- 'Unable to find the commit hash of this change.';
-const CHANGE_SUBJECT_LIMIT = 50;
-
-/**
- * @extends PolymerElement
- */
-class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
- LegacyElementMixin(PolymerElement)) {
- static get template() { return htmlTemplate; }
-
- static get is() { return 'gr-confirm-revert-submission-dialog'; }
- /**
- * Fired when the confirm button is pressed.
- *
- * @event confirm
- */
-
- /**
- * Fired when the cancel button is pressed.
- *
- * @event cancel
- */
-
- static get properties() {
- return {
- message: String,
- commitMessage: String,
- };
- }
-
- _getTrimmedChangeSubject(subject) {
- if (!subject) return '';
- if (subject.length < CHANGE_SUBJECT_LIMIT) return subject;
- return subject.substring(0, CHANGE_SUBJECT_LIMIT) + '...';
- }
-
- _modifyRevertSubmissionMsg(change) {
- return this.$.jsAPI.modifyRevertSubmissionMsg(change,
- this.message, this.commitMessage);
- }
-
- _populateRevertSubmissionMessage(message, change, changes) {
- if (change === undefined) {
- return;
- }
- // Follow the same convention of the revert
- const commitHash = change.current_revision;
- if (!commitHash) {
- this.dispatchEvent(new CustomEvent('show-alert', {
- detail: {message: ERR_COMMIT_NOT_FOUND},
- composed: true, bubbles: true,
- }));
- return;
- }
- const submissionId = change.submission_id;
- const revertTitle = 'Revert submission ' + submissionId;
- this.changes = changes;
- this.message = revertTitle + '\n\n' +
- 'Reason for revert: <INSERT REASONING HERE>\n';
- changes = changes || [];
- if (changes.length) {
- this.message += 'Reverted Changes:\n';
- changes.forEach(change => {
- this.message += change.change_id.substring(0, 10) + ': ' +
- this._getTrimmedChangeSubject(change.subject) + '\n';
- });
- }
- this.message = this._modifyRevertSubmissionMsg(change);
- }
-
- _handleConfirmTap(e) {
- e.preventDefault();
- e.stopPropagation();
- this.dispatchEvent(new CustomEvent('confirm', {
- composed: true, bubbles: false,
- }));
- }
-
- _handleCancelTap(e) {
- e.preventDefault();
- e.stopPropagation();
- this.dispatchEvent(new CustomEvent('cancel', {
- composed: true, bubbles: false,
- }));
- }
-}
-
-customElements.define(GrConfirmRevertSubmissionDialog.is,
- GrConfirmRevertSubmissionDialog);
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
new file mode 100644
index 0000000..9754e89
--- /dev/null
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
@@ -0,0 +1,140 @@
+/**
+ * @license
+ * Copyright (C) 2019 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.
+ */
+import '../../shared/gr-dialog/gr-dialog';
+import '../../../styles/shared-styles';
+import '../../shared/gr-js-api-interface/gr-js-api-interface';
+import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners';
+import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin';
+import {PolymerElement} from '@polymer/polymer/polymer-element';
+import {htmlTemplate} from './gr-confirm-revert-submission-dialog_html';
+import {customElement, property} from '@polymer/decorators';
+import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
+import {ChangeInfo} from '../../../types/common';
+
+const ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
+const CHANGE_SUBJECT_LIMIT = 50;
+
+export interface GrConfirmRevertSubmissionDialog {
+ $: {
+ jsAPI: JsApiService & Element;
+ };
+}
+@customElement('gr-confirm-revert-submission-dialog')
+export class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
+ LegacyElementMixin(PolymerElement)
+) {
+ static get template() {
+ return htmlTemplate;
+ }
+
+ /**
+ * Fired when the confirm button is pressed.
+ *
+ * @event confirm
+ */
+
+ /**
+ * Fired when the cancel button is pressed.
+ *
+ * @event cancel
+ */
+
+ @property({type: String})
+ message?: string;
+
+ @property({type: String})
+ commitMessage?: string;
+
+ _getTrimmedChangeSubject(subject: string) {
+ if (!subject) return '';
+ if (subject.length < CHANGE_SUBJECT_LIMIT) return subject;
+ return subject.substring(0, CHANGE_SUBJECT_LIMIT) + '...';
+ }
+
+ _modifyRevertSubmissionMsg(change?: ChangeInfo) {
+ if (!change || !this.message || !this.commitMessage) {
+ return this.message;
+ }
+ return this.$.jsAPI.modifyRevertSubmissionMsg(
+ change,
+ this.message,
+ this.commitMessage
+ );
+ }
+
+ _populateRevertSubmissionMessage(
+ change?: ChangeInfo,
+ changes?: ChangeInfo[]
+ ) {
+ if (change === undefined) {
+ return;
+ }
+ // Follow the same convention of the revert
+ const commitHash = change.current_revision;
+ if (!commitHash) {
+ this.dispatchEvent(
+ new CustomEvent('show-alert', {
+ detail: {message: ERR_COMMIT_NOT_FOUND},
+ composed: true,
+ bubbles: true,
+ })
+ );
+ return;
+ }
+ const revertTitle = `Revert submission ${change.submission_id}`;
+ this.message =
+ revertTitle + '\n\n' + 'Reason for revert: <INSERT REASONING HERE>\n';
+ changes = changes || [];
+ if (changes.length) {
+ this.message += 'Reverted Changes:\n';
+ changes.forEach(change => {
+ this.message +=
+ `${change.change_id.substring(0, 10)}: ` +
+ `${this._getTrimmedChangeSubject(change.subject)}\n`;
+ });
+ }
+ this.message = this._modifyRevertSubmissionMsg(change);
+ }
+
+ _handleConfirmTap(e: Event) {
+ e.preventDefault();
+ e.stopPropagation();
+ this.dispatchEvent(
+ new CustomEvent('confirm', {
+ composed: true,
+ bubbles: false,
+ })
+ );
+ }
+
+ _handleCancelTap(e: Event) {
+ e.preventDefault();
+ e.stopPropagation();
+ this.dispatchEvent(
+ new CustomEvent('cancel', {
+ composed: true,
+ bubbles: false,
+ })
+ );
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ 'gr-confirm-revert-submission-dialog': GrConfirmRevertSubmissionDialog;
+ }
+}
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js
index e2f2e9e..1ed799f 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js
@@ -40,7 +40,6 @@
test('single line', () => {
assert.isNotOk(element.message);
element._populateRevertSubmissionMessage(
- 'one line commit\n\nChange-Id: abcdefg\n',
{current_revision: 'abcd123', submission_id: '111'});
const expected = 'Revert submission 111\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n';
@@ -50,7 +49,6 @@
test('multi line', () => {
assert.isNotOk(element.message);
element._populateRevertSubmissionMessage(
- 'many lines\ncommit\n\nmessage\n\nChange-Id: abcdefg\n',
{current_revision: 'abcd123', submission_id: '111'});
const expected = 'Revert submission 111\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n';
@@ -60,7 +58,6 @@
test('issue above change id', () => {
assert.isNotOk(element.message);
element._populateRevertSubmissionMessage(
- 'test \nvery\n\ncommit\n\nBug: Issue 42\nChange-Id: abcdefg\n',
{current_revision: 'abcd123', submission_id: '111'});
const expected = 'Revert submission 111\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n';
@@ -70,7 +67,6 @@
test('revert a revert', () => {
assert.isNotOk(element.message);
element._populateRevertSubmissionMessage(
- 'Revert "one line commit"\n\nChange-Id: abcdefg\n',
{current_revision: 'abcd123', submission_id: '111'});
const expected = 'Revert submission 111\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n';
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts
index 4b597a5..3d2d71b 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts
@@ -33,5 +33,10 @@
export interface JsApiService {
getElement(key: TargetElement): HTMLElement;
addEventCallback(eventName: EventType, callback: EventCallback): void;
+ modifyRevertSubmissionMsg(
+ change: ChangeInfo,
+ revertSubmissionMsg: string,
+ origMsg: string
+ ): string;
// TODO(TS): Add more methods when needed for the TS conversion.
}