Skip to content

Commit

Permalink
feat: add conditional correlationKey rendering
Browse files Browse the repository at this point in the history
closes #19
  • Loading branch information
marstamm committed Nov 23, 2023
1 parent 0555608 commit 6b23145
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/cloud-element-templates/Condition.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isEventSubProcess } from 'bpmn-js/lib/util/DiUtil';
import { getPropertyValue } from './util/propertyUtil';
import { is } from 'bpmn-js/lib/util/ModelUtil';

/**
* Based on conditions, remove properties from the template.
Expand All @@ -7,7 +9,7 @@ export function applyConditions(element, elementTemplate) {
const { properties } = elementTemplate;

const filteredProperties = properties.filter(property => {
return isConditionMet(element, properties, property);
return isPropertyAllowed(element, property) && isConditionMet(element, properties, property);
});

return {
Expand Down Expand Up @@ -72,3 +74,19 @@ export function getValue(element, properties, propertyId) {

return getPropertyValue(element, property);
}

function isPropertyAllowed(element, property) {
const { binding } = property;
const { type } = binding;

if (
type === 'bpmn:Message#zeebe:subscription#property' &&
binding.name === 'correlationKey' &&
is(element, 'bpmn:StartEvent') &&
!isEventSubProcess(element.parent)
) {
return false;
}

return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export default class ElementTemplatesConditionChecker extends CommandInterceptor
], this._saveConditionalState, true, this);

this.postExecute([
'element.updateProperties', 'element.updateModdleProperties', 'propertiesPanel.zeebe.changeTemplate'
'element.updateProperties',
'element.updateModdleProperties',
'propertiesPanel.zeebe.changeTemplate',
'element.move'
], this._applyConditions, true, this);
}

Expand Down
1 change: 1 addition & 0 deletions test/spec/Example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
ZeebeBehaviorsModule,
BpmnPropertiesPanelModule,
BpmnPropertiesProviderModule,
ZeebePropertiesProviderModule,
CloudElementTemplatesPropertiesProviderModule,
ElementTemplateChooserModule,
ElementTemplatesIconsRenderer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import TestContainer from 'mocha-test-container-support';
import { act } from '@testing-library/preact';

import {
bootstrapModeler,
bootstrapPropertiesPanel,
inject
} from 'test/TestHelper';

Expand All @@ -16,14 +18,18 @@ import ZeebeBehaviorsModule from 'camunda-bpmn-js-behaviors/lib/camunda-cloud';

import diagramXML from './fixtures/condition.bpmn';
import messageDiagramXML from './fixtures/condition-message.bpmn';
import messageCorrelationDiagramXML from './fixtures/message-correlation-key.bpmn';

import template from './fixtures/condition.json';
import messageTemplates from './fixtures/condition-message.json';
import messageCorrelationTemplate from './fixtures/message-correlation-key.json';

import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';
import { findExtension, findMessage, findZeebeSubscription } from 'src/cloud-element-templates/Helper';
import ElementTemplatesConditionChecker from 'src/cloud-element-templates/ElementTemplatesConditionChecker';
import { getBpmnJS } from 'bpmn-js/test/helper';
import { isString } from 'min-dash';
import { query as domQuery } from 'min-dom';


describe('provider/cloud-element-templates - ElementTemplatesConditionChecker', function() {
Expand Down Expand Up @@ -915,6 +921,60 @@ describe('provider/cloud-element-templates - ElementTemplatesConditionChecker',
}));


describe('correlationKey visibility', function() {

beforeEach(bootstrapPropertiesPanel(messageCorrelationDiagramXML, {
container: container,
modules: [
coreModule,
elementTemplatesModule,
modelingModule,
ElementTemplatesConditionChecker,
BpmnPropertiesPanelModule,
ZeebeBehaviorsModule
],
moddleExtensions: {
zeebe: zeebeModdlePackage
}
}));

beforeEach(inject(function(elementTemplates) {
elementTemplates.set([ messageCorrelationTemplate ]);
}));


it('should show correlation key - MessageStartSubprocess', inject(async function(elementRegistry, selection) {

// given
let element = elementRegistry.get('MessageStartSubprocess');

// when
element = changeTemplate(element, messageCorrelationTemplate);
await act(() => selection.select(element));

// then
const correlationKeyEntry = domQuery('[data-entry-id="custom-entry-message-correlation-key-rendering-1"]', container);
expect(correlationKeyEntry).to.exist;
}));


it('should NOT show correlation key', inject(async function(elementRegistry, selection) {

// given
let element = elementRegistry.get('MessageStart');

// when
element = changeTemplate(element, messageCorrelationTemplate);
await act(() => selection.select(element));

// then
const correlationKeyEntry = domQuery('[data-entry-id="custom-entry-message-correlation-key-rendering-1"]', container);
expect(correlationKeyEntry).not.to.exist;
}));

});


it('should add conditional entries', inject(async function(elementRegistry) {

// given
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_165ah7c" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0-alpha.1" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.2.0">
<bpmn:process id="Process_0vvlc66" isExecutable="true">
<bpmn:subProcess id="Activity_0exjy73" triggeredByEvent="true">
<bpmn:startEvent id="MessageStartSubprocess">
<bpmn:messageEventDefinition id="MessageEventDefinition_1n4teqw" />
</bpmn:startEvent>
</bpmn:subProcess>
<bpmn:task id="Activity_1utl3n3" />
<bpmn:boundaryEvent id="MessageBoundary" attachedToRef="Activity_1utl3n3">
<bpmn:messageEventDefinition id="MessageEventDefinition_0qsg82v" />
</bpmn:boundaryEvent>
<bpmn:startEvent id="MessageStart">
<bpmn:messageEventDefinition id="MessageEventDefinition_0752swo" />
</bpmn:startEvent>
<bpmn:intermediateCatchEvent id="MessageIntermediate">
<bpmn:messageEventDefinition id="MessageEventDefinition_1yd090z" />
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0vvlc66">
<bpmndi:BPMNShape id="Event_1u99b1d_di" bpmnElement="MessageStart">
<dc:Bounds x="292" y="92" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1utl3n3_di" bpmnElement="Activity_1utl3n3">
<dc:Bounds x="510" y="70" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0t0yt4q_di" bpmnElement="MessageIntermediate">
<dc:Bounds x="392" y="92" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_01wsyz0_di" bpmnElement="Activity_0exjy73" isExpanded="true">
<dc:Bounds x="250" y="220" width="350" height="200" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_15z79dd_di" bpmnElement="MessageStartSubprocess">
<dc:Bounds x="290" y="302" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0lqa760_di" bpmnElement="MessageBoundary">
<dc:Bounds x="542" y="132" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "Message Property",
"id": "message-correlation-key-rendering",
"description": "A conditional template.",
"appliesTo": [
"bpmn:Event"
],
"elementType": {
"value": "bpmn:StartEvent",
"eventDefinition": "bpmn:MessageEventDefinition"
},
"properties": [
{
"label": "name",
"type": "Hidden",
"value": "one",
"binding": {
"type": "bpmn:Message#property",
"name": "name"
}
},
{
"label": "Correlation Key",
"id": "correlationKey",
"type": "String",
"value": "correlationKey",
"binding": {
"type": "bpmn:Message#zeebe:subscription#property",
"name": "correlationKey"
}
}
]
}

0 comments on commit 6b23145

Please sign in to comment.