chore(bpmn-replace): reorganize toggling collapsed state

This commit is contained in:
Maciej Barelkowski 2021-10-19 14:22:58 +02:00 committed by Nico Rehwaldt
parent 973ac6e35a
commit e1efb556f2
1 changed files with 11 additions and 13 deletions

View File

@ -45,8 +45,10 @@ var CUSTOM_PROPERTIES = [
'isInterrupting' 'isInterrupting'
]; ];
/**
function toggeling(element, target) { * Check if element should be collapsed or expanded.
*/
function shouldToggleCollapsed(element, targetElement) {
var oldCollapsed = ( var oldCollapsed = (
element && has(element, 'collapsed') ? element.collapsed : !isExpanded(element) element && has(element, 'collapsed') ? element.collapsed : !isExpanded(element)
@ -54,11 +56,11 @@ function toggeling(element, target) {
var targetCollapsed; var targetCollapsed;
if (target && (has(target, 'collapsed') || has(target, 'isExpanded'))) { if (targetElement && (has(targetElement, 'collapsed') || has(targetElement, 'isExpanded'))) {
// property is explicitly set so use it // property is explicitly set so use it
targetCollapsed = ( targetCollapsed = (
has(target, 'collapsed') ? target.collapsed : !target.isExpanded has(targetElement, 'collapsed') ? targetElement.collapsed : !targetElement.isExpanded
); );
} else { } else {
@ -67,7 +69,6 @@ function toggeling(element, target) {
} }
if (oldCollapsed !== targetCollapsed) { if (oldCollapsed !== targetCollapsed) {
element.collapsed = oldCollapsed;
return true; return true;
} }
@ -75,7 +76,6 @@ function toggeling(element, target) {
} }
/** /**
* This module takes care of replacing BPMN elements * This module takes care of replacing BPMN elements
*/ */
@ -106,15 +106,13 @@ export default function BpmnReplace(
var type = target.type, var type = target.type,
oldBusinessObject = element.businessObject; oldBusinessObject = element.businessObject;
if (isSubProcess(oldBusinessObject)) { if (isSubProcess(oldBusinessObject) && type === 'bpmn:SubProcess') {
if (type === 'bpmn:SubProcess') { if (shouldToggleCollapsed(element, target)) {
if (toggeling(element, target)) {
// expanding or collapsing process // expanding or collapsing process
modeling.toggleCollapse(element); modeling.toggleCollapse(element);
return element; return element;
}
} }
} }