Skip to content

Commit 78af19c

Browse files
committed
fix: set loop characteristics in a command
Closes #1960 Release-As: 14.0.1
1 parent 71e1f47 commit 78af19c

File tree

3 files changed

+91
-16
lines changed

3 files changed

+91
-16
lines changed

lib/features/popup-menu/ReplaceMenuProvider.js

+24-15
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ import {
1515
import {
1616
forEach,
1717
filter,
18-
isArray,
19-
isUndefined
18+
isArray
2019
} from 'min-dash';
2120

2221
import * as replaceOptions from '../replace/ReplaceOptions';
2322

2423
/**
25-
* @typedef {import('../features/BpmnFactory').default} BpmnFactory
24+
* @typedef {import('../modeling/BpmnFactory').default} BpmnFactory
2625
* @typedef {import('diagram-js/lib/features/popup-menu/PopupMenu').default} PopupMenu
27-
* @typedef {import('../features/Modeling').default} Modeling
28-
* @typedef {import('../features/BpmnReplace').default} BpmnReplace
26+
* @typedef {import('../modeling/Modeling').default} Modeling
27+
* @typedef {import('../replace/BpmnReplace').default} BpmnReplace
2928
* @typedef {import('diagram-js/lib/features/Rules').default} Rules
3029
* @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
30+
* @typedef {import('../copy-paste/ModdleCopy').default} ModdleCopy
3131
*
3232
* @typedef {import('../../model/Types').Element} Element
3333
* @typedef {import('../../model/Types').Moddle} Moddle
@@ -54,10 +54,11 @@ import * as replaceOptions from '../replace/ReplaceOptions';
5454
* @param {BpmnReplace} bpmnReplace
5555
* @param {Rules} rules
5656
* @param {Translate} translate
57+
* @param {ModdleCopy} moddleCopy
5758
*/
5859
export default function ReplaceMenuProvider(
5960
bpmnFactory, popupMenu, modeling, moddle,
60-
bpmnReplace, rules, translate) {
61+
bpmnReplace, rules, translate, moddleCopy) {
6162

6263
this._bpmnFactory = bpmnFactory;
6364
this._popupMenu = popupMenu;
@@ -66,6 +67,7 @@ export default function ReplaceMenuProvider(
6667
this._bpmnReplace = bpmnReplace;
6768
this._rules = rules;
6869
this._translate = translate;
70+
this._moddleCopy = moddleCopy;
6971

7072
this._register();
7173
}
@@ -77,7 +79,8 @@ ReplaceMenuProvider.$inject = [
7779
'moddle',
7880
'bpmnReplace',
7981
'rules',
80-
'translate'
82+
'translate',
83+
'moddleCopy'
8184
];
8285

8386
ReplaceMenuProvider.prototype._register = function() {
@@ -461,18 +464,24 @@ ReplaceMenuProvider.prototype._getLoopCharacteristicsHeaderEntries = function(ta
461464
var translate = this._translate;
462465

463466
function toggleLoopEntry(event, entry) {
464-
var newLoopCharacteristics = getBusinessObject(target).loopCharacteristics;
465467

468+
// remove
466469
if (entry.active) {
467-
newLoopCharacteristics = undefined;
468-
} else {
469-
if (isUndefined(entry.options.isSequential) || !newLoopCharacteristics
470-
|| !is(newLoopCharacteristics, entry.options.loopCharacteristics)) {
471-
newLoopCharacteristics = self._moddle.create(entry.options.loopCharacteristics);
472-
}
470+
self._modeling.updateProperties(target, { loopCharacteristics: undefined });
471+
return;
472+
}
473+
474+
const currentLoopCharacteristics = target.businessObject.get('loopCharacteristics'),
475+
newLoopCharacteristics = self._moddle.create(entry.options.loopCharacteristics);
473476

474-
newLoopCharacteristics.isSequential = entry.options.isSequential;
477+
// copy old properties
478+
if (currentLoopCharacteristics) {
479+
self._moddleCopy.copyElement(currentLoopCharacteristics, newLoopCharacteristics);
475480
}
481+
482+
// update `isSequential` property
483+
newLoopCharacteristics.set('isSequential', entry.options.isSequential);
484+
476485
self._modeling.updateProperties(target, { loopCharacteristics: newLoopCharacteristics });
477486
}
478487

test/fixtures/bpmn/draw/activity-markers-simple.bpmn

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="_opd4cBZiEeWgh4rX9Ivzlg" targetNamespace="http://activiti.org/bpmn" exporter="Camunda Modeler" exporterVersion="1.0.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
2+
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="_opd4cBZiEeWgh4rX9Ivzlg" targetNamespace="http://activiti.org/bpmn" exporter="Camunda Modeler" exporterVersion="1.0.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
33
<bpmn2:process id="Process_1" isExecutable="false">
44
<bpmn2:task id="ParallelTask" name="ParallelTask">
55
<bpmn2:multiInstanceLoopCharacteristics camunda:collection="foo" camunda:elementVariable="bar">

test/spec/features/popup-menu/ReplaceMenuProviderSpec.js

+66
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,72 @@ describe('features/popup-menu - replace menu provider', function() {
779779
}));
780780
});
781781

782+
783+
describe('integration', function() {
784+
785+
it('should toggle sequential -> undo to parallel', inject(function(elementRegistry, commandStack) {
786+
787+
// given
788+
var task = elementRegistry.get('ParallelTask');
789+
790+
openPopup(task);
791+
792+
// when
793+
triggerAction('toggle-sequential-mi');
794+
795+
commandStack.undo();
796+
797+
// then
798+
const bo = getBusinessObject(task),
799+
loopCharacteristics = bo.get('loopCharacteristics');
800+
801+
expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.true;
802+
expect(loopCharacteristics.isSequential).to.be.false;
803+
}));
804+
805+
806+
it('should toggle parallel -> undo to parallel', inject(function(elementRegistry, commandStack) {
807+
808+
// given
809+
var task = elementRegistry.get('ParallelTask');
810+
811+
openPopup(task);
812+
813+
// when
814+
triggerAction('toggle-parallel-mi');
815+
816+
commandStack.undo();
817+
818+
// then
819+
const bo = getBusinessObject(task),
820+
loopCharacteristics = bo.get('loopCharacteristics');
821+
822+
expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.true;
823+
expect(loopCharacteristics.isSequential).to.be.false;
824+
}));
825+
826+
827+
it('should toggle loop -> undo to parallel', inject(function(elementRegistry, commandStack) {
828+
829+
// given
830+
var task = elementRegistry.get('ParallelTask');
831+
832+
openPopup(task);
833+
834+
// when
835+
triggerAction('toggle-loop');
836+
837+
commandStack.undo();
838+
839+
// then
840+
const bo = getBusinessObject(task),
841+
loopCharacteristics = bo.get('loopCharacteristics');
842+
843+
expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.true;
844+
expect(loopCharacteristics.isSequential).to.be.false;
845+
}));
846+
});
847+
782848
});
783849

784850

0 commit comments

Comments
 (0)