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 53adf3c626..501636c212 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 @@ -640,6 +640,9 @@ // Plugin actions always contain ~ in the key. if (a.indexOf('~') !== -1) { pluginActions.push(actions[a]); + const patchNum = type === ActionType.REVISION ? this.patchNum : null; + this.$.restAPI.getChangeActionURL(this.changeNum, patchNum, '/' + a) + .then(url => actions[a].__url = url); // Add server-side provided plugin actions to overflow menu. this._overflowActions.push({ type, 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 6fea56bfd3..a3932c2283 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 @@ -114,11 +114,32 @@ limitations under the License. assert.isFalse(element._shouldHideActions({base: ['test']}, false)); }); - test('plugin actions', () => { + test('plugin revision actions', () => { + sandbox.stub(element.$.restAPI, 'getChangeActionURL').returns( + Promise.resolve('the-url')); element.revisionActions = { 'plugin~action': {}, }; assert.isOk(element.revisionActions['plugin~action']); + flush(() => { + assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith( + element.changeNum, element.patchNum, '/plugin~action')); + assert.equal(element.revisionActions['plugin~action'].__url, 'the-url'); + }); + }); + + test('plugin change actions', () => { + sandbox.stub(element.$.restAPI, 'getChangeActionURL').returns( + Promise.resolve('the-url')); + element.actions = { + 'plugin~action': {}, + }; + assert.isOk(element.actions['plugin~action']); + flush(() => { + assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith( + element.changeNum, null, '/plugin~action')); + assert.equal(element.revisionActions['plugin~action'].__url, 'the-url'); + }); }); test('not supported actions are filtered out', () => { diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js index d6a7a6722b..f0c42f0e53 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js @@ -79,9 +79,18 @@ return this.div(checkbox, this.msg(title)); }; + GrPluginActionContext.prototype.prependLabel = function(title, checkbox) { + return this.label(checkbox, title); + }; + GrPluginActionContext.prototype.call = function(payload, onSuccess) { - this.plugin._send( - this.action.method, '/' + this.action.__key, onSuccess, payload); + if (!this.action.__url) { + console.warn(`Unable to ${this.action.method} to ${this.action.__key}!`); + return; + } + this.plugin.restApi() + .send(this.action.method, this.action.__url, payload) + .then(onSuccess); }; window.GrPluginActionContext = GrPluginActionContext; diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html index 0099d80218..072a781e9e 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html @@ -115,13 +115,17 @@ limitations under the License. instance.action = { method: 'METHOD', __key: 'key', + __url: '/changes/1/revisions/2/foo~bar', }; - sandbox.stub(plugin, '_send'); + const sendStub = sandbox.stub().returns(Promise.resolve()); + sandbox.stub(plugin, 'restApi').returns({ + send: sendStub, + }); const payload = {foo: 'foo'}; const successStub = sandbox.stub(); instance.call(payload, successStub); - assert.isTrue( - plugin._send.calledWith('METHOD', '/key', successStub, payload)); + assert.isTrue(sendStub.calledWith( + 'METHOD', '/changes/1/revisions/2/foo~bar', payload)); }); });