Skip to content

Commit 1ccba5c

Browse files
azeghersfake-join[bot]
authored andcommitted
feat(replace): add switch between DataStore and DataObject in replace menu
Closes bpmn-io#1372
1 parent d252ba2 commit 1ccba5c

8 files changed

Lines changed: 234 additions & 14 deletions

File tree

lib/features/popup-menu/ReplaceMenuProvider.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ ReplaceMenuProvider.prototype.getEntries = function(element) {
7777

7878
var differentType = isDifferentType(element);
7979

80+
if (is(businessObject, 'bpmn:DataObjectReference')) {
81+
return this._createEntries(element, replaceOptions.DATA_OBJECT_REFERENCE);
82+
}
83+
84+
if (is(businessObject, 'bpmn:DataStoreReference')) {
85+
return this._createEntries(element, replaceOptions.DATA_STORE_REFERENCE);
86+
}
87+
8088
// start events outside sub processes
8189
if (is(businessObject, 'bpmn:StartEvent') && !is(businessObject.$parent, 'bpmn:SubProcess')) {
8290

lib/features/replace/BpmnReplace.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default function BpmnReplace(
8484
moddleCopy,
8585
modeling,
8686
replace,
87+
rules,
8788
selection
8889
) {
8990

@@ -221,6 +222,11 @@ export default function BpmnReplace(
221222
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
222223
}
223224

225+
if (!rules.allowed('shape.resize', { shape: newBusinessObject })) {
226+
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
227+
newElement.width = elementFactory._getDefaultSize(newBusinessObject).width;
228+
}
229+
224230
newBusinessObject.name = oldBusinessObject.name;
225231

226232
// retain default flow's reference between inclusive <-> exclusive gateways and activities
@@ -247,6 +253,15 @@ export default function BpmnReplace(
247253
newElement.host = target.host;
248254
}
249255

256+
// The DataStoreReference element is 14px wider than the DataObjectReference element
257+
// This ensures that they stay centered on the x axis when replaced
258+
if (
259+
newElement.type === 'bpmn:DataStoreReference' ||
260+
newElement.type === 'bpmn:DataObjectReference'
261+
) {
262+
newElement.x = element.x + (element.width - newElement.width) / 2;
263+
}
264+
250265
newElement.di = {};
251266

252267
// fill and stroke will be set to DI
@@ -273,6 +288,7 @@ BpmnReplace.$inject = [
273288
'moddleCopy',
274289
'modeling',
275290
'replace',
291+
'rules',
276292
'selection'
277293
];
278294

lib/features/replace/ReplaceOptions.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,28 @@ export var TASK = [
537537
}
538538
];
539539

540+
export var DATA_OBJECT_REFERENCE = [
541+
{
542+
label: 'Data Store Reference',
543+
actionName: 'replace-with-data-store-reference',
544+
className: 'bpmn-icon-data-store',
545+
target: {
546+
type: 'bpmn:DataStoreReference'
547+
}
548+
}
549+
];
550+
551+
export var DATA_STORE_REFERENCE = [
552+
{
553+
label: 'Data Object Reference',
554+
actionName: 'replace-with-data-object-reference',
555+
className: 'bpmn-icon-data-object',
556+
target: {
557+
type: 'bpmn:DataObjectReference'
558+
}
559+
}
560+
];
561+
540562
export var BOUNDARY_EVENT = [
541563
{
542564
label: 'Message Boundary Event',

lib/util/DiUtil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function isExpanded(element) {
1515
}
1616

1717
if (is(element, 'bpmn:SubProcess')) {
18-
return !!getBusinessObject(element).di.isExpanded;
18+
return getBusinessObject(element).di && !!getBusinessObject(element).di.isExpanded;
1919
}
2020

2121
if (is(element, 'bpmn:Participant')) {

test/fixtures/bpmn/features/replace/data-object.bpmn renamed to test/fixtures/bpmn/features/replace/data-elements.bpmn

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
<bpmn:dataObjectReference id="DataObjectReference_1" dataObjectRef="DataObject" />
55
<bpmn:dataObject id="DataObject" />
66
<bpmn:dataObjectReference id="DataObjectReference_2" dataObjectRef="DataObject" />
7+
<bpmn:dataStoreReference id="DataStoreReference_1" dataStoreRef="DataStore" />
8+
<bpmn:dataStore id="DataStore" />
79
</bpmn:process>
810
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
911
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process">
1012
<bpmndi:BPMNShape id="DataObjectReference_1_di" bpmnElement="DataObjectReference_1">
11-
<dc:Bounds x="201" y="184" width="36" height="50" />
12-
<bpmndi:BPMNLabel>
13-
<dc:Bounds x="174" y="234" width="90" height="20" />
14-
</bpmndi:BPMNLabel>
13+
<dc:Bounds x="200" y="200" width="36" height="50" />
1514
</bpmndi:BPMNShape>
1615
<bpmndi:BPMNShape id="DataObjectReference_2_di" bpmnElement="DataObjectReference_2">
17-
<dc:Bounds x="301" y="184" width="36" height="50" />
18-
<bpmndi:BPMNLabel>
19-
<dc:Bounds x="274" y="234" width="90" height="20" />
20-
</bpmndi:BPMNLabel>
16+
<dc:Bounds x="300" y="200" width="36" height="50" />
17+
</bpmndi:BPMNShape>
18+
<bpmndi:BPMNShape id="DataStoreReference_1_di" bpmnElement="DataStoreReference_1">
19+
<dc:Bounds x="400" y="200" width="50" height="50" />
2120
</bpmndi:BPMNShape>
2221
</bpmndi:BPMNPlane>
2322
</bpmndi:BPMNDiagram>

test/spec/features/context-pad/ContextPadProviderSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ describe('features - context-pad', function() {
265265
expectContextPadEntries('DataStoreReference', [
266266
'connect',
267267
'append.text-annotation',
268-
'!replace',
268+
'replace',
269269
'!append.end-event'
270270
]);
271271
}));
@@ -489,11 +489,11 @@ describe('features - context-pad', function() {
489489

490490
// given
491491
var rootShape = canvas.getRootElement(),
492-
dataStore = elementFactory.createShape({ type: 'bpmn:DataStoreReference' }),
492+
group = elementFactory.createShape({ type: 'bpmn:Group' }),
493493
replaceMenu;
494494

495495
// when
496-
create.start(canvasEvent({ x: 0, y: 0 }), dataStore);
496+
create.start(canvasEvent({ x: 0, y: 0 }), group);
497497

498498
dragging.move(canvasEvent({ x: 50, y: 50 }));
499499
dragging.hover({ element: rootShape });

test/spec/features/popup-menu/ReplaceMenuProviderSpec.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('features/popup-menu - replace menu provider', function() {
2929

3030
var diagramXMLMarkers = require('../../../fixtures/bpmn/draw/activity-markers-simple.bpmn'),
3131
diagramXMLReplace = require('../../../fixtures/bpmn/features/replace/01_replace.bpmn'),
32-
diagramXMLDataObject = require('../../../fixtures/bpmn/features/replace/data-object.bpmn');
32+
diagramXMLDataElements = require('../../../fixtures/bpmn/features/replace/data-elements.bpmn');
3333

3434
var testModules = [
3535
coreModule,
@@ -50,9 +50,10 @@ describe('features/popup-menu - replace menu provider', function() {
5050
});
5151
};
5252

53+
5354
describe('data object - collection marker', function() {
5455

55-
beforeEach(bootstrapModeler(diagramXMLDataObject, { modules: testModules }));
56+
beforeEach(bootstrapModeler(diagramXMLDataElements, { modules: testModules }));
5657

5758

5859
it('should toggle on', inject(function(elementRegistry) {
@@ -1202,6 +1203,50 @@ describe('features/popup-menu - replace menu provider', function() {
12021203
});
12031204

12041205

1206+
describe('data object', function() {
1207+
1208+
beforeEach(bootstrapModeler(diagramXMLDataElements, { modules: testModules }));
1209+
1210+
1211+
it('should only contain data store reference', inject(function(elementRegistry) {
1212+
1213+
// given
1214+
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
1215+
1216+
// when
1217+
openPopup(dataObjectReference);
1218+
1219+
// then
1220+
expect(queryEntries()).to.have.length(2);
1221+
expect(queryEntry('toggle-is-collection')).to.exist;
1222+
expect(queryEntry('replace-with-data-store-reference')).to.exist;
1223+
expect(queryEntry('replace-with-data-object-reference')).to.be.null;
1224+
}));
1225+
});
1226+
1227+
1228+
describe('data store', function() {
1229+
1230+
beforeEach(bootstrapModeler(diagramXMLDataElements, { modules: testModules }));
1231+
1232+
1233+
it('should only contain data object reference', inject(function(elementRegistry) {
1234+
1235+
// given
1236+
var dataStoreReference = elementRegistry.get('DataStoreReference_1');
1237+
1238+
// when
1239+
openPopup(dataStoreReference);
1240+
1241+
// then
1242+
expect(queryEntries()).to.have.length(1);
1243+
expect(queryEntry('toggle-is-collection')).to.be.null;
1244+
expect(queryEntry('replace-with-data-store-reference')).to.be.null;
1245+
expect(queryEntry('replace-with-data-object-reference')).to.exist;
1246+
}));
1247+
1248+
});
1249+
12051250
});
12061251

12071252

test/spec/features/replace/BpmnReplaceSpec.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,136 @@ describe('features/replace - bpmn replace', function() {
16481648

16491649
});
16501650

1651+
1652+
describe('center', function() {
1653+
1654+
var diagramXML = require('../../../fixtures/bpmn/features/replace/data-elements.bpmn');
1655+
1656+
var testModules = [
1657+
modelingModule,
1658+
coreModule
1659+
];
1660+
1661+
beforeEach(bootstrapModeler(diagramXML, {
1662+
modules: testModules
1663+
}));
1664+
1665+
1666+
describe('data store reference to data object reference', function() {
1667+
1668+
it('should center on replace', inject(function(bpmnReplace, elementRegistry) {
1669+
1670+
// given
1671+
var dataStoreReference = elementRegistry.get('DataStoreReference_1');
1672+
var positionX = dataStoreReference.x;
1673+
1674+
// when
1675+
bpmnReplace.replaceElement(dataStoreReference, { type: 'bpmn:DataObjectReference' });
1676+
1677+
var dataObjectReference = elementRegistry.get('DataStoreReference_1');
1678+
var newPositionX = positionX + (dataStoreReference.width - dataObjectReference.width) / 2;
1679+
1680+
// then
1681+
expect(dataObjectReference.x).to.eql(newPositionX);
1682+
}));
1683+
1684+
1685+
it('should undo', inject(function(bpmnReplace, commandStack, elementRegistry) {
1686+
1687+
// given
1688+
var dataStoreReference = elementRegistry.get('DataStoreReference_1');
1689+
var positionX = dataStoreReference.x;
1690+
1691+
bpmnReplace.replaceElement(dataStoreReference, { type: 'bpmn:DataObjectReference' });
1692+
1693+
// when
1694+
commandStack.undo();
1695+
1696+
// then
1697+
expect(elementRegistry.get('DataStoreReference_1').x).to.eql(positionX);
1698+
}));
1699+
1700+
1701+
it('should redo', inject(function(bpmnReplace, commandStack, elementRegistry) {
1702+
1703+
// given
1704+
var dataStoreReference = elementRegistry.get('DataStoreReference_1');
1705+
var positionX = dataStoreReference.x;
1706+
1707+
bpmnReplace.replaceElement(dataStoreReference, { type: 'bpmn:DataObjectReference' });
1708+
commandStack.undo();
1709+
1710+
// when
1711+
commandStack.redo();
1712+
1713+
var dataObjectReference = elementRegistry.get('DataStoreReference_1');
1714+
var newPositionX = positionX + (dataStoreReference.width - dataObjectReference.width) / 2;
1715+
1716+
// then
1717+
expect(dataObjectReference.x).to.eql(newPositionX);
1718+
}));
1719+
1720+
});
1721+
1722+
1723+
describe('data object reference to data store reference', function() {
1724+
1725+
it('should center on replace', inject(function(bpmnReplace, elementRegistry) {
1726+
1727+
// given
1728+
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
1729+
var positionX = dataObjectReference.x;
1730+
1731+
// when
1732+
bpmnReplace.replaceElement(dataObjectReference, { type: 'bpmn:DataStoreReference' });
1733+
1734+
var dataStoreReference = elementRegistry.get('DataObjectReference_1');
1735+
var newPositionX = positionX + (dataObjectReference.width - dataStoreReference.width) / 2;
1736+
1737+
// then
1738+
expect(dataStoreReference.x).to.eql(newPositionX);
1739+
}));
1740+
1741+
1742+
it('should undo', inject(function(bpmnReplace, commandStack, elementRegistry) {
1743+
1744+
// given
1745+
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
1746+
var positionX = dataObjectReference.x;
1747+
1748+
bpmnReplace.replaceElement(dataObjectReference, { type: 'bpmn:DataStoreReference' });
1749+
1750+
// when
1751+
commandStack.undo();
1752+
1753+
// then
1754+
expect(elementRegistry.get('DataObjectReference_1').x).to.eql(positionX);
1755+
}));
1756+
1757+
1758+
it('should redo', inject(function(bpmnReplace, commandStack, elementRegistry) {
1759+
1760+
// given
1761+
var dataObjectReference = elementRegistry.get('DataObjectReference_1');
1762+
var positionX = dataObjectReference.x;
1763+
1764+
bpmnReplace.replaceElement(dataObjectReference, { type: 'bpmn:DataStoreReference' });
1765+
commandStack.undo();
1766+
1767+
// when
1768+
commandStack.redo();
1769+
1770+
var dataStoreReference = elementRegistry.get('DataObjectReference_1');
1771+
var newPositionX = positionX + (dataObjectReference.width - dataStoreReference.width) / 2;
1772+
1773+
// then
1774+
expect(dataStoreReference.x).to.eql(newPositionX);
1775+
}));
1776+
1777+
});
1778+
1779+
});
1780+
16511781
});
16521782

16531783

0 commit comments

Comments
 (0)