Skip to content

Commit

Permalink
fix: automatically update variable
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul99ahad committed Aug 26, 2024
1 parent 2ca70f5 commit fd81b34
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import DmnFactory from './DmnFactory';
import ElementFactory from './ElementFactory';
import IdChangeBehavior from
'dmn-js-shared/lib/features/modeling/behavior/IdChangeBehavior';
import NameChangeBehavior from
'dmn-js-shared/lib/features/modeling/behavior/NameChangeBehavior';
import Modeling from './Modeling';
import Behavior from './behavior';

export default {
__init__: [ 'dmnUpdater', 'idChangeBehavior', 'modeling' ],
__init__: [ 'dmnUpdater', 'idChangeBehavior', 'nameChangeBehavior', 'modeling' ],
__depends__: [ Behavior, CommandStack ],
dmnUpdater: [ 'type', DmnUpdater ],
dmnFactory: [ 'type', DmnFactory ],
elementFactory: [ 'type', ElementFactory ],
idChangeBehavior: [ 'type', IdChangeBehavior ],
nameChangeBehavior: [ 'type', NameChangeBehavior ],
modeling: [ 'type', Modeling ]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { bootstrapModeler, inject } from 'test/helper';

import decisionTableXML from './name-change-behavior.dmn';

import CoreModule from 'src/core';
import Modeling from 'src/features/modeling';


describe('NameChangeBehavior', function() {

describe('with existing variable', function() {

beforeEach(bootstrapModeler(decisionTableXML, {
modules: [
CoreModule,
Modeling
],
}));


it('should update variable name when element name is changed', inject(
function(modeling, sheet) {

// given
const root = sheet.getRoot(),
decisionTable = root.businessObject;

const decision = decisionTable.$parent;

// when
modeling.editDecisionTableName('foo');

// then
const variable = decision.get('variable');

expect(variable.get('name')).to.equal('foo');
}
));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" id="dish" name="Desired Dish" namespace="party" exporter="Camunda Modeler" exporterVersion="5.25.0">
<inputData id="InputData_0wikdil" name="Variable" />
<decision id="season" name="Season">
<variable id="InformationItem_var" name="Season" />
<informationRequirement id="InformationRequirement_13flr3u">
<requiredInput href="#InputData_0wikdil" />
</informationRequirement>
<decisionTable id="DecisionTable_0hzuy0u">
<input id="InputClause_1c1qe3j">
<inputExpression id="LiteralExpression_0qgvyx9" typeRef="string" />
</input>
<output id="OutputClause_1xvwwox" typeRef="string" />
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram>
<dmndi:DMNShape id="DMNShape_1ds1jom" dmnElementRef="InputData_0wikdil">
<dc:Bounds height="45" width="125" x="138" y="198" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_0qwszuo" dmnElementRef="InformationRequirement_13flr3u">
<di:waypoint x="201" y="198" />
<di:waypoint x="200" y="155" />
<di:waypoint x="200" y="135" />
</dmndi:DMNEdge>
<dmndi:DMNShape id="DMNShape_0d8mpxr" dmnElementRef="season">
<dc:Bounds height="55" width="100" x="150" y="80" />
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ export default class Modeling {

this._commandStack.execute('element.updateProperties', context);
}

updateProperties(el, props) {
const context = {
element: el,
properties: props
};

this._commandStack.execute('element.updateProperties', context);
}
}

Modeling.$inject = [ 'commandStack', 'viewer', 'eventBus' ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ export default class NameChangeBehavior extends CommandInterceptor {
updateVariableFromLabel = ({ context }) => {
const { element, newLabel } = context;
const bo = getBusinessObject(element);

if (!bo.variable) {
return;
}

bo.variable.name = newLabel;
this._modeling.updateProperties(element, { variable: bo.variable });
};

updateVariableFromElement = ({ context }) => {
const { element, properties } = context;
const bo = getBusinessObject(element);

if (!bo.variable) {
return;
}

if (!(is(element, 'dmn:Decision') || is(element, 'dmn:BusinessKnowledgeModel'))) {
return;
Expand All @@ -39,11 +46,13 @@ export default class NameChangeBehavior extends CommandInterceptor {
if (!this.isNameChanged(properties)) {
return;
}

if (this.isVariable(element)) {
return;
}

else if (!this.isElementVariable(element)) {
this.syncElementVariableChange(element);
this.syncElementVariableChange(bo);
}
};

Expand All @@ -53,7 +62,6 @@ export default class NameChangeBehavior extends CommandInterceptor {

isVariable(element) {
const parent = getParent(element);

return (
is(element, 'dmn:InformationItem') &&
parent && parent.get('variable') === element
Expand All @@ -65,9 +73,10 @@ export default class NameChangeBehavior extends CommandInterceptor {
return variable && (element.name === variable.name);
}

syncElementVariableChange(element) {
const newName = element.get('name');
this._modeling.editVariableName(newName);
syncElementVariableChange(businessObject) {
const name = businessObject.get('name');
const variable = businessObject.variable;
this._modeling.updateProperties(variable, { name });
}
}

Expand Down

0 comments on commit fd81b34

Please sign in to comment.