From 6a1ae97cbc5e6abd207130fecb355584630613a0 Mon Sep 17 00:00:00 2001 From: Alexis Zeghers <42282939+AZeghers@users.noreply.github.com> Date: Wed, 18 Nov 2020 11:39:01 +0100 Subject: [PATCH] feat(replace): add switch between DataStore and DataObject in replace menu Closes #1372 --- .../popup-menu/ReplaceMenuProvider.js | 8 +++++++ lib/features/replace/BpmnReplace.js | 7 ++++++ lib/features/replace/ReplaceOptions.js | 22 +++++++++++++++++++ lib/util/DiUtil.js | 2 +- .../context-pad/ContextPadProviderSpec.js | 6 ++--- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/features/popup-menu/ReplaceMenuProvider.js b/lib/features/popup-menu/ReplaceMenuProvider.js index 0ce22c602a..45fd6e5d90 100644 --- a/lib/features/popup-menu/ReplaceMenuProvider.js +++ b/lib/features/popup-menu/ReplaceMenuProvider.js @@ -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')) { diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js index 5547d46789..2860ec9a97 100644 --- a/lib/features/replace/BpmnReplace.js +++ b/lib/features/replace/BpmnReplace.js @@ -84,6 +84,7 @@ export default function BpmnReplace( moddleCopy, modeling, replace, + rules, selection ) { @@ -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 @@ -273,6 +279,7 @@ BpmnReplace.$inject = [ 'moddleCopy', 'modeling', 'replace', + 'rules', 'selection' ]; diff --git a/lib/features/replace/ReplaceOptions.js b/lib/features/replace/ReplaceOptions.js index b132368e46..d49e9b6900 100644 --- a/lib/features/replace/ReplaceOptions.js +++ b/lib/features/replace/ReplaceOptions.js @@ -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', diff --git a/lib/util/DiUtil.js b/lib/util/DiUtil.js index 91c4e5a12a..119cb54dfa 100644 --- a/lib/util/DiUtil.js +++ b/lib/util/DiUtil.js @@ -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; } if (is(element, 'bpmn:Participant')) { diff --git a/test/spec/features/context-pad/ContextPadProviderSpec.js b/test/spec/features/context-pad/ContextPadProviderSpec.js index bd6159fbbf..adfb580425 100644 --- a/test/spec/features/context-pad/ContextPadProviderSpec.js +++ b/test/spec/features/context-pad/ContextPadProviderSpec.js @@ -265,7 +265,7 @@ describe('features - context-pad', function() { expectContextPadEntries('DataStoreReference', [ 'connect', 'append.text-annotation', - '!replace', + 'replace', '!append.end-event' ]); })); @@ -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 });