Skip to content

Commit

Permalink
feat: add multi-element delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and nikku committed Nov 5, 2021
1 parent b511d61 commit 2a9d061
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions lib/features/context-pad/ContextPadProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
assign,
forEach,
isArray
isArray,
every
} from 'min-dash';

import {
Expand Down Expand Up @@ -86,9 +87,49 @@ ContextPadProvider.$inject = [
'translate'
];

ContextPadProvider.prototype.getMultiElementContextPadEntries = function(elements) {
var modeling = this._modeling;

ContextPadProvider.prototype.getContextPadEntries = function(element) {
var actions = {};

if (this._isDeleteAllowed(elements)) {
assign(actions, {
'delete': {
group: 'edit',
className: 'bpmn-icon-trash',
title: this._translate('Remove'),
action: {
click: function(event, elements) {
modeling.removeElements(elements.slice());
}
}
}
});
}

return actions;
};

/**
* @param {djs.model.Base[]} elements
* @return {boolean}
*/
ContextPadProvider.prototype._isDeleteAllowed = function(elements) {

var baseAllowed = this._rules.allowed('elements.delete', {
elements: elements
});

if (isArray(baseAllowed)) {
return every(baseAllowed, function(element) {
return includes(baseAllowed, element);
});
}

return baseAllowed;
};

ContextPadProvider.prototype.getContextPadEntries = function(element) {
var contextPad = this._contextPad,
modeling = this._modeling,

Expand All @@ -113,7 +154,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
connect.start(event, element);
}

function removeElement(e) {
function removeElement(e, element) {
modeling.removeElements([ element ]);
}

Expand Down Expand Up @@ -470,3 +511,7 @@ function isEventType(eventBo, type, definition) {

return isType && isDefinition;
}

function includes(array, item) {
return array.indexOf(item) !== -1;
}

0 comments on commit 2a9d061

Please sign in to comment.