PolyGerrit: Adds delete and publish change edits to actions
Rebasing a change edit will be added in a follow up change. Bug: Issue 4437 Bug: Issue 7213 Change-Id: I3e1f3566a1c44937350b1f92eca560bb8e2e2340
This commit is contained in:
@@ -157,6 +157,19 @@ limitations under the License.
|
||||
Do you really want to delete the change?
|
||||
</div>
|
||||
</gr-confirm-dialog>
|
||||
<gr-confirm-dialog
|
||||
id="confirmDeleteEditDialog"
|
||||
class="confirmDialog"
|
||||
confirm-label="Delete"
|
||||
on-cancel="_handleConfirmDialogCancel"
|
||||
on-confirm="_handleDeleteEditConfirm">
|
||||
<div class="header">
|
||||
Delete Change Edit
|
||||
</div>
|
||||
<div class="main">
|
||||
Do you really want to delete the edit?
|
||||
</div>
|
||||
</gr-confirm-dialog>
|
||||
</gr-overlay>
|
||||
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
|
||||
@@ -51,11 +51,13 @@
|
||||
const ChangeActions = {
|
||||
ABANDON: 'abandon',
|
||||
DELETE: '/',
|
||||
DELETE_EDIT: 'deleteEdit',
|
||||
IGNORE: 'ignore',
|
||||
MOVE: 'move',
|
||||
MUTE: 'mute',
|
||||
PRIVATE: 'private',
|
||||
PRIVATE_DELETE: 'private.delete',
|
||||
PUBLISH_EDIT: 'publishEdit',
|
||||
RESTORE: 'restore',
|
||||
REVERT: 'revert',
|
||||
UNIGNORE: 'unignore',
|
||||
@@ -118,6 +120,26 @@
|
||||
__type: 'revision',
|
||||
};
|
||||
|
||||
const PUBLISH_EDIT = {
|
||||
enabled: true,
|
||||
label: 'Publish Edit',
|
||||
title: 'Publish change edit',
|
||||
__key: 'publishEdit',
|
||||
__primary: false,
|
||||
__type: 'change',
|
||||
method: 'POST',
|
||||
};
|
||||
|
||||
const DELETE_EDIT = {
|
||||
enabled: true,
|
||||
label: 'Delete Edit',
|
||||
title: 'Delete change edit',
|
||||
__key: 'deleteEdit',
|
||||
__primary: false,
|
||||
__type: 'change',
|
||||
method: 'DELETE',
|
||||
};
|
||||
|
||||
const AWAIT_CHANGE_ATTEMPTS = 5;
|
||||
const AWAIT_CHANGE_TIMEOUT_MS = 1000;
|
||||
|
||||
@@ -276,6 +298,10 @@
|
||||
type: Array,
|
||||
value() { return []; },
|
||||
},
|
||||
editLoaded: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
|
||||
ActionType,
|
||||
@@ -288,7 +314,8 @@
|
||||
],
|
||||
|
||||
observers: [
|
||||
'_actionsChanged(actions.*, revisionActions.*, _additionalActions.*)',
|
||||
'_actionsChanged(actions.*, revisionActions.*, _additionalActions.*, ' +
|
||||
'editLoaded, change)',
|
||||
],
|
||||
|
||||
listeners: {
|
||||
@@ -422,7 +449,7 @@
|
||||
},
|
||||
|
||||
_actionsChanged(actionsChangeRecord, revisionActionsChangeRecord,
|
||||
additionalActionsChangeRecord) {
|
||||
additionalActionsChangeRecord, editLoaded, change) {
|
||||
const additionalActions = (additionalActionsChangeRecord &&
|
||||
additionalActionsChangeRecord.base) || [];
|
||||
this.hidden = this._keyCount(actionsChangeRecord) === 0 &&
|
||||
@@ -436,6 +463,29 @@
|
||||
!revisionActions.download) {
|
||||
this.set('revisionActions.download', DOWNLOAD_ACTION);
|
||||
}
|
||||
|
||||
const changeActions = actionsChangeRecord.base || {};
|
||||
if (Object.keys(changeActions).length !== 0) {
|
||||
if (editLoaded) {
|
||||
if (this.changeIsOpen(change.status)) {
|
||||
if (!changeActions.publishEdit) {
|
||||
this.set('actions.publishEdit', PUBLISH_EDIT);
|
||||
}
|
||||
}
|
||||
if (!changeActions.deleteEdit) {
|
||||
this.set('actions.deleteEdit', DELETE_EDIT);
|
||||
}
|
||||
} else {
|
||||
if (changeActions.publishEdit) {
|
||||
delete this.actions.publishEdit;
|
||||
this.notifyPath('actions.publishEdit');
|
||||
}
|
||||
if (changeActions.deleteEdit) {
|
||||
delete this.actions.deleteEdit;
|
||||
this.notifyPath('actions.deleteEdit');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_getValuesFor(obj) {
|
||||
@@ -638,12 +688,18 @@
|
||||
case ChangeActions.DELETE:
|
||||
this._handleDeleteTap();
|
||||
break;
|
||||
case ChangeActions.DELETE_EDIT:
|
||||
this._handleDeleteEditTap();
|
||||
break;
|
||||
case ChangeActions.WIP:
|
||||
this._handleWipTap();
|
||||
break;
|
||||
case ChangeActions.MOVE:
|
||||
this._handleMoveTap();
|
||||
break;
|
||||
case ChangeActions.PUBLISH_EDIT:
|
||||
this._handlePublishEditTap();
|
||||
break;
|
||||
default:
|
||||
this._fireAction(this._prependSlash(key), this.actions[key], false);
|
||||
}
|
||||
@@ -775,6 +831,12 @@
|
||||
this._fireAction('/', this.actions[ChangeActions.DELETE], false);
|
||||
},
|
||||
|
||||
_handleDeleteEditConfirm() {
|
||||
this._hideAllDialogs();
|
||||
|
||||
this._fireAction('/edit', this.actions.deleteEdit, false);
|
||||
},
|
||||
|
||||
_getActionOverflowIndex(type, key) {
|
||||
return this._overflowActions.findIndex(action => {
|
||||
return action.type === type && action.key === key;
|
||||
@@ -862,6 +924,8 @@
|
||||
}
|
||||
break;
|
||||
case ChangeActions.WIP:
|
||||
case ChangeActions.DELETE_EDIT:
|
||||
case ChangeActions.PUBLISH_EDIT:
|
||||
page.show(this.changePath(this.changeNum));
|
||||
break;
|
||||
default:
|
||||
@@ -949,10 +1013,18 @@
|
||||
this._showActionDialog(this.$.confirmDeleteDialog);
|
||||
},
|
||||
|
||||
_handleDeleteEditTap() {
|
||||
this._showActionDialog(this.$.confirmDeleteEditDialog);
|
||||
},
|
||||
|
||||
_handleWipTap() {
|
||||
this._fireAction('/wip', this.actions.wip, false);
|
||||
},
|
||||
|
||||
_handlePublishEditTap() {
|
||||
this._fireAction('/edit:publish', this.actions.publishEdit, false);
|
||||
},
|
||||
|
||||
_handleHideBackgroundContent() {
|
||||
this.$.mainContent.classList.add('overlayOpen');
|
||||
},
|
||||
|
||||
@@ -360,6 +360,99 @@ limitations under the License.
|
||||
assert.isFalse(element.$.mainContent.classList.contains('overlayOpen'));
|
||||
});
|
||||
|
||||
suite('change edits', () => {
|
||||
let fireActionStub;
|
||||
const deleteEditAction = {
|
||||
enabled: true,
|
||||
label: 'Delete Edit',
|
||||
title: 'Delete change edit',
|
||||
__key: 'deleteEdit',
|
||||
__primary: false,
|
||||
__type: 'change',
|
||||
method: 'DELETE',
|
||||
};
|
||||
const publishEditAction = {
|
||||
enabled: true,
|
||||
label: 'Publish Edit',
|
||||
title: 'Publish change edit',
|
||||
__key: 'publishEdit',
|
||||
__primary: false,
|
||||
__type: 'change',
|
||||
method: 'POST',
|
||||
};
|
||||
|
||||
setup(() => {
|
||||
fireActionStub = sandbox.stub(element, '_fireAction');
|
||||
element.patchNum = 'edit';
|
||||
element.editLoaded = true;
|
||||
});
|
||||
|
||||
test('does not delete edit on action', () => {
|
||||
element._handleDeleteEditTap();
|
||||
assert.isFalse(fireActionStub.called);
|
||||
});
|
||||
|
||||
test('shows confirm dialog for delete edit', () => {
|
||||
element._handleDeleteEditTap();
|
||||
assert.isFalse(element.$$('#confirmDeleteEditDialog').hidden);
|
||||
assert.ok(element.$$('gr-button[data-action-key="deleteEdit"]'));
|
||||
MockInteractions.tap(
|
||||
element.$$('#confirmDeleteEditDialog').$$('gr-button[primary]'));
|
||||
flushAsynchronousOperations();
|
||||
assert.isTrue(
|
||||
fireActionStub.calledWith('/edit', deleteEditAction, false));
|
||||
});
|
||||
|
||||
test('show publish edit', () => {
|
||||
element.change = {
|
||||
status: 'NEW',
|
||||
};
|
||||
const publishEditButton =
|
||||
element.$$('gr-button[data-action-key="publishEdit"]');
|
||||
assert.ok(publishEditButton);
|
||||
MockInteractions.tap(publishEditButton);
|
||||
element._handlePublishEditTap();
|
||||
flushAsynchronousOperations();
|
||||
|
||||
assert.isTrue(
|
||||
fireActionStub.calledWith('/edit:publish', publishEditAction, false));
|
||||
});
|
||||
|
||||
test('hide publishEdit if change is not open', () => {
|
||||
element.change = {
|
||||
status: 'MERGED',
|
||||
};
|
||||
flushAsynchronousOperations();
|
||||
|
||||
const publishEditButton =
|
||||
element.$$('gr-button[data-action-key="publishEdit"]');
|
||||
assert.isNotOk(publishEditButton);
|
||||
|
||||
const deleteEditButton =
|
||||
element.$$('gr-button[data-action-key="deleteEdit"]');
|
||||
assert.ok(deleteEditButton);
|
||||
});
|
||||
|
||||
test('do not show delete edit on a non change edit', () => {
|
||||
element.editLoaded = false;
|
||||
flushAsynchronousOperations();
|
||||
const deleteEditButton =
|
||||
element.$$('gr-button[data-action-key="deleteEdit"]');
|
||||
assert.isNotOk(deleteEditButton);
|
||||
});
|
||||
|
||||
test('do not show publish edit on a non change edit', () => {
|
||||
element.change = {
|
||||
status: 'NEW',
|
||||
};
|
||||
element.editLoaded = false;
|
||||
flushAsynchronousOperations();
|
||||
const publishEditButton =
|
||||
element.$$('gr-button[data-action-key="publishEdit"]');
|
||||
assert.isNotOk(publishEditButton);
|
||||
});
|
||||
});
|
||||
|
||||
suite('cherry-pick', () => {
|
||||
let fireActionStub;
|
||||
|
||||
|
||||
@@ -351,6 +351,7 @@ limitations under the License.
|
||||
commit-num="[[_commitInfo.commit]]"
|
||||
patch-num="[[computeLatestPatchNum(_allPatchSets)]]"
|
||||
commit-message="[[_latestCommitMessage]]"
|
||||
edit-loaded="[[_editLoaded]]"
|
||||
on-reload-change="_handleReloadChange"
|
||||
on-download-tap="_handleOpenDownloadDialog"></gr-change-actions>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user