Convert gr-confirm-revert-submission-dialog to typescript
The change converts the following files to typescript: * elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts Change-Id: I3132b807bde64eddfd78e51d903c3a4b98a5b1c1
This commit is contained in:
@@ -988,8 +988,7 @@ class GrChangeActions extends GestureEventListeners(
|
|||||||
this.$.restAPI.getChanges('', query)
|
this.$.restAPI.getChanges('', query)
|
||||||
.then(changes => {
|
.then(changes => {
|
||||||
this.$.confirmRevertSubmissionDialog.
|
this.$.confirmRevertSubmissionDialog.
|
||||||
_populateRevertSubmissionMessage(
|
_populateRevertSubmissionMessage(this.change, changes);
|
||||||
this.commitMessage, this.change, changes);
|
|
||||||
this._showActionDialog(this.$.confirmRevertSubmissionDialog);
|
this._showActionDialog(this.$.confirmRevertSubmissionDialog);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,26 +14,33 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import '../../shared/gr-dialog/gr-dialog.js';
|
import '../../shared/gr-dialog/gr-dialog';
|
||||||
import '../../../styles/shared-styles.js';
|
import '../../../styles/shared-styles';
|
||||||
import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
|
import '../../shared/gr-js-api-interface/gr-js-api-interface';
|
||||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners';
|
||||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
|
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin';
|
||||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
import {PolymerElement} from '@polymer/polymer/polymer-element';
|
||||||
import {htmlTemplate} from './gr-confirm-revert-submission-dialog_html.js';
|
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 =
|
const ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
|
||||||
'Unable to find the commit hash of this change.';
|
|
||||||
const CHANGE_SUBJECT_LIMIT = 50;
|
const CHANGE_SUBJECT_LIMIT = 50;
|
||||||
|
|
||||||
/**
|
export interface GrConfirmRevertSubmissionDialog {
|
||||||
* @extends PolymerElement
|
$: {
|
||||||
*/
|
jsAPI: JsApiService & Element;
|
||||||
class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
|
};
|
||||||
LegacyElementMixin(PolymerElement)) {
|
}
|
||||||
static get template() { return htmlTemplate; }
|
@customElement('gr-confirm-revert-submission-dialog')
|
||||||
|
export 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.
|
* Fired when the confirm button is pressed.
|
||||||
*
|
*
|
||||||
@@ -46,69 +53,88 @@ class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
|
|||||||
* @event cancel
|
* @event cancel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static get properties() {
|
@property({type: String})
|
||||||
return {
|
message?: string;
|
||||||
message: String,
|
|
||||||
commitMessage: String,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_getTrimmedChangeSubject(subject) {
|
@property({type: String})
|
||||||
|
commitMessage?: string;
|
||||||
|
|
||||||
|
_getTrimmedChangeSubject(subject: string) {
|
||||||
if (!subject) return '';
|
if (!subject) return '';
|
||||||
if (subject.length < CHANGE_SUBJECT_LIMIT) return subject;
|
if (subject.length < CHANGE_SUBJECT_LIMIT) return subject;
|
||||||
return subject.substring(0, CHANGE_SUBJECT_LIMIT) + '...';
|
return subject.substring(0, CHANGE_SUBJECT_LIMIT) + '...';
|
||||||
}
|
}
|
||||||
|
|
||||||
_modifyRevertSubmissionMsg(change) {
|
_modifyRevertSubmissionMsg(change?: ChangeInfo) {
|
||||||
return this.$.jsAPI.modifyRevertSubmissionMsg(change,
|
if (!change || !this.message || !this.commitMessage) {
|
||||||
this.message, this.commitMessage);
|
return this.message;
|
||||||
|
}
|
||||||
|
return this.$.jsAPI.modifyRevertSubmissionMsg(
|
||||||
|
change,
|
||||||
|
this.message,
|
||||||
|
this.commitMessage
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_populateRevertSubmissionMessage(message, change, changes) {
|
_populateRevertSubmissionMessage(
|
||||||
|
change?: ChangeInfo,
|
||||||
|
changes?: ChangeInfo[]
|
||||||
|
) {
|
||||||
if (change === undefined) {
|
if (change === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Follow the same convention of the revert
|
// Follow the same convention of the revert
|
||||||
const commitHash = change.current_revision;
|
const commitHash = change.current_revision;
|
||||||
if (!commitHash) {
|
if (!commitHash) {
|
||||||
this.dispatchEvent(new CustomEvent('show-alert', {
|
this.dispatchEvent(
|
||||||
detail: {message: ERR_COMMIT_NOT_FOUND},
|
new CustomEvent('show-alert', {
|
||||||
composed: true, bubbles: true,
|
detail: {message: ERR_COMMIT_NOT_FOUND},
|
||||||
}));
|
composed: true,
|
||||||
|
bubbles: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const submissionId = change.submission_id;
|
const revertTitle = `Revert submission ${change.submission_id}`;
|
||||||
const revertTitle = 'Revert submission ' + submissionId;
|
this.message =
|
||||||
this.changes = changes;
|
revertTitle + '\n\n' + 'Reason for revert: <INSERT REASONING HERE>\n';
|
||||||
this.message = revertTitle + '\n\n' +
|
|
||||||
'Reason for revert: <INSERT REASONING HERE>\n';
|
|
||||||
changes = changes || [];
|
changes = changes || [];
|
||||||
if (changes.length) {
|
if (changes.length) {
|
||||||
this.message += 'Reverted Changes:\n';
|
this.message += 'Reverted Changes:\n';
|
||||||
changes.forEach(change => {
|
changes.forEach(change => {
|
||||||
this.message += change.change_id.substring(0, 10) + ': ' +
|
this.message +=
|
||||||
this._getTrimmedChangeSubject(change.subject) + '\n';
|
`${change.change_id.substring(0, 10)}: ` +
|
||||||
|
`${this._getTrimmedChangeSubject(change.subject)}\n`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.message = this._modifyRevertSubmissionMsg(change);
|
this.message = this._modifyRevertSubmissionMsg(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e: Event) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.dispatchEvent(new CustomEvent('confirm', {
|
this.dispatchEvent(
|
||||||
composed: true, bubbles: false,
|
new CustomEvent('confirm', {
|
||||||
}));
|
composed: true,
|
||||||
|
bubbles: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e: Event) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.dispatchEvent(new CustomEvent('cancel', {
|
this.dispatchEvent(
|
||||||
composed: true, bubbles: false,
|
new CustomEvent('cancel', {
|
||||||
}));
|
composed: true,
|
||||||
|
bubbles: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define(GrConfirmRevertSubmissionDialog.is,
|
declare global {
|
||||||
GrConfirmRevertSubmissionDialog);
|
interface HTMLElementTagNameMap {
|
||||||
|
'gr-confirm-revert-submission-dialog': GrConfirmRevertSubmissionDialog;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ suite('gr-confirm-revert-submission-dialog tests', () => {
|
|||||||
test('single line', () => {
|
test('single line', () => {
|
||||||
assert.isNotOk(element.message);
|
assert.isNotOk(element.message);
|
||||||
element._populateRevertSubmissionMessage(
|
element._populateRevertSubmissionMessage(
|
||||||
'one line commit\n\nChange-Id: abcdefg\n',
|
|
||||||
{current_revision: 'abcd123', submission_id: '111'});
|
{current_revision: 'abcd123', submission_id: '111'});
|
||||||
const expected = 'Revert submission 111\n\n' +
|
const expected = 'Revert submission 111\n\n' +
|
||||||
'Reason for revert: <INSERT REASONING HERE>\n';
|
'Reason for revert: <INSERT REASONING HERE>\n';
|
||||||
@@ -50,7 +49,6 @@ suite('gr-confirm-revert-submission-dialog tests', () => {
|
|||||||
test('multi line', () => {
|
test('multi line', () => {
|
||||||
assert.isNotOk(element.message);
|
assert.isNotOk(element.message);
|
||||||
element._populateRevertSubmissionMessage(
|
element._populateRevertSubmissionMessage(
|
||||||
'many lines\ncommit\n\nmessage\n\nChange-Id: abcdefg\n',
|
|
||||||
{current_revision: 'abcd123', submission_id: '111'});
|
{current_revision: 'abcd123', submission_id: '111'});
|
||||||
const expected = 'Revert submission 111\n\n' +
|
const expected = 'Revert submission 111\n\n' +
|
||||||
'Reason for revert: <INSERT REASONING HERE>\n';
|
'Reason for revert: <INSERT REASONING HERE>\n';
|
||||||
@@ -60,7 +58,6 @@ suite('gr-confirm-revert-submission-dialog tests', () => {
|
|||||||
test('issue above change id', () => {
|
test('issue above change id', () => {
|
||||||
assert.isNotOk(element.message);
|
assert.isNotOk(element.message);
|
||||||
element._populateRevertSubmissionMessage(
|
element._populateRevertSubmissionMessage(
|
||||||
'test \nvery\n\ncommit\n\nBug: Issue 42\nChange-Id: abcdefg\n',
|
|
||||||
{current_revision: 'abcd123', submission_id: '111'});
|
{current_revision: 'abcd123', submission_id: '111'});
|
||||||
const expected = 'Revert submission 111\n\n' +
|
const expected = 'Revert submission 111\n\n' +
|
||||||
'Reason for revert: <INSERT REASONING HERE>\n';
|
'Reason for revert: <INSERT REASONING HERE>\n';
|
||||||
@@ -70,7 +67,6 @@ suite('gr-confirm-revert-submission-dialog tests', () => {
|
|||||||
test('revert a revert', () => {
|
test('revert a revert', () => {
|
||||||
assert.isNotOk(element.message);
|
assert.isNotOk(element.message);
|
||||||
element._populateRevertSubmissionMessage(
|
element._populateRevertSubmissionMessage(
|
||||||
'Revert "one line commit"\n\nChange-Id: abcdefg\n',
|
|
||||||
{current_revision: 'abcd123', submission_id: '111'});
|
{current_revision: 'abcd123', submission_id: '111'});
|
||||||
const expected = 'Revert submission 111\n\n' +
|
const expected = 'Revert submission 111\n\n' +
|
||||||
'Reason for revert: <INSERT REASONING HERE>\n';
|
'Reason for revert: <INSERT REASONING HERE>\n';
|
||||||
|
|||||||
@@ -33,5 +33,10 @@ export type EventCallback = (...args: any[]) => any;
|
|||||||
export interface JsApiService {
|
export interface JsApiService {
|
||||||
getElement(key: TargetElement): HTMLElement;
|
getElement(key: TargetElement): HTMLElement;
|
||||||
addEventCallback(eventName: EventType, callback: EventCallback): void;
|
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.
|
// TODO(TS): Add more methods when needed for the TS conversion.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user