Skip to content

Commit

Permalink
feat: handle default flow
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Feb 5, 2022
1 parent 8141b93 commit f97594c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
20 changes: 11 additions & 9 deletions lib/features/context-pads/handler/InclusiveGatewayHandler.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import {
is
} from '../../../util/ElementHelper';

import {
ForkIcon
} from '../../../icons';

import { getBusinessObject } from '../../../util/ElementHelper';
import { isSequenceFlow } from '../../../simulator/util/ModelUtil';

export default function InclusiveGatewayHandler(inclusiveGatewaySettings) {
this._inclusiveGatewaySettings = inclusiveGatewaySettings;
}

InclusiveGatewayHandler.prototype.createContextPads = function(element) {

const outgoingFlows = element.outgoing.filter(function(outgoing) {
return is(outgoing, 'bpmn:SequenceFlow');
});
const outgoingFlows = element.outgoing.filter(isSequenceFlow);

if (outgoingFlows.length < 2) {
return;
}

const nonDefaultFlows = outgoingFlows.filter(outgoing => {
const flowBo = getBusinessObject(outgoing),
gatewayBo = getBusinessObject(element);

Check warning on line 21 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L19-L21

Added lines #L19 - L21 were not covered by tests

return gatewayBo.default !== flowBo;

Check warning on line 23 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L23

Added line #L23 was not covered by tests
});

const html = `

Check warning on line 26 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L26

Added line #L26 was not covered by tests
<div class="bts-context-pad" title="Set Sequence Flow">
${ForkIcon()}
</div>
`;

return outgoingFlows.map(sequenceFlow => {
return nonDefaultFlows.map(sequenceFlow => {
const action = () => {
this._inclusiveGatewaySettings.toggleSequenceFlow(element, sequenceFlow);

Check warning on line 34 in lib/features/context-pads/handler/InclusiveGatewayHandler.js

View check run for this annotation

Codecov / codecov/patch

lib/features/context-pads/handler/InclusiveGatewayHandler.js#L32-L34

Added lines #L32 - L34 were not covered by tests
};
Expand Down
46 changes: 35 additions & 11 deletions lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
is
} from '../../util/ElementHelper';

import {
TOGGLE_MODE_EVENT
} from '../../util/EventHelper';
Expand All @@ -10,9 +6,11 @@ import {
const SELECTED_COLOR = '--token-simulation-grey-darken-30';
const NOT_SELECTED_COLOR = '--token-simulation-grey-lighten-56';

function isSequenceFlow(connection) {
return is(connection, 'bpmn:SequenceFlow');
}
import {
getBusinessObject,
is,
isSequenceFlow
} from '../../simulator/util/ModelUtil';


export default function InclusiveGatewaySettings(
Expand Down Expand Up @@ -58,13 +56,18 @@ InclusiveGatewaySettings.prototype.reset = function() {
};

InclusiveGatewaySettings.prototype.toggleSequenceFlow = function(gateway, sequenceFlow) {
const activeOutgoing = this._getActiveOutgoing(gateway);
const activeOutgoing = this._getActiveOutgoing(gateway),
defaultFlow = getDefaultFlow(gateway);

Check warning on line 60 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L59-L60

Added lines #L59 - L60 were not covered by tests

let newActiveOutgoing;
if (activeOutgoing.includes(sequenceFlow)) {
newActiveOutgoing = activeOutgoing.filter(outgoing => outgoing !== sequenceFlow);
newActiveOutgoing = without(activeOutgoing, sequenceFlow);

Check warning on line 64 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L63-L64

Added lines #L63 - L64 were not covered by tests
} else {
newActiveOutgoing = activeOutgoing.concat(sequenceFlow);
newActiveOutgoing = without(activeOutgoing, defaultFlow).concat(sequenceFlow);

Check warning on line 66 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L66

Added line #L66 was not covered by tests
}

if (!newActiveOutgoing.length && defaultFlow) {
return this._setActiveOutgoing(gateway, [ defaultFlow ]);

Check warning on line 70 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L69-L70

Added lines #L69 - L70 were not covered by tests
}

this._setActiveOutgoing(gateway, newActiveOutgoing);

Check warning on line 73 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L73

Added line #L73 was not covered by tests
Expand Down Expand Up @@ -99,7 +102,10 @@ InclusiveGatewaySettings.prototype._setActiveOutgoing = function(gateway, active
InclusiveGatewaySettings.prototype._setGatewayDefaults = function(gateway) {
const sequenceFlows = gateway.outgoing.filter(isSequenceFlow);

Check warning on line 103 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L103

Added line #L103 was not covered by tests

this._setActiveOutgoing(gateway, sequenceFlows);
const defaultFlow = getDefaultFlow(gateway);
const nonDefaultFlows = without(sequenceFlows, defaultFlow);

Check warning on line 106 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L105-L106

Added lines #L105 - L106 were not covered by tests

this._setActiveOutgoing(gateway, nonDefaultFlows);

Check warning on line 108 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L108

Added line #L108 was not covered by tests
};

InclusiveGatewaySettings.prototype._resetGateway = function(gateway) {
Expand All @@ -113,3 +119,21 @@ InclusiveGatewaySettings.$inject = [
'simulator',
'simulationStyles'
];

function getDefaultFlow(gateway) {
const defaultFlow = getBusinessObject(gateway).default;

Check warning on line 124 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L124

Added line #L124 was not covered by tests

if (!defaultFlow) {
return;

Check warning on line 127 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L126-L127

Added lines #L126 - L127 were not covered by tests
}

return gateway.outgoing.find(flow => {
const flowBo = getBusinessObject(flow);

Check warning on line 131 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L130-L131

Added lines #L130 - L131 were not covered by tests

return flowBo === defaultFlow;

Check warning on line 133 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L133

Added line #L133 was not covered by tests
});
}

function without(array, element) {
return array.filter(arrayElement => arrayElement !== element);

Check warning on line 138 in lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js

View check run for this annotation

Codecov / codecov/patch

lib/features/inclusive-gateway-settings/InclusiveGatewaySettings.js#L138

Added line #L138 was not covered by tests
}

0 comments on commit f97594c

Please sign in to comment.