Skip to content

Commit

Permalink
fix(drd-updater): do not move edges to text annotation targets
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and nikku committed Nov 25, 2019
1 parent 5ae92c6 commit 90a7952
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 51 deletions.
34 changes: 19 additions & 15 deletions packages/dmn-js-drd/src/features/modeling/DrdUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default function DrdUpdater(
connectionBo = connection.businessObject,
target = context.target,
targetBo = target.businessObject,
extensionElements = targetBo.extensionElements,
extensionElements = targetBo.get('extensionElements'),
di = context.di;

if (is(connection, 'dmn:Association')) {
Expand All @@ -150,7 +150,7 @@ export default function DrdUpdater(
var connection = context.connection,
target = context.target,
targetBo = target.businessObject,
extensionElements = targetBo.extensionElements,
extensionElements = targetBo.get('extensionElements'),
di = context.di;

reverseUpdateParent(context);
Expand All @@ -166,7 +166,7 @@ export default function DrdUpdater(
source = context.source,
target = context.target,
targetBo = target.businessObject,
extensionElements = targetBo.extensionElements;
extensionElements = targetBo.get('extensionElements');

if (is(connection, 'dmn:Association')) {
return;
Expand All @@ -188,7 +188,7 @@ export default function DrdUpdater(
target = context.target,
oldDI = context.oldDI,
targetBo = target.businessObject,
extensionElements = targetBo.extensionElements;
extensionElements = targetBo.get('extensionElements');

if (!oldDI || is(connection, 'dmn:Association')) {
return;
Expand All @@ -204,10 +204,10 @@ export default function DrdUpdater(
newSource = context.newSource,
oldTarget = context.oldTarget,
oldTargetBo = oldTarget.businessObject,
oldTargetBoExtensionElements = oldTargetBo.extensionElements,
oldTargetBoExtensionElements = oldTargetBo.get('extensionElements'),
newTarget = context.newTarget,
newTargetBo = newTarget.businessObject,
newTargetBoExtensionElements = newTargetBo.extensionElements;
newTargetBoExtensionElements = newTargetBo.get('extensionElements');

self.updateSemanticParent(connectionBo, newTargetBo);

Expand All @@ -225,7 +225,9 @@ export default function DrdUpdater(
remove(oldTargetBoExtensionElements.get('values'), edge);

// (2) add edge to new target
newTargetBoExtensionElements.get('values').push(edge);
if (!is(newTarget, 'dmn:TextAnnotation')) {
newTargetBoExtensionElements.get('values').push(edge);
}

// (3) reference new source
if (newSource) {
Expand All @@ -241,10 +243,10 @@ export default function DrdUpdater(
newSource = context.newSource,
oldTarget = context.oldTarget,
oldTargetBo = oldTarget.businessObject,
oldTargetBoExtensionElements = oldTargetBo.extensionElements,
oldTargetBoExtensionElements = oldTargetBo.get('extensionElements'),
newTarget = context.newTarget,
newTargetBo = newTarget.businessObject,
newTargetBoExtensionElements = newTargetBo.extensionElements;
newTargetBoExtensionElements = newTargetBo.get('extensionElements');

self.updateSemanticParent(connectionBo, oldTargetBo);

Expand All @@ -260,7 +262,9 @@ export default function DrdUpdater(
if (edge) {

// (1) remove edge from new target
remove(newTargetBoExtensionElements.get('values'), edge);
if (!is(newTarget, 'dmn:TextAnnotation')) {
remove(newTargetBoExtensionElements.get('values'), edge);
}

// (2) add edge to old target
oldTargetBoExtensionElements.get('values').push(edge);
Expand Down Expand Up @@ -288,7 +292,7 @@ export default function DrdUpdater(
forEach(outgoing, function(connection) {
var target = connection.target,
targetBo = target.businessObject,
extensionElements = targetBo.extensionElements;
extensionElements = targetBo.get('extensionElements');

var edge = find(extensionElements.get('values'), function(extensionElement) {
return is(extensionElement, 'biodi:Edge') &&
Expand Down Expand Up @@ -318,7 +322,7 @@ export default function DrdUpdater(
forEach(outgoing, function(connection) {
var target = connection.target,
targetBo = target.businessObject,
extensionElements = targetBo.extensionElements;
extensionElements = targetBo.get('extensionElements');

var edge = find(extensionElements.get('values'), function(extensionElement) {
return is(extensionElement, 'biodi:Edge') &&
Expand Down Expand Up @@ -347,7 +351,7 @@ DrdUpdater.prototype.updateBounds = function(shape) {
var drdFactory = this._drdFactory;

var businessObject = shape.businessObject,
extensionElements = businessObject.extensionElements,
extensionElements = businessObject.get('extensionElements'),
bounds;

if (!extensionElements) {
Expand Down Expand Up @@ -390,9 +394,9 @@ DrdUpdater.prototype.updateConnectionWaypoints = function(context) {
extensionElements;

if (is(connection, 'dmn:Association')) {
extensionElements = connectionBo.extensionElements;
extensionElements = connectionBo.get('extensionElements');
} else {
extensionElements = targetBo.extensionElements;
extensionElements = targetBo.get('extensionElements');
}

var edge = find(extensionElements.get('values'), function(extensionElement) {
Expand Down
100 changes: 65 additions & 35 deletions packages/dmn-js-drd/test/spec/features/modeling/DrdUpdaterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,59 +157,89 @@ describe('features/modeling - DrdUpdater', function() {

describe('move edge to new target on reconnect connection', function() {

var decision,
decisionBo,
edge;
describe('decision', function() {

beforeEach(inject(function(elementRegistry, modeling) {
var decision,
decisionBo,
edge;

// given
decision = elementRegistry.get('Decision_2');
beforeEach(inject(function(elementRegistry, modeling) {

decisionBo = decision.businessObject;
// given
decision = elementRegistry.get('Decision_2');

edge = getEdge(decisionBo);
decisionBo = decision.businessObject;

var connection = decision.incoming[ 0 ];
edge = getEdge(decisionBo);

// when
modeling.reconnect(
connection,
connection.source,
elementRegistry.get('Decision_3'),
getMid(elementRegistry.get('Decision_3'))
);
}));
var connection = decision.incoming[ 0 ];

// when
modeling.reconnect(
connection,
connection.source,
elementRegistry.get('Decision_3'),
getMid(elementRegistry.get('Decision_3'))
);
}));

it('<do>', function() {

// then
expect(getEdge(decisionBo)).not.to.exist;
});
it('<do>', function() {

// then
expect(getEdge(decisionBo)).not.to.exist;
});

it('<undo>', inject(function(commandStack) {

// when
commandStack.undo();
it('<undo>', inject(function(commandStack) {

// then
expect(getEdge(decisionBo)).to.equal(edge);
}));
// when
commandStack.undo();

// then
expect(getEdge(decisionBo)).to.equal(edge);
}));

it('<redo>', inject(function(commandStack) {

// given
commandStack.undo();
it('<redo>', inject(function(commandStack) {

// when
commandStack.redo();
// given
commandStack.undo();

// then
expect(getEdge(decisionBo)).not.to.exist;
}));
// when
commandStack.redo();

// then
expect(getEdge(decisionBo)).not.to.exist;
}));

});


it('should NOT move edge to text annotation', inject(
function(elementRegistry, modeling) {

// given
var decision = elementRegistry.get('Decision_2'),
decisionBo = decision.businessObject,
textAnnotation = elementRegistry.get('TextAnnotation_1'),
textAnnotationBo = textAnnotation.businessObject;

var connection = decision.incoming[ 0 ];

// when
modeling.reconnect(
connection,
connection.source,
textAnnotation,
getMid(textAnnotation)
);

// then
expect(getEdge(decisionBo)).to.not.exist;
expect(getEdge(textAnnotationBo)).to.not.exist;
})
);

});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/1.0" id="Definitions_1" name="DRD" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="3.3.5">
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/1.0" id="Definitions_1" name="DRD" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="3.4.1">
<decision id="Decision_1">
<extensionElements>
<biodi:bounds x="157" y="100" width="180" height="80" />
Expand All @@ -22,4 +22,9 @@
<biodi:bounds x="157" y="300" width="180" height="80" />
</extensionElements>
</decision>
<textAnnotation id="TextAnnotation_1">
<extensionElements>
<biodi:bounds x="400" y="100" width="100" height="80" />
</extensionElements>
</textAnnotation>
</definitions>

0 comments on commit 90a7952

Please sign in to comment.