feat: replace elements on create

Closes #1340
This commit is contained in:
Maciej Barelkowski 2021-04-15 09:18:15 +02:00
parent f4eb87188d
commit 175d92d931
2 changed files with 478 additions and 402 deletions

View File

@ -24,6 +24,19 @@ export default function ReplaceElementBehaviour(
this._elementRegistry = elementRegistry; this._elementRegistry = elementRegistry;
this._selection = selection; this._selection = selection;
// replace elements on create, e.g. during copy-paste
this.postExecuted([ 'elements.create' ], 500, function(event) {
var context = event.context,
target = context.parent,
elements = context.elements;
var canReplace = bpmnRules.canReplace(elements, target);
if (canReplace) {
this.replaceElements(elements, canReplace.replacements);
}
}, this);
// replace elements on move // replace elements on move
this.postExecuted([ 'elements.move' ], 500, function(event) { this.postExecuted([ 'elements.move' ], 500, function(event) {
var context = event.context, var context = event.context,

View File

@ -21,7 +21,9 @@ import {
var ATTACH = { attach: true }; var ATTACH = { attach: true };
describe('features/modeling - move start event behavior', function() { describe('features/modeling - replace element behavior', function() {
describe('<shape.move>', function() {
var testModules = [ var testModules = [
replacePreviewModule, replacePreviewModule,
@ -452,5 +454,66 @@ describe('features/modeling - move start event behavior', function() {
})); }));
}); });
});
describe('shape.create', function() {
var diagramXML = require('../../../../fixtures/bpmn/event-sub-processes.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: [
replacePreviewModule,
modelingModule,
coreModule
]
}));
it('should replace Timer Start Event with None Start Event when created in SubProcess',
inject(function(elementRegistry, modeling, elementFactory) {
// given
var subProcess = elementRegistry.get('SubProcess_3'),
startEvent = elementFactory.createShape(
{ type: 'bpmn:StartEvent', eventDefinitionType: 'bpmn:TimerEventDefinition' }),
id = startEvent.businessObject.id;
// when
modeling.createElements(
startEvent, { x: subProcess.x + 30, y: subProcess.y + 30 }, subProcess);
// then
var createdEvent = elementRegistry.get(id);
expect(createdEvent).to.exist;
expect(createdEvent.businessObject.eventDefinitions).to.not.exist;
})
);
it('should NOT replace Timer Start Event when created in EventSubProcess',
inject(function(elementRegistry, modeling, elementFactory) {
// given
var subProcess = elementRegistry.get('SubProcess_2'),
startEvent = elementFactory.createShape(
{ type: 'bpmn:StartEvent', eventDefinitionType: 'bpmn:TimerEventDefinition' }),
id = startEvent.businessObject.id;
// when
modeling.createElements(
startEvent, { x: subProcess.x + 30, y: subProcess.y + 30 }, subProcess);
// then
var createdEvent = elementRegistry.get(id);
expect(createdEvent).to.eql(startEvent);
expect(createdEvent.businessObject.eventDefinitions).to.have.lengthOf(1);
expect(
is(createdEvent.businessObject.eventDefinitions[0], 'bpmn:TimerEventDefinition')
).to.be.true;
})
);
});
}); });