Skip to content

Commit 16a52f9

Browse files
Buckwichbarmac
authored andcommitted
feat: add delete action for multi element context
Related to camunda/camunda-modeler#4554
1 parent 0a82a60 commit 16a52f9

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

packages/dmn-js-drd/src/features/context-pad/ContextPadProvider.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
assign,
3+
every,
34
isArray
45
} from 'min-dash';
56

@@ -297,3 +298,43 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
297298

298299
return actions;
299300
};
301+
302+
ContextPadProvider.prototype.getMultiElementContextPadEntries = function(
303+
elements
304+
) {
305+
var modeling = this._modeling,
306+
translate = this._translate;
307+
308+
var actions = {};
309+
310+
if (this._isDeleteAllowed(elements)) {
311+
assign(actions, {
312+
'delete': {
313+
group: 'edit',
314+
className: 'dmn-icon-trash',
315+
title: translate('Delete'),
316+
action: {
317+
click: (e, elements) => modeling.removeElements(elements.slice())
318+
},
319+
},
320+
});
321+
}
322+
323+
return actions;
324+
};
325+
326+
ContextPadProvider.prototype._isDeleteAllowed = function(elements) {
327+
328+
// rules allowed can return boolean or array of elements (not reflected in type )
329+
var allowedOrAllowedElements = this._rules.allowed('elements.delete', {
330+
elements: elements
331+
});
332+
333+
if (isArray(allowedOrAllowedElements)) {
334+
return every(elements, el => allowedOrAllowedElements.includes(el));
335+
}
336+
337+
return allowedOrAllowedElements;
338+
};
339+
340+

packages/dmn-js-drd/test/spec/features/context-pad/ContextPadProviderSpec.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,64 @@ describe('features - context-pad', function() {
166166
})
167167
);
168168

169+
170+
describe('multi remove', function() {
171+
172+
it('should add delete action by default', inject(
173+
function(elementRegistry, contextPad) {
174+
175+
// given
176+
var shape1 = elementRegistry.get('dayType_id'),
177+
shape2 = elementRegistry.get('temperature_id');
178+
179+
// when
180+
contextPad.open([ shape1, shape2 ]);
181+
182+
// then
183+
expect(deleteAction([ shape1, shape2 ])).to.exist;
184+
}
185+
));
186+
187+
188+
it('should NOT add delete action when rule returns false', inject(
189+
function(elementRegistry, contextPad, customRules) {
190+
191+
// given
192+
customRules.addRule('elements.delete', 1500, function() {
193+
return false;
194+
});
195+
196+
var shape1 = elementRegistry.get('dayType_id'),
197+
shape2 = elementRegistry.get('temperature_id');
198+
199+
// when
200+
contextPad.open([ shape1, shape2 ]);
201+
202+
// then
203+
expect(deleteAction([ shape1, shape2 ])).not.to.exist;
204+
}
205+
));
206+
207+
208+
it('should trigger batch delete', inject(
209+
function(elementRegistry, contextPad, customRules) {
210+
211+
// given
212+
var shape1 = elementRegistry.get('dayType_id'),
213+
shape2 = elementRegistry.get('temperature_id');
214+
215+
contextPad.open([ shape1, shape2 ]);
216+
217+
// when
218+
contextPad.trigger('click', padEvent('delete'));
219+
220+
// then
221+
expect(elementRegistry.get('dayType_id')).not.to.exist;
222+
expect(elementRegistry.get('temperature_id')).not.to.exist;
223+
}
224+
));
225+
226+
});
169227
});
170228

171229

0 commit comments

Comments
 (0)