Skip to content

Commit 2aef21e

Browse files
marstammbarmac
authored andcommitted
feat(FEEL): use moddle element to filter for variables
related to camunda/camunda-modeler#3510
1 parent adc2986 commit 2aef21e

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/provider/HOCs/withVariableContext.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ import { getVariablesForElement } from '@bpmn-io/extract-process-variables/zeebe
22
import { useEffect, useState } from '@bpmn-io/properties-panel/preact/hooks';
33
import { useService } from '../../hooks';
44

5-
function useServiceIfAvailable(service, fallback) {
6-
const resolved = useService(service, false);
7-
8-
if (!resolved) {
9-
return fallback;
10-
}
11-
12-
return resolved;
13-
}
5+
const fallbackResolver = {
6+
getVariablesForElement: bo => getVariablesForElement(bo)
7+
};
148

159
export function withVariableContext(Component) {
1610
return props => {
@@ -21,12 +15,12 @@ export function withVariableContext(Component) {
2115
const [ variables, setVariables ] = useState([]);
2216
const eventBus = useService('eventBus');
2317

24-
const variableResolver = useServiceIfAvailable('variableResolver', { getVariablesForElement });
18+
const variableResolver = useServiceIfAvailable('variableResolver', fallbackResolver);
2519

2620
useEffect(() => {
2721
const extractVariables = async () => {
2822

29-
const variables = await variableResolver.getVariablesForElement(bo);
23+
const variables = await variableResolver.getVariablesForElement(bo, element);
3024

3125
setVariables(variables.map(variable => {
3226
return {
@@ -53,4 +47,16 @@ export function withVariableContext(Component) {
5347

5448
return <Component { ...props } variables={ variables }></Component>;
5549
};
56-
}
50+
}
51+
52+
// helpers //////////
53+
54+
function useServiceIfAvailable(service, fallback) {
55+
const resolved = useService(service, false);
56+
57+
if (!resolved) {
58+
return fallback;
59+
}
60+
61+
return resolved;
62+
}

test/spec/provider/HOCs/withVariableContext.bpmn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_17tkbpr" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.0.0">
2+
<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:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_17tkbpr" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.16.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.0.0">
33
<bpmn:process id="Process_1i2l690" isExecutable="true">
44
<bpmn:serviceTask id="Task_2">
55
<bpmn:extensionElements>
66
<zeebe:ioMapping>
7-
<zeebe:output source="= source" target="OutputVariable_0svilsd" />
7+
<zeebe:input source="" target="InputVariable_1" />
8+
<zeebe:output source="" target="OutputVariable_1" />
89
</zeebe:ioMapping>
910
</bpmn:extensionElements>
1011
</bpmn:serviceTask>

test/spec/provider/HOCs/withVariableContext.spec.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('HOCs - withVariableContext.js', function() {
7676
expect(mockComponent).to.have.been.calledWith(
7777
matchesVariables([
7878
{
79-
name: 'OutputVariable_0svilsd',
79+
name: 'OutputVariable_1',
8080
info: 'Written in Task_2'
8181
}
8282
])
@@ -111,7 +111,11 @@ describe('HOCs - withVariableContext.js', function() {
111111
expect(mockComponent).to.have.been.calledWith(
112112
matchesVariables([
113113
{
114-
name: 'OutputVariable_0svilsd',
114+
name: 'InputVariable_1',
115+
info: 'Written in Task_2'
116+
},
117+
{
118+
name: 'OutputVariable_1',
115119
info: 'Written in Task_2'
116120
}
117121
])
@@ -160,6 +164,10 @@ describe('HOCs - withVariableContext.js', function() {
160164
await waitFor(() => {
161165
expect(mockComponent.lastCall).to.have.been.calledWith(
162166
matchesVariables([
167+
{
168+
name: 'InputVariable_1',
169+
info: 'Written in Task_2'
170+
},
163171
{
164172
name: 'newVariable',
165173
info: 'Written in Task_2'
@@ -234,7 +242,7 @@ describe('HOCs - withVariableContext.js', function() {
234242
expect(mockComponent).to.have.been.calledWith(
235243
matchesVariables([
236244
{
237-
name: 'OutputVariable_0svilsd',
245+
name: 'OutputVariable_1',
238246
info: 'Written in Task_2'
239247
},
240248
{
@@ -248,7 +256,7 @@ describe('HOCs - withVariableContext.js', function() {
248256
}));
249257

250258

251-
it('should supply variables to extension element', inject(async function(elementRegistry, injector) {
259+
it('should supply and filter variables to extension element', inject(async function(elementRegistry, injector) {
252260

253261
// given
254262
const mockComponent = sinon.spy();
@@ -274,7 +282,7 @@ describe('HOCs - withVariableContext.js', function() {
274282
expect(mockComponent).to.have.been.calledWith(
275283
matchesVariables([
276284
{
277-
name: 'OutputVariable_0svilsd',
285+
name: 'InputVariable_1',
278286
info: 'Written in Task_2'
279287
},
280288
{
@@ -311,7 +319,7 @@ describe('HOCs - withVariableContext.js', function() {
311319
container
312320
});
313321

314-
const ioMapping = ioMappings.outputParameters[0];
322+
const ioMapping = ioMappings.inputParameters[0];
315323

316324
// when
317325
await act(() => {

0 commit comments

Comments
 (0)