Skip to content

Commit d9b908b

Browse files
feat: create ad-hoc sub process via replace menu
Related to camunda/camunda-modeler#4801
1 parent 61c2651 commit d9b908b

File tree

7 files changed

+427
-169
lines changed

7 files changed

+427
-169
lines changed

lib/features/popup-menu/ReplaceMenuProvider.js

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ ReplaceMenuProvider.prototype.getPopupMenuEntries = function(target) {
231231
return this._createEntries(target, filteredReplaceOptions);
232232
}
233233

234+
// expanded ad hoc sub processes
235+
if (is(businessObject, 'bpmn:AdHocSubProcess') && isExpanded(target)) {
236+
237+
filteredReplaceOptions = filter(replaceOptions.AD_HOC_SUBPROCESS_EXPANDED, differentType);
238+
239+
return this._createEntries(target, filteredReplaceOptions);
240+
}
241+
234242
// expanded sub processes
235243
if (is(businessObject, 'bpmn:SubProcess') && isExpanded(target)) {
236244

@@ -239,18 +247,16 @@ ReplaceMenuProvider.prototype.getPopupMenuEntries = function(target) {
239247
return this._createEntries(target, filteredReplaceOptions);
240248
}
241249

242-
// collapsed ad hoc sub processes
243-
if (is(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(target)) {
250+
// collapsed sub process or collapsed ad hoc sub process
251+
if (is(businessObject, 'bpmn:SubProcess') && !isExpanded(target)) {
244252

245253
filteredReplaceOptions = filter(replaceOptions.TASK, function(replaceOption) {
246254

247-
var target = replaceOption.target;
248-
249-
var isTargetSubProcess = target.type === 'bpmn:SubProcess';
255+
var isTargetSameType = replaceOption.target.type === target.type;
256+
var isTargetExpanded = replaceOption.target.isExpanded === true;
250257

251-
var isTargetExpanded = target.isExpanded === true;
252-
253-
return isDifferentType(target, target) && (!isTargetSubProcess || isTargetExpanded);
258+
// Collapsed subprocess cannot be replaced with itself or expanded subprocess of different type.
259+
return isTargetSameType === isTargetExpanded;
254260
});
255261

256262
return this._createEntries(target, filteredReplaceOptions);
@@ -265,13 +271,6 @@ ReplaceMenuProvider.prototype.getPopupMenuEntries = function(target) {
265271
if (is(businessObject, 'bpmn:FlowNode')) {
266272
filteredReplaceOptions = filter(replaceOptions.TASK, differentType);
267273

268-
// collapsed sub process cannot be replaced with itself
269-
if (is(businessObject, 'bpmn:SubProcess') && !isExpanded(target)) {
270-
filteredReplaceOptions = filter(filteredReplaceOptions, function(replaceOption) {
271-
return replaceOption.label !== 'Sub-process (collapsed)';
272-
});
273-
}
274-
275274
return this._createEntries(target, filteredReplaceOptions);
276275
}
277276

@@ -308,15 +307,6 @@ ReplaceMenuProvider.prototype.getPopupMenuHeaderEntries = function(target) {
308307
};
309308
}
310309

311-
if (is(target, 'bpmn:SubProcess') &&
312-
!is(target, 'bpmn:Transaction') &&
313-
!isEventSubProcess(target)) {
314-
headerEntries = {
315-
...headerEntries,
316-
...this._getAdHocHeaderEntries(target)
317-
};
318-
}
319-
320310
if (canBeNonInterrupting(target)) {
321311
headerEntries = {
322312
...headerEntries,
@@ -614,44 +604,6 @@ ReplaceMenuProvider.prototype._getParticipantMultiplicityHeaderEntries = functio
614604
};
615605
};
616606

617-
/**
618-
* Get popup menu header entries for the ad-hoc property of the given BPMN element.
619-
*
620-
* @param {PopupMenuTarget} element
621-
*
622-
* @return {PopupMenuHeaderEntries}
623-
*/
624-
ReplaceMenuProvider.prototype._getAdHocHeaderEntries = function(element) {
625-
var translate = this._translate;
626-
var businessObject = getBusinessObject(element);
627-
628-
var isAdHoc = is(businessObject, 'bpmn:AdHocSubProcess');
629-
630-
var replaceElement = this._bpmnReplace.replaceElement;
631-
632-
return {
633-
'toggle-adhoc': {
634-
className: 'bpmn-icon-ad-hoc-marker',
635-
title: translate('Ad-hoc'),
636-
active: isAdHoc,
637-
action: function(event, entry) {
638-
if (isAdHoc) {
639-
return replaceElement(element, { type: 'bpmn:SubProcess' }, {
640-
autoResize: false,
641-
layoutConnection: false
642-
});
643-
} else {
644-
return replaceElement(element, { type: 'bpmn:AdHocSubProcess' }, {
645-
autoResize: false,
646-
layoutConnection: false
647-
});
648-
}
649-
}
650-
}
651-
};
652-
};
653-
654-
655607
ReplaceMenuProvider.prototype._getNonInterruptingHeaderEntries = function(element) {
656608
const translate = this._translate;
657609
const businessObject = getBusinessObject(element);

lib/features/replace/BpmnReplace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default function BpmnReplace(
145145
var type = targetElement.type,
146146
oldBusinessObject = element.businessObject;
147147

148-
if (isSubProcess(oldBusinessObject) && type === 'bpmn:SubProcess') {
148+
if (isSubProcess(oldBusinessObject) && (type === 'bpmn:SubProcess' || type === 'bpmn:AdHocSubProcess')) {
149149
if (shouldToggleCollapsed(element, targetElement)) {
150150

151151
// expanding or collapsing process

lib/features/replace/ReplaceOptions.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,15 @@ export var SUBPROCESS_EXPANDED = [
427427
isExpanded: true
428428
}
429429
},
430+
{
431+
label: 'Ad-hoc sub-process',
432+
actionName: 'replace-with-ad-hoc-subprocess',
433+
className: 'bpmn-icon-subprocess-expanded',
434+
target: {
435+
type: 'bpmn:AdHocSubProcess',
436+
isExpanded: true
437+
}
438+
},
430439
{
431440
label: 'Sub-process (collapsed)',
432441
actionName: 'replace-with-collapsed-subprocess',
@@ -438,6 +447,49 @@ export var SUBPROCESS_EXPANDED = [
438447
}
439448
];
440449

450+
/**
451+
* @type {ReplaceOption[]}
452+
*/
453+
export var AD_HOC_SUBPROCESS_EXPANDED = [
454+
{
455+
label: 'Sub-process',
456+
actionName: 'replace-with-subprocess',
457+
className: 'bpmn-icon-subprocess-expanded',
458+
target: {
459+
type: 'bpmn:SubProcess',
460+
isExpanded: true
461+
}
462+
},
463+
{
464+
label: 'Transaction',
465+
actionName: 'replace-with-transaction',
466+
className: 'bpmn-icon-transaction',
467+
target: {
468+
type: 'bpmn:Transaction',
469+
isExpanded: true
470+
}
471+
},
472+
{
473+
label: 'Event sub-process',
474+
actionName: 'replace-with-event-subprocess',
475+
className: 'bpmn-icon-event-subprocess-expanded',
476+
target: {
477+
type: 'bpmn:SubProcess',
478+
triggeredByEvent: true,
479+
isExpanded: true
480+
}
481+
},
482+
{
483+
label: 'Ad-hoc sub-process (collapsed)',
484+
actionName: 'replace-with-collapsed-ad-hoc-subprocess',
485+
className: 'bpmn-icon-subprocess-collapsed',
486+
target: {
487+
type: 'bpmn:AdHocSubProcess',
488+
isExpanded: false
489+
}
490+
}
491+
];
492+
441493
/**
442494
* @type {ReplaceOption[]}
443495
*/
@@ -460,6 +512,15 @@ export var TRANSACTION = [
460512
isExpanded: true
461513
}
462514
},
515+
{
516+
label: 'Ad-hoc sub-process',
517+
actionName: 'replace-with-ad-hoc-subprocess',
518+
className: 'bpmn-icon-subprocess-expanded',
519+
target: {
520+
type: 'bpmn:AdHocSubProcess',
521+
isExpanded: true
522+
}
523+
},
463524
{
464525
label: 'Event sub-process',
465526
actionName: 'replace-with-event-subprocess',
@@ -570,6 +631,24 @@ export var TASK = [
570631
type: 'bpmn:SubProcess',
571632
isExpanded: true
572633
}
634+
},
635+
{
636+
label: 'Ad-hoc sub-process (collapsed)',
637+
actionName: 'replace-with-collapsed-ad-hoc-subprocess',
638+
className: 'bpmn-icon-subprocess-collapsed',
639+
target: {
640+
type: 'bpmn:AdHocSubProcess',
641+
isExpanded: false
642+
}
643+
},
644+
{
645+
label: 'Ad-hoc sub-process (expanded)',
646+
actionName: 'replace-with-ad-hoc-subprocess',
647+
className: 'bpmn-icon-subprocess-expanded',
648+
target: {
649+
type: 'bpmn:AdHocSubProcess',
650+
isExpanded: true
651+
}
573652
}
574653
];
575654

test/spec/features/modeling/behavior/ToggleElementCollapseBehaviour.bpmn

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
<bpmn2:startEvent id="StartEvent_4">
4444
<bpmn2:outgoing>SequenceFlow_9</bpmn2:outgoing>
4545
</bpmn2:startEvent>
46-
<bpmn2:sequenceFlow id="SequenceFlow_9" sourceRef="StartEvent_4" targetRef="SubProcess_2" />
46+
<bpmn2:sequenceFlow id="SequenceFlow_9" sourceRef="StartEvent_4" targetRef="AdHocSubProcess_1" />
4747
<bpmn2:endEvent id="EndEvent_5">
4848
<bpmn2:incoming>SequenceFlow_8</bpmn2:incoming>
4949
</bpmn2:endEvent>
50-
<bpmn2:sequenceFlow id="SequenceFlow_8" sourceRef="SubProcess_2" targetRef="EndEvent_5" />
50+
<bpmn2:sequenceFlow id="SequenceFlow_8" sourceRef="AdHocSubProcess_1" targetRef="EndEvent_5" />
5151
<bpmn2:subProcess id="SubProcess_3" />
5252
<bpmn2:adHocSubProcess id="SubProcess_4">
5353
<bpmn2:multiInstanceLoopCharacteristics />
5454
<bpmn2:startEvent id="StartEvent_5" />
5555
</bpmn2:adHocSubProcess>
56-
<bpmn2:adHocSubProcess id="SubProcess_2">
56+
<bpmn2:adHocSubProcess id="AdHocSubProcess_1">
5757
<bpmn2:incoming>SequenceFlow_9</bpmn2:incoming>
5858
<bpmn2:outgoing>SequenceFlow_8</bpmn2:outgoing>
5959
<bpmn2:multiInstanceLoopCharacteristics />
@@ -143,7 +143,7 @@
143143
<bpmndi:BPMNShape id="AdHocSubProcess_0ojckgh_di" bpmnElement="SubProcess_4" isExpanded="false">
144144
<dc:Bounds x="541" y="652" width="100" height="80" />
145145
</bpmndi:BPMNShape>
146-
<bpmndi:BPMNShape id="AdHocSubProcess_128w1vu_di" bpmnElement="SubProcess_2" isExpanded="true">
146+
<bpmndi:BPMNShape id="AdHocSubProcess_128w1vu_di" bpmnElement="AdHocSubProcess_1" isExpanded="true">
147147
<dc:Bounds x="407" y="335" width="385" height="200" />
148148
</bpmndi:BPMNShape>
149149
<bpmndi:BPMNEdge id="SequenceFlow_1s8bqj4_di" bpmnElement="SequenceFlow_11">

test/spec/features/modeling/behavior/ToggleElementCollapseBehaviourSpec.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('features/modeling - collapse and expand elements', function() {
8989
// when
9090
var expandedAdHocSubProcess = bpmnReplace.replaceElement(collapsedAdHocSubProcess,
9191
{
92-
type: 'bpmn:SubProcess',
92+
type: 'bpmn:AdHocSubProcess',
9393
isExpanded: true
9494
}
9595
);
@@ -322,12 +322,12 @@ describe('features/modeling - collapse and expand elements', function() {
322322
inject(function(elementRegistry, bpmnReplace) {
323323

324324
// given
325-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
325+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
326326

327327
// when
328328
var collapsedSubProcess = bpmnReplace.replaceElement(expandedSubProcess,
329329
{
330-
type: 'bpmn:SubProcess',
330+
type: 'bpmn:AdHocSubProcess',
331331
isExpanded: false
332332
}
333333
);
@@ -342,12 +342,12 @@ describe('features/modeling - collapse and expand elements', function() {
342342
inject(function(elementRegistry, bpmnReplace) {
343343

344344
// given
345-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
345+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
346346

347347
// when
348348
var collapsedSubProcess = bpmnReplace.replaceElement(expandedSubProcess,
349349
{
350-
type: 'bpmn:SubProcess',
350+
type: 'bpmn:AdHocSubProcess',
351351
isExpanded: false
352352
}
353353
);
@@ -364,7 +364,7 @@ describe('features/modeling - collapse and expand elements', function() {
364364
inject(function(elementRegistry, bpmnReplace) {
365365

366366
// given
367-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
367+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
368368
var originalChildren = expandedSubProcess.children.slice();
369369

370370
// when
@@ -376,7 +376,7 @@ describe('features/modeling - collapse and expand elements', function() {
376376
);
377377

378378
// then
379-
var plane = elementRegistry.get('SubProcess_2_plane');
379+
var plane = elementRegistry.get('AdHocSubProcess_1_plane');
380380
originalChildren.forEach(function(c) {
381381
expect(plane.children).to.include(c);
382382
});
@@ -390,7 +390,7 @@ describe('features/modeling - collapse and expand elements', function() {
390390
inject(function(elementRegistry, bpmnReplace) {
391391

392392
// given
393-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
393+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
394394
var oldMid = {
395395
x: expandedSubProcess.x + expandedSubProcess.width / 2,
396396
y: expandedSubProcess.y + expandedSubProcess.height / 2
@@ -399,7 +399,7 @@ describe('features/modeling - collapse and expand elements', function() {
399399
// when
400400
var collapsedSubProcess = bpmnReplace.replaceElement(expandedSubProcess,
401401
{
402-
type: 'bpmn:SubProcess',
402+
type: 'bpmn:AdHocSubProcess',
403403
isExpanded: false
404404
}
405405
);
@@ -426,10 +426,10 @@ describe('features/modeling - collapse and expand elements', function() {
426426
inject(function(elementRegistry, bpmnReplace, commandStack) {
427427

428428
// given
429-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
429+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
430430
var collapsedSubProcess = bpmnReplace.replaceElement(expandedSubProcess,
431431
{
432-
type: 'bpmn:SubProcess',
432+
type: 'bpmn:AdHocSubProcess',
433433
isExpanded: false
434434
}
435435
);
@@ -447,7 +447,7 @@ describe('features/modeling - collapse and expand elements', function() {
447447
inject(function(elementRegistry, bpmnReplace, commandStack) {
448448

449449
// given
450-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
450+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
451451
var originalBounds = {
452452
x: expandedSubProcess.x,
453453
y: expandedSubProcess.y,
@@ -457,7 +457,7 @@ describe('features/modeling - collapse and expand elements', function() {
457457

458458
bpmnReplace.replaceElement(expandedSubProcess,
459459
{
460-
type: 'bpmn:SubProcess',
460+
type: 'bpmn:AdHocSubProcess',
461461
isExpanded: false
462462
}
463463
);
@@ -475,12 +475,12 @@ describe('features/modeling - collapse and expand elements', function() {
475475
inject(function(elementRegistry, bpmnReplace, commandStack) {
476476

477477
// given
478-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
478+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
479479
var originalChildren = expandedSubProcess.children.slice();
480480

481481
bpmnReplace.replaceElement(expandedSubProcess,
482482
{
483-
type: 'bpmn:SubProcess',
483+
type: 'bpmn:AdHocSubProcess',
484484
isExpanded: false
485485
}
486486
);
@@ -589,7 +589,7 @@ describe('features/modeling - collapse and expand elements', function() {
589589
inject(function(eventBus, bpmnReplace, elementRegistry) {
590590

591591
// given
592-
var expandedSubProcess = elementRegistry.get('SubProcess_2');
592+
var expandedSubProcess = elementRegistry.get('AdHocSubProcess_1');
593593

594594
// should not be called
595595
eventBus.once('commandStack.shape.toggleCollapse.execute', function(e) {

0 commit comments

Comments
 (0)