Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Checks From diagram-js #1903

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/features/auto-place/BpmnAutoPlaceUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
getConnectedDistance
} from 'diagram-js/lib/features/auto-place/AutoPlaceUtil';

import { isConnection } from 'diagram-js/lib/util/ModelUtil';

/**
* @typedef {import('../../model/Types').Shape} Shape
*
Expand Down Expand Up @@ -169,8 +171,4 @@ export function getDataElementPosition(source, element) {
};

return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
}

function isConnection(element) {
return !!element.waypoints;
}
2 changes: 1 addition & 1 deletion lib/features/copy-paste/BpmnCopyPaste.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ BpmnCopyPaste.$inject = [
'bpmnFactory',
'eventBus',
'moddleCopy'
];
];
6 changes: 2 additions & 4 deletions lib/features/modeling/behavior/CreateParticipantBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {

import { asTRBL } from 'diagram-js/lib/layout/LayoutUtil';

import { isConnection } from 'diagram-js/lib/util/ModelUtil';

/**
* @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
* @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
Expand Down Expand Up @@ -229,10 +231,6 @@ function getParticipantCreateConstraints(shape, childrenBBox) {
};
}

function isConnection(element) {
return !!element.waypoints;
}

function findParticipant(elements) {
return find(elements, function(element) {
return is(element, 'bpmn:Participant');
Expand Down
6 changes: 2 additions & 4 deletions lib/features/modeling/cmd/SetColorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
isLabel
} from '../../../util/LabelUtil';

import { isConnection } from 'diagram-js/lib/util/ModelUtil';

/**
* @typedef {import('diagram-js/lib/command/CommandHandler').default} CommandHandler
*
Expand Down Expand Up @@ -144,10 +146,6 @@ function colorToHex(color) {
return /^#[0-9a-fA-F]{6}$/.test(context.fillStyle) ? context.fillStyle : null;
}

function isConnection(element) {
return !!element.waypoints;
}

/**
* Add legacy properties if required.
*
Expand Down
11 changes: 2 additions & 9 deletions lib/features/rules/BpmnRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
getBoundaryAttachment as isBoundaryAttachment
} from '../snapping/BpmnSnappingUtil';

import { isConnection } from 'diagram-js/lib/util/ModelUtil';

/**
* @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
*
Expand Down Expand Up @@ -486,15 +488,6 @@ function isEventBasedTarget(element) {
);
}

/**
* @param {Element} element
*
* @return {boolean}
*/
function isConnection(element) {
return element.waypoints;
}

/**
* @param {Element} element
*
Expand Down
13 changes: 4 additions & 9 deletions lib/util/LabelUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {

import { is } from './ModelUtil';

import { isLabel } from 'diagram-js/lib/util/ModelUtil';

export { isLabel } from 'diagram-js/lib/util/ModelUtil';

/**
* @typedef {import('diagram-js/lib/util/Types').Point} Point
* @typedef {import('diagram-js/lib/util/Types').Rect} Rect
Expand Down Expand Up @@ -170,15 +174,6 @@ export function getExternalLabelBounds(di, element) {
}, size);
}

/**
* @param {Element} element
*
* @return {boolean}
*/
export function isLabel(element) {
return element && !!element.labelTarget;
}

/**
* @param {ModdleElement} semantic
*
Expand Down
8 changes: 3 additions & 5 deletions test/spec/features/copy-paste/BpmnCopyPasteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
is
} from 'lib/util/ModelUtil';

import { isRoot } from 'diagram-js/lib/util/ModelUtil';

/**
* @typedef {import('../../../../lib/model/Types').Element} Element
*/
Expand Down Expand Up @@ -1015,7 +1017,7 @@ function integrationTest(elementIds) {
});

// (4) move all elements except root
modeling.moveElements(elementRegistry.filter(isRoot), { x: 50, y: -50 });
modeling.moveElements(elementRegistry.filter(element => !isRoot(element)), { x: 50, y: -50 });
nikku marked this conversation as resolved.
Show resolved Hide resolved

// when
// (5) undo moving, pasting and removing
Expand Down Expand Up @@ -1057,10 +1059,6 @@ function integrationTest(elementIds) {
};
}

function isRoot(element) {
return !!element.parent;
}

function getPropertyForElements(elements, property) {
return map(elements, function(element) {
return element[ property ];
Expand Down
6 changes: 3 additions & 3 deletions test/spec/features/rules/BpmnRulesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ describe('features/modeling/rules - BpmnRules', function() {
// given
var task1 = elementFactory.createShape({ type: 'bpmn:Task' }),
task2 = elementFactory.createShape({ type: 'bpmn:Task' }),
sequenceFlow = elementFactory.createConnection({
messageFlow = elementFactory.createConnection({
type: 'bpmn:MessageFlow',
source: task1,
target: task2
});

// then
expectCanCreate([ task1, task2, sequenceFlow ], 'Process', false);
expectCanCreate([ task1, task2, messageFlow ], 'Process', false);
}));


Expand Down Expand Up @@ -2157,7 +2157,7 @@ describe('features/modeling/rules - BpmnRules', function() {
it('should ignore label elements', inject(function(elementFactory, rules) {

// given
var label = elementFactory.createShape({ type: 'bpmn:FlowNode', labelTarget: {} });
var label = elementFactory.createLabel({});

// when
var result = rules.allowed('connection.start', { source: label });
Expand Down
9 changes: 9 additions & 0 deletions test/spec/features/rules/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
map
} from 'min-dash';

/**
* @typedef {import('../../../../lib/model/Types').Parent} Parent
* @typedef {import('../../../../lib/model/Types').Shape} Shape
*/

export function expectCanConnect(source, target, rules) {

Expand Down Expand Up @@ -49,6 +53,11 @@ export function expectCanDrop(element, target, expectedResult) {
}


/**
* @param {Shape|Element[]} shape Shape or array of elements to create.
* @param {Parent} target
* @param {any} expectedResult
*/
export function expectCanCreate(shape, target, expectedResult) {

var result = getBpmnJS().invoke(function(rules) {
Expand Down