Add show-revision-actions event once revisionActions is available
After https://gerrit-review.googlesource.com/c/gerrit/+/238972, revisionActions is fetched separately and `showchange` is no longer waiting for that. this change will add a show-revision-actions event so plugin can hook to this one to add / modify / remove revision actions Bug: Issue 12051 Change-Id: I009f0b96b7f985bee1d53286c1dea427e41616fa
This commit is contained in:
parent
e7683ee296
commit
2943bec0b1
@ -494,6 +494,10 @@
|
||||
if (!revisionActions) { return; }
|
||||
|
||||
this.revisionActions = this._updateRebaseAction(revisionActions);
|
||||
this._sendShowRevisionActions({
|
||||
change: this.change,
|
||||
revisionActions,
|
||||
});
|
||||
this._handleLoadingComplete();
|
||||
})
|
||||
.catch(err => {
|
||||
@ -507,6 +511,13 @@
|
||||
Gerrit.awaitPluginsLoaded().then(() => this._loading = false);
|
||||
}
|
||||
|
||||
_sendShowRevisionActions(detail) {
|
||||
this.$.jsAPI.handleEvent(
|
||||
this.$.jsAPI.EventType.SHOW_REVISION_ACTIONS,
|
||||
detail
|
||||
);
|
||||
}
|
||||
|
||||
_updateRebaseAction(revisionActions) {
|
||||
if (revisionActions && revisionActions.rebase) {
|
||||
revisionActions.rebase.rebaseOnCurrent =
|
||||
|
@ -124,6 +124,15 @@ limitations under the License.
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('show-revision-actions event should fire', done => {
|
||||
const spy = sinon.spy(element, '_sendShowRevisionActions');
|
||||
element.reload();
|
||||
flush(() => {
|
||||
assert.isTrue(spy.called);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('primary and secondary actions split properly', () => {
|
||||
// Submit should be the only primary action.
|
||||
assert.equal(element._topLevelPrimaryActions.length, 1);
|
||||
|
@ -17,11 +17,13 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// Note: for new events, naming convention should be: `a-b`
|
||||
const EventType = {
|
||||
HISTORY: 'history',
|
||||
LABEL_CHANGE: 'labelchange',
|
||||
SHOW_CHANGE: 'showchange',
|
||||
SUBMIT_CHANGE: 'submitchange',
|
||||
SHOW_REVISION_ACTIONS: 'show-revision-actions',
|
||||
COMMIT_MSG_EDIT: 'commitmsgedit',
|
||||
COMMENT: 'comment',
|
||||
REVERT: 'revert',
|
||||
@ -82,6 +84,9 @@
|
||||
case EventType.LABEL_CHANGE:
|
||||
this._handleLabelChange(detail);
|
||||
break;
|
||||
case EventType.SHOW_REVISION_ACTIONS:
|
||||
this._handleShowRevisionActions(detail);
|
||||
break;
|
||||
case EventType.HIGHLIGHTJS_LOADED:
|
||||
this._handleHighlightjsLoaded(detail);
|
||||
break;
|
||||
@ -177,6 +182,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{change: !Object, revisionActions: !Object}} detail
|
||||
*/
|
||||
_handleShowRevisionActions(detail) {
|
||||
const registeredCallbacks = this._getEventCallbacks(
|
||||
EventType.SHOW_REVISION_ACTIONS
|
||||
);
|
||||
for (const cb of registeredCallbacks) {
|
||||
try {
|
||||
cb(detail.revisionActions, detail.change);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleCommitMessage(change, msg) {
|
||||
for (const cb of this._getEventCallbacks(EventType.COMMIT_MSG_EDIT)) {
|
||||
try {
|
||||
|
@ -215,6 +215,22 @@ limitations under the License.
|
||||
{change: testChange, patchNum: 1, info: {mergeable: false}});
|
||||
});
|
||||
|
||||
test('show-revision-actions event', done => {
|
||||
const testChange = {
|
||||
_number: 42,
|
||||
revisions: {def: {_number: 2}, abc: {_number: 1}},
|
||||
};
|
||||
plugin.on(element.EventType.SHOW_REVISION_ACTIONS, throwErrFn);
|
||||
plugin.on(element.EventType.SHOW_REVISION_ACTIONS, (actions, change) => {
|
||||
assert.deepEqual(change, testChange);
|
||||
assert.deepEqual(actions, {test: {}});
|
||||
assert.isTrue(errorStub.calledOnce);
|
||||
done();
|
||||
});
|
||||
element.handleEvent(element.EventType.SHOW_REVISION_ACTIONS,
|
||||
{change: testChange, revisionActions: {test: {}}});
|
||||
});
|
||||
|
||||
test('handleEvent awaits plugins load', done => {
|
||||
const testChange = {
|
||||
_number: 42,
|
||||
|
Loading…
Reference in New Issue
Block a user