Make it possible to add or remove change actions to overflow menu

``` js
Gerrit.install(function(plugin) {
  // Move cherry-pick button out of overflow menu.
  plugin.setActionOverflow('revision', 'cherrypick', false);
  // Move submit button out of overflow menu.
  plugin.setActionOverflow('revision', 'submit', true);
});
```

Revision and change actions are as returned by Gerrit's REST API.

Feature: Issue 5360
Change-Id: I151894b39929bd67ef0e00802c699831ab3f72fc
This commit is contained in:
Viktar Donich
2017-04-17 10:58:12 -07:00
parent 16444f4501
commit 44e2ccd2ab
7 changed files with 198 additions and 60 deletions

View File

@@ -23,6 +23,12 @@
* @event tap-item-<id>
*/
/**
* Fired when a non-link dropdown item is tapped.
*
* @event tap-item
*/
properties: {
items: Array,
topContent: Object,
@@ -93,7 +99,13 @@
_handleItemTap: function(e) {
var id = e.target.getAttribute('data-id');
var item = this.items.find(function(item) {
return item.id === id;
});
if (id && this.disabledIds.indexOf(id) === -1) {
if (item) {
this.dispatchEvent(new CustomEvent('tap-item', {detail: item}));
}
this.dispatchEvent(new CustomEvent('tap-item-' + id));
}
},

View File

@@ -74,13 +74,17 @@ limitations under the License.
});
test('non link items', function() {
element.items = [
{name: 'item one', id: 'foo'}, {name: 'item two', id: 'bar'}];
var stub = sinon.stub();
element.addEventListener('tap-item-foo', stub);
var item0 = {name: 'item one', id: 'foo'};
element.items = [item0, {name: 'item two', id: 'bar'}];
var fooTapped = sinon.stub();
var tapped = sinon.stub();
element.addEventListener('tap-item-foo', fooTapped);
element.addEventListener('tap-item', tapped);
flushAsynchronousOperations();
MockInteractions.tap(element.$$('.itemAction'));
assert.isTrue(stub.called);
assert.isTrue(fooTapped.called);
assert.isTrue(tapped.called);
assert.deepEqual(tapped.lastCall.args[0].detail, item0);
});
test('disabled non link item', function() {
@@ -88,10 +92,13 @@ limitations under the License.
element.disabledIds = ['foo'];
var stub = sinon.stub();
var tapped = sinon.stub();
element.addEventListener('tap-item-foo', stub);
element.addEventListener('tap-item', tapped);
flushAsynchronousOperations();
MockInteractions.tap(element.$$('.itemAction'));
assert.isFalse(stub.called);
assert.isFalse(tapped.called);
});
});
</script>