From 5a5b682ccdf9c7478a5432945ef6494d48700597 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Fri, 8 Nov 2024 10:41:40 +0100 Subject: [PATCH] fix: make name change behavior not break on name change Related to https://github.com/bpmn-io/dmn-js-properties-panel/issues/103 Related to https://github.com/camunda/camunda-modeler/issues/4684 Co-authored-by: Nico Rehwaldt --- .../behavior/NameChangeBehaviorSpec.js | 127 ++++++++++++------ .../modeling/behavior/NameChangeBehavior.js | 9 +- packages/dmn-js/CHANGELOG.md | 4 + 3 files changed, 98 insertions(+), 42 deletions(-) diff --git a/packages/dmn-js-drd/test/spec/features/modeling/behavior/NameChangeBehaviorSpec.js b/packages/dmn-js-drd/test/spec/features/modeling/behavior/NameChangeBehaviorSpec.js index 42369271..e1f193fa 100644 --- a/packages/dmn-js-drd/test/spec/features/modeling/behavior/NameChangeBehaviorSpec.js +++ b/packages/dmn-js-drd/test/spec/features/modeling/behavior/NameChangeBehaviorSpec.js @@ -6,68 +6,119 @@ import CoreModule from 'src/core'; import Modeling from 'src/features/modeling'; -describe('NameChangeBehavior', function() { +describe('features/modeling - NameChangeBehavior', function() { - describe('with label change', function() { + beforeEach(bootstrapModeler(simpleStringEditXML, { + modules: [ + CoreModule, + Modeling + ], + })); - beforeEach(bootstrapModeler(simpleStringEditXML, { - modules: [ - CoreModule, - Modeling - ], - })); - - describe('should update variable name when label is changed', function() { - - - it('', inject( - function(modeling, elementRegistry) { - - // given - const decision = elementRegistry.get('season'), - bo = decision.businessObject, - variable = bo.variable; - // when - modeling.updateLabel(decision,'foo'); + describe('should update variable name when label is changed', function() { - // then - expect(variable.get('name')).to.equal('foo'); - } - )); - - - it('', inject(function(modeling, elementRegistry, commandStack) { + it('', inject( + function(modeling, elementRegistry) { // given const decision = elementRegistry.get('season'), bo = decision.businessObject, variable = bo.variable; - modeling.updateLabel(decision,'foo'); // when - commandStack.undo(); + modeling.updateLabel(decision,'foo'); // then - expect(variable.get('name')).to.equal('season'); - })); + expect(variable.get('name')).to.equal('foo'); + } + )); + + + it('', inject(function(modeling, elementRegistry, commandStack) { + + // given + const decision = elementRegistry.get('season'), + bo = decision.businessObject, + variable = bo.variable; + modeling.updateLabel(decision,'foo'); + + // when + commandStack.undo(); + + // then + expect(variable.get('name')).to.equal('season'); + })); + + + it('', inject(function(modeling, elementRegistry, commandStack) { + + // given + const decision = elementRegistry.get('season'), + bo = decision.businessObject, + variable = bo.variable; + modeling.updateLabel(decision,'foo'); + // when + commandStack.undo(); + commandStack.redo(); + + // then + expect(variable.get('name')).to.equal('foo'); + })); + }); + + + describe('should update variable name when element name is changed', function() { - it('', inject(function(modeling, elementRegistry, commandStack) { + + it('', inject( + function(modeling, elementRegistry) { // given const decision = elementRegistry.get('season'), bo = decision.businessObject, variable = bo.variable; - modeling.updateLabel(decision,'foo'); // when - commandStack.undo(); - commandStack.redo(); + modeling.updateProperties(decision, { name: 'foo' }); // then expect(variable.get('name')).to.equal('foo'); - })); - }); + } + )); + + + it('', inject(function(modeling, elementRegistry, commandStack) { + + // given + const decision = elementRegistry.get('season'), + bo = decision.businessObject, + variable = bo.variable; + modeling.updateProperties(decision, { name: 'foo' }); + + // when + commandStack.undo(); + + // then + expect(variable.get('name')).to.equal('season'); + })); + + + it('', inject(function(modeling, elementRegistry, commandStack) { + + // given + const decision = elementRegistry.get('season'), + bo = decision.businessObject, + variable = bo.variable; + modeling.updateProperties(decision, { name: 'foo' }); + + // when + commandStack.undo(); + commandStack.redo(); + + // then + expect(variable.get('name')).to.equal('foo'); + })); }); }); diff --git a/packages/dmn-js-shared/src/features/modeling/behavior/NameChangeBehavior.js b/packages/dmn-js-shared/src/features/modeling/behavior/NameChangeBehavior.js index b1a277b1..565112c6 100644 --- a/packages/dmn-js-shared/src/features/modeling/behavior/NameChangeBehavior.js +++ b/packages/dmn-js-shared/src/features/modeling/behavior/NameChangeBehavior.js @@ -51,7 +51,7 @@ export default class NameChangeBehavior extends CommandInterceptor { return; } - else if (!this.isElementVariable(element)) { + else if (!this.shouldSyncVariable(element)) { this.syncElementVariableChange(bo); } }; @@ -68,9 +68,10 @@ export default class NameChangeBehavior extends CommandInterceptor { ); } - isElementVariable(element) { - const variable = element.get('variable'); - return variable && (element.name === variable.name); + shouldSyncVariable(element) { + const bo = getBusinessObject(element), + variable = bo.get('variable'); + return variable && (bo.name === variable.name); } syncElementVariableChange(businessObject) { diff --git a/packages/dmn-js/CHANGELOG.md b/packages/dmn-js/CHANGELOG.md index 3e002736..dafbfe0f 100644 --- a/packages/dmn-js/CHANGELOG.md +++ b/packages/dmn-js/CHANGELOG.md @@ -16,6 +16,10 @@ ___Note:__ Yet to be released changes appear here._ * Keyboard (DRD) is now implicit, and canvas is focusable, cf. [bpmn-io/diagram-js#662](https://github.com/bpmn-io/diagram-js/pull/662)) +## 16.8.2 + +* `FIX`: make name change behavior not break on name change ([#917](https://github.com/bpmn-io/dmn-js/pull/917)) + ## 16.8.1 * `FIX`: make literal expression editor hitbox bigger in BKM ([camunda/camunda-modeler#4545](https://github.com/camunda/camunda-modeler/issues/4545))