Skip to content

Commit

Permalink
feat(replace): add switch between DataStore and DataObject in replace…
Browse files Browse the repository at this point in the history
… menu

Closes #1372
  • Loading branch information
azeghers committed Nov 18, 2020
1 parent 4b46f69 commit 7583d55
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/features/popup-menu/ReplaceMenuProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ ReplaceMenuProvider.prototype.getEntries = function(element) {

var differentType = isDifferentType(element);

if (is(businessObject, 'bpmn:DataObjectReference')) {
return this._createEntries(element, replaceOptions.DATA_OBJECT_REFERENCE);
}

if (is(businessObject, 'bpmn:DataStoreReference')) {
return this._createEntries(element, replaceOptions.DATA_STORE_REFERENCE);
}

// start events outside sub processes
if (is(businessObject, 'bpmn:StartEvent') && !is(businessObject.$parent, 'bpmn:SubProcess')) {

Expand Down
7 changes: 7 additions & 0 deletions lib/features/replace/BpmnReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function BpmnReplace(
moddleCopy,
modeling,
replace,
rules,
selection
) {

Expand Down Expand Up @@ -221,6 +222,11 @@ export default function BpmnReplace(
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
}

if (!rules.allowed('shape.resize', { shape: newBusinessObject })) {
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
newElement.width = elementFactory._getDefaultSize(newBusinessObject).width;
}

newBusinessObject.name = oldBusinessObject.name;

// retain default flow's reference between inclusive <-> exclusive gateways and activities
Expand Down Expand Up @@ -273,6 +279,7 @@ BpmnReplace.$inject = [
'moddleCopy',
'modeling',
'replace',
'rules',
'selection'
];

Expand Down
22 changes: 22 additions & 0 deletions lib/features/replace/ReplaceOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,28 @@ export var TASK = [
}
];

export var DATA_OBJECT_REFERENCE = [
{
label: 'Data Store Reference',
actionName: 'replace-with-data-store-reference',
className: 'bpmn-icon-data-store',
target: {
type: 'bpmn:DataStoreReference'
}
}
];

export var DATA_STORE_REFERENCE = [
{
label: 'Data Object Reference',
actionName: 'replace-with-data-object-reference',
className: 'bpmn-icon-data-object',
target: {
type: 'bpmn:DataObjectReference'
}
}
];

export var BOUNDARY_EVENT = [
{
label: 'Message Boundary Event',
Expand Down
2 changes: 1 addition & 1 deletion lib/util/DiUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function isExpanded(element) {
}

if (is(element, 'bpmn:SubProcess')) {
return !!getBusinessObject(element).di.isExpanded;
return getBusinessObject(element).di && !!getBusinessObject(element).di.isExpanded;

This comment has been minimized.

Copy link
@nikku

nikku Nov 19, 2020

Member

What is the use-case for this one?

This comment has been minimized.

Copy link
@philippfromme

philippfromme Nov 19, 2020

Contributor

ElementFactory#_getDefaultSize will go and check the DI if the element is a subprocess. Since we've only just created a new business object there is no DI yet so that will lead to an error. Also, I don't think it's very nice for isExpanded to just error when there is no DI.

This comment has been minimized.

Copy link
@philippfromme

philippfromme Nov 19, 2020

Contributor

So for the new addition to BpmnReplace to work it is necessary. Otherwise, we'd have to opt-out of calling _getDefaultSize in the case of task to subprocess.

}

if (is(element, 'bpmn:Participant')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<bpmn:dataObjectReference id="DataObjectReference_1" dataObjectRef="DataObject" />
<bpmn:dataObject id="DataObject" />
<bpmn:dataObjectReference id="DataObjectReference_2" dataObjectRef="DataObject" />
<bpmn:dataStoreReference id="DataStoreReference_1" dataStoreRef="DataStore" />
<bpmn:dataStore id="DataStore" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process">
Expand All @@ -19,6 +21,12 @@
<dc:Bounds x="274" y="234" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="DataStoreReference_1_di" bpmnElement="DataStoreReference_1">
<dc:Bounds x="401" y="184" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="374" y="234" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
6 changes: 3 additions & 3 deletions test/spec/features/context-pad/ContextPadProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('features - context-pad', function() {
expectContextPadEntries('DataStoreReference', [
'connect',
'append.text-annotation',
'!replace',
'replace',
'!append.end-event'
]);
}));
Expand Down Expand Up @@ -489,11 +489,11 @@ describe('features - context-pad', function() {

// given
var rootShape = canvas.getRootElement(),
dataStore = elementFactory.createShape({ type: 'bpmn:DataStoreReference' }),
group = elementFactory.createShape({ type: 'bpmn:Group' }),
replaceMenu;

// when
create.start(canvasEvent({ x: 0, y: 0 }), dataStore);
create.start(canvasEvent({ x: 0, y: 0 }), group);

dragging.move(canvasEvent({ x: 50, y: 50 }));
dragging.hover({ element: rootShape });
Expand Down
49 changes: 47 additions & 2 deletions test/spec/features/popup-menu/ReplaceMenuProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('features/popup-menu - replace menu provider', function() {

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

var testModules = [
coreModule,
Expand All @@ -50,9 +50,10 @@ describe('features/popup-menu - replace menu provider', function() {
});
};


describe('data object - collection marker', function() {

beforeEach(bootstrapModeler(diagramXMLDataObject, { modules: testModules }));
beforeEach(bootstrapModeler(diagramXMLDataElements, { modules: testModules }));


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


describe('data object', function() {

beforeEach(bootstrapModeler(diagramXMLDataElements, { modules: testModules }));


it('should only contain data store reference', inject(function(elementRegistry) {

// given
var dataObjectReference = elementRegistry.get('DataObjectReference_1');

// when
openPopup(dataObjectReference);

// then
expect(queryEntries()).to.have.length(2);
expect(queryEntry('toggle-is-collection')).to.exist;
expect(queryEntry('replace-with-data-store-reference')).to.exist;
expect(queryEntry('replace-with-data-object-reference')).to.be.null;
}));
});


describe('data store', function() {

beforeEach(bootstrapModeler(diagramXMLDataElements, { modules: testModules }));


it('should only contain data object reference', inject(function(elementRegistry) {

// given
var dataStoreReference = elementRegistry.get('DataStoreReference_1');

// when
openPopup(dataStoreReference);

// then
expect(queryEntries()).to.have.length(1);
expect(queryEntry('toggle-is-collection')).to.be.null;
expect(queryEntry('replace-with-data-store-reference')).to.be.null;
expect(queryEntry('replace-with-data-object-reference')).to.exist;
}));

});

});


Expand Down

0 comments on commit 7583d55

Please sign in to comment.