From 06e1478fc83b7d3581065e394bfdd40f5f1c69f7 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Thu, 14 Nov 2019 08:52:19 +0100 Subject: [PATCH] chore(rules): remove rule --- lib/features/modeling/BpmnUpdater.js | 111 +++++++----------- .../behavior/BoundaryEventBehavior.js | 2 +- .../behavior/DataInputAssociationBehavior.js | 4 +- .../behavior/ReplaceConnectionBehavior.js | 10 +- lib/features/rules/BpmnRules.js | 18 --- .../custom-elements/CustomRules.js | 13 +- .../popup-menu/ReplaceMenuProviderSpec.js | 66 ----------- 7 files changed, 48 insertions(+), 176 deletions(-) diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index f45489fc..28d24076 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -178,16 +178,14 @@ export default function BpmnUpdater( 'connection.create', 'connection.move', 'connection.delete', - 'connection.reconnectEnd', - 'connection.reconnectStart' + 'connection.reconnect' ], ifBpmn(updateConnection)); this.reverted([ 'connection.create', 'connection.move', 'connection.delete', - 'connection.reconnectEnd', - 'connection.reconnectStart' + 'connection.reconnect' ], ifBpmn(updateConnection)); @@ -208,85 +206,56 @@ export default function BpmnUpdater( 'connection.updateWaypoints', ], ifBpmn(updateConnectionWaypoints)); - - // update Default & Conditional flows - this.executed([ - 'connection.reconnectEnd', - 'connection.reconnectStart' - ], ifBpmn(function(e) { - var context = e.context, + // update conditional/default flows + this.executed('connection.reconnect', ifBpmn(function(event) { + var context = event.context, connection = context.connection, - businessObject = getBusinessObject(connection), - oldSource = getBusinessObject(context.oldSource), - oldTarget = getBusinessObject(context.oldTarget), - newSource = getBusinessObject(connection.source), - newTarget = getBusinessObject(connection.target); + oldSource = context.oldSource, + newSource = context.newSource, + connectionBo = getBusinessObject(connection), + oldSourceBo = getBusinessObject(oldSource), + newSourceBo = getBusinessObject(newSource); - if (oldSource === newSource || oldTarget === newTarget) { - return; + // remove condition from connection on reconnect to new source + // if new source can NOT have condional sequence flow + if (connectionBo.conditionExpression && !isAny(newSourceBo, [ + 'bpmn:Activity', + 'bpmn:ExclusiveGateway', + 'bpmn:InclusiveGateway' + ])) { + context.oldConditionExpression = connectionBo.conditionExpression; + + delete connectionBo.conditionExpression; } - // on reconnectStart -> default flow - if (oldSource && oldSource.default === businessObject) { - context.default = oldSource.default; - oldSource.default = undefined; - } + // remove default from old source flow on reconnect to new source + // if source changed + if (oldSource !== newSource && oldSourceBo.default === connectionBo) { + context.oldDefault = oldSourceBo.default; - // on reconnectEnd -> default flow - if ((businessObject.sourceRef && businessObject.sourceRef.default) && - !isAny(newTarget, [ - 'bpmn:Activity', - 'bpmn:EndEvent', - 'bpmn:Gateway', - 'bpmn:IntermediateThrowEvent', - 'bpmn:IntermediateCatchEvent' - ])) { - context.default = businessObject.sourceRef.default; - businessObject.sourceRef.default = undefined; - } - - // on reconnectStart -> conditional flow - if (oldSource && (businessObject.conditionExpression) && - !(is(newSource, 'bpmn:Activity') || - is(newSource, 'bpmn:Gateway'))) { - context.conditionExpression = businessObject.conditionExpression; - businessObject.conditionExpression = undefined; - } - - // on reconnectEnd -> conditional flow - if (oldTarget && (businessObject.conditionExpression) && - !isAny(newTarget, [ - 'bpmn:Activity', - 'bpmn:EndEvent', - 'bpmn:Gateway', - 'bpmn:IntermediateThrowEvent', - 'bpmn:IntermediateCatchEvent' - ])) { - context.conditionExpression = businessObject.conditionExpression; - businessObject.conditionExpression = undefined; + delete oldSourceBo.default; } })); - this.reverted([ - 'connection.reconnectEnd', - 'connection.reconnectStart' - ], ifBpmn(function(e) { - var context = e.context, + this.reverted('connection.reconnect', ifBpmn(function(event) { + var context = event.context, connection = context.connection, - businessObject = getBusinessObject(connection), - newSource = getBusinessObject(connection.source); + oldSource = context.oldSource, + newSource = context.newSource, + connectionBo = getBusinessObject(connection), + oldSourceBo = getBusinessObject(oldSource), + newSourceBo = getBusinessObject(newSource); - // default flow - if (context.default) { - if (is(newSource, 'bpmn:ExclusiveGateway') || is(newSource, 'bpmn:InclusiveGateway') || - is(newSource, 'bpmn:Activity')) { - newSource.default = context.default; - } + // add condition to connection on revert reconnect to new source + if (context.oldConditionExpression) { + connectionBo.conditionExpression = context.oldConditionExpression; } - // conditional flow - if (context.conditionExpression && is(newSource, 'bpmn:Activity')) { - businessObject.conditionExpression = context.conditionExpression; + // add default to old source on revert reconnect to new source + if (context.oldDefault) { + oldSourceBo.default = context.oldDefault; + + delete newSourceBo.default; } })); diff --git a/lib/features/modeling/behavior/BoundaryEventBehavior.js b/lib/features/modeling/behavior/BoundaryEventBehavior.js index 24501f47..5b1c149b 100644 --- a/lib/features/modeling/behavior/BoundaryEventBehavior.js +++ b/lib/features/modeling/behavior/BoundaryEventBehavior.js @@ -40,7 +40,7 @@ export default function BoundaryEventBehavior(eventBus, modeling) { }); // remove after replacing connected gateway with event-based gateway - this.postExecute('connection.reconnectStart', function(event) { + this.postExecute('connection.reconnect', function(event) { var oldSource = event.context.oldSource, newSource = event.context.newSource; diff --git a/lib/features/modeling/behavior/DataInputAssociationBehavior.js b/lib/features/modeling/behavior/DataInputAssociationBehavior.js index 59a251fe..eae529a0 100644 --- a/lib/features/modeling/behavior/DataInputAssociationBehavior.js +++ b/lib/features/modeling/behavior/DataInputAssociationBehavior.js @@ -39,14 +39,14 @@ export default function DataInputAssociationBehavior(eventBus, bpmnFactory) { 'connection.create', 'connection.delete', 'connection.move', - 'connection.reconnectEnd' + 'connection.reconnect' ], ifDataInputAssociation(fixTargetRef)); this.reverted([ 'connection.create', 'connection.delete', 'connection.move', - 'connection.reconnectEnd' + 'connection.reconnect' ], ifDataInputAssociation(fixTargetRef)); diff --git a/lib/features/modeling/behavior/ReplaceConnectionBehavior.js b/lib/features/modeling/behavior/ReplaceConnectionBehavior.js index d69e4cbb..e3681230 100644 --- a/lib/features/modeling/behavior/ReplaceConnectionBehavior.js +++ b/lib/features/modeling/behavior/ReplaceConnectionBehavior.js @@ -146,11 +146,7 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, forEach(allConnections, fixConnection); }, true); - this.preExecute([ - 'connection.reconnect', - 'connection.reconnectStart', - 'connection.reconnectEnd' - ], replaceReconnectedConnection); + this.preExecute('connection.reconnect', replaceReconnectedConnection); this.postExecuted('element.updateProperties', function(event) { var context = event.context, @@ -159,7 +155,7 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, businessObject = element.businessObject, connection; - // remove condition expression when morphing to default flow + // remove condition on change to default if (properties.default) { connection = find( element.outgoing, @@ -171,7 +167,7 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, } } - // remove default property from source when morphing to conditional flow + // remove default from source on change to conditional if (properties.conditionExpression && businessObject.sourceRef.default === businessObject) { modeling.updateProperties(element.source, { default: undefined }); } diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 1a364a42..6946173c 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -87,24 +87,6 @@ BpmnRules.prototype.init = function() { } }); - this.addRule('connection.reconnectStart', function(context) { - - var connection = context.connection, - source = context.hover || context.source, - target = connection.target; - - return canConnect(source, target, connection); - }); - - this.addRule('connection.reconnectEnd', function(context) { - - var connection = context.connection, - source = connection.source, - target = context.hover || context.target; - - return canConnect(source, target, connection); - }); - this.addRule('connection.reconnect', function(context) { var connection = context.connection, diff --git a/test/integration/custom-elements/CustomRules.js b/test/integration/custom-elements/CustomRules.js index c31d6a70..b2446887 100644 --- a/test/integration/custom-elements/CustomRules.js +++ b/test/integration/custom-elements/CustomRules.js @@ -28,24 +28,15 @@ CustomRules.prototype.init = function() { return canConnect(source, target); }); - this.addRule('connection.reconnectStart', HIGH_PRIORITY, function(context) { + this.addRule('connection.reconnect', HIGH_PRIORITY, function(context) { var connection = context.connection, - source = context.hover || context.source, + source = context.source, target = connection.target; return canConnect(source, target, connection); }); - this.addRule('connection.reconnectEnd', HIGH_PRIORITY, function(context) { - - var connection = context.connection, - source = connection.source, - target = context.hover || context.target; - - return canConnect(source, target, connection); - }); - this.addRule('connection.updateWaypoints', HIGH_PRIORITY, function(context) { // OK! but visually ignore diff --git a/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js b/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js index 285d71a9..c607ed15 100644 --- a/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js +++ b/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js @@ -1353,40 +1353,6 @@ describe('features/popup-menu - replace menu provider', function() { ); - [ - 'bpmn:StartEvent' - ].forEach(function(type) { - - it('should replace DefaultFlow with SequenceFlow when changing target to ' + type, - inject(function(elementRegistry, elementFactory, canvas, popupMenu, modeling) { - - // given - var sequenceFlow = elementRegistry.get('SequenceFlow_1'), - root = canvas.getRootElement(); - - var intermediateEvent = elementFactory.createShape({ type: type }); - - modeling.createShape(intermediateEvent, { x: 686, y: 50 }, root); - - openPopup(sequenceFlow); - - triggerAction(popupMenu, 'replace-with-default-flow'); - - // when - modeling.reconnectEnd(sequenceFlow, intermediateEvent, [ - { x: 686, y: 267, original: { x: 686, y: 307 } }, - { x: 686, y: 50, original: { x: 686, y: 75 } } - ]); - - var gateway = elementRegistry.get('ExclusiveGateway_1'); - - // then - expect(gateway.businessObject.default).not.to.exist; - }) - ); - }); - - [ 'bpmn:Activity', 'bpmn:EndEvent', @@ -1686,38 +1652,6 @@ describe('features/popup-menu - replace menu provider', function() { ); - [ - 'bpmn:StartEvent' - ].forEach(function(type) { - - it('should replace ConditionalFlow with SequenceFlow when changing target to ' + type, - inject(function(elementRegistry, elementFactory, canvas, popupMenu, modeling) { - - // given - var sequenceFlow = elementRegistry.get('SequenceFlow_3'), - root = canvas.getRootElement(), - intermediateEvent = elementFactory.createShape({ type: type }); - - modeling.createShape(intermediateEvent, { x: 497, y: 197 }, root); - - openPopup(sequenceFlow); - - triggerAction(popupMenu, 'replace-with-conditional-flow'); - - // when - modeling.reconnectEnd(sequenceFlow, intermediateEvent, [ - { x: 389, y: 197, original: { x: 389, y: 197 } }, - { x: 497, y: 197, original: { x: 497, y: 197 } } - ]); - - // then - expect(sequenceFlow.businessObject.conditionExpression).not.to.exist; - }) - ); - - }); - - [ 'bpmn:Activity', 'bpmn:EndEvent',