Skip to content

Commit

Permalink
feat(modeling): keep global elements when deleting last participant
Browse files Browse the repository at this point in the history
closes #1676
  • Loading branch information
marstamm committed May 28, 2024
1 parent 8a0fcc3 commit d640a3c
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/features/modeling/Modeling.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ Modeling.prototype.makeProcess = function() {
};

this._commandStack.execute('canvas.updateRoot', context);

return processElement;
};

/**
Expand Down
7 changes: 6 additions & 1 deletion lib/features/modeling/behavior/RemoveParticipantBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export default function RemoveParticipantBehavior(eventBus, modeling) {
if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {

// replace empty collaboration with process diagram
modeling.makeProcess();
var process = modeling.makeProcess();

// move all root elements from collaboration to process
var children = collaborationRoot.children.slice();

modeling.moveElements(children, { x: 0, y: 0 }, process);
}
}, true);

Expand Down
23 changes: 23 additions & 0 deletions test/fixtures/bpmn/collaboration/collaboration-data-store.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="_P58jANhOEeSW1LwlVzMs4g" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="5.22.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:collaboration id="_Collaboration_2">
<bpmn2:participant id="_Participant_2" name="Participant" processRef="Process_1" />
</bpmn2:collaboration>
<bpmn2:process id="Process_1" isExecutable="false">
<bpmn2:dataStoreReference id="DataStoreReference_1by5u7v" />
<bpmn2:startEvent id="Event_13f8lfq" />
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_2">
<bpmndi:BPMNShape id="_BPMNShape_Participant_2" bpmnElement="_Participant_2" isHorizontal="true">
<dc:Bounds x="154" y="82" width="546" height="236" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_13f8lfq_di" bpmnElement="Event_13f8lfq">
<dc:Bounds x="222" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="DataStoreReference_1by5u7v_di" bpmnElement="DataStoreReference_1by5u7v">
<dc:Bounds x="154" y="375" width="50" height="50" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('features/modeling - remove participant behavior', function() {

describe('when removing last remaining participant', function() {

var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-empty-participant.bpmn');
var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-data-store.bpmn');

beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));

Expand Down Expand Up @@ -89,6 +89,9 @@ describe('features/modeling - remove participant behavior', function() {
expect(getDi(newRootShape)).to.eql(diPlane);

expect(bpmnDefinitions.rootElements).to.include(newRootBusinessObject);

// data store is preserved
expect(newRootShape.children).to.have.length(1);
}));


Expand Down Expand Up @@ -126,4 +129,97 @@ describe('features/modeling - remove participant behavior', function() {

});


describe('when removing all diagram content', function() {

var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-data-store.bpmn');

beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));

describe('should transform diagram into process diagram', function() {

it('execute', inject(function(modeling, elementRegistry, canvas) {

// given
var participantShape = elementRegistry.get('_Participant_2'),
participant = participantShape.businessObject,
participantDi = getDi(participantShape),
process = participant.processRef,
collaborationElement = participantShape.parent,
collaboration = collaborationElement.businessObject,
diPlane = getDi(collaborationElement),
bpmnDefinitions = collaboration.$parent;

// when
var rootElement = canvas.getRootElement();

var elements = elementRegistry.filter(function(element) {
return element !== rootElement;
});

modeling.removeElements(elements);

// then
expect(participant.$parent).not.to.be.ok;

var newRootShape = canvas.getRootElement(),
newRootBusinessObject = newRootShape.businessObject;

expect(newRootBusinessObject.$instanceOf('bpmn:Process')).to.be.true;

// collaboration DI is unwired
expect(participantDi.$parent).not.to.be.ok;
expect(getDi(collaborationElement)).not.to.be.ok;

expect(bpmnDefinitions.rootElements).not.to.include(process);
expect(bpmnDefinitions.rootElements).not.to.include(collaboration);

// process DI is wired
expect(diPlane.bpmnElement).to.eql(newRootBusinessObject);
expect(getDi(newRootShape)).to.eql(diPlane);

expect(bpmnDefinitions.rootElements).to.include(newRootBusinessObject);
}));


it('undo', inject(function(modeling, elementRegistry, canvas, commandStack) {

// given
var participantShape = elementRegistry.get('_Participant_2'),
participant = participantShape.businessObject,
originalRootElement = participantShape.parent,
originalRootElementBo = originalRootElement.businessObject,
originalRootElementDi = getDi(originalRootElement),
bpmnDefinitions = originalRootElementBo.$parent,
participantDi = getDi(participantShape),
diPlane = participantDi.$parent;

var rootElement = canvas.getRootElement();

var elements = elementRegistry.filter(function(element) {
return element !== rootElement;
});

modeling.removeElements(elements);

// when
commandStack.undo();

// then
expect(participant.$parent).to.eql(originalRootElementBo);
expect(originalRootElementBo.$parent).to.eql(bpmnDefinitions);

expect(canvas.getRootElement()).to.eql(originalRootElement);

// di is unwired
expect(participantDi.$parent).to.eql(originalRootElementDi);

// new di is wired
expect(diPlane.bpmnElement).to.eql(originalRootElementBo);
}));

});

});

});

0 comments on commit d640a3c

Please sign in to comment.