Skip to content

Commit d9e03d4

Browse files
Skaiirphilippfromme
authored andcommitted
feat: enable editing of zeebe:priorityDefinition
Closes #1069
1 parent 8d59ba0 commit d9e03d4

File tree

6 files changed

+448
-1
lines changed

6 files changed

+448
-1
lines changed

src/contextProvider/zeebe/TooltipProvider.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ const TooltipProvider = {
295295
</p>
296296
</div>
297297
);
298+
},
299+
'priorityDefinitionPriority': (element) => {
300+
301+
const translate = useService('translate');
302+
303+
return (
304+
<div>
305+
<p>{ translate('An integer value that can range from 0 to 100, where a higher value indicates a higher priority.') }</p>
306+
<p>{ translate('If unset, the default value is 50.') }</p>
307+
</div>
308+
);
298309
}
299310
};
300311

src/provider/zeebe/ZeebePropertiesProvider.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
MultiInstanceProps,
1717
OutputPropagationProps,
1818
OutputProps,
19+
PriorityDefinitionProps,
1920
ScriptImplementationProps,
2021
ScriptProps,
2122
SignalProps,
@@ -293,7 +294,8 @@ function AssignmentDefinitionGroup(element, injector) {
293294
label: translate('Assignment'),
294295
entries: [
295296
...AssignmentDefinitionProps({ element }),
296-
...TaskScheduleProps({ element })
297+
...TaskScheduleProps({ element }),
298+
...PriorityDefinitionProps({ element })
297299
],
298300
component: Group
299301
};
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import {
2+
getBusinessObject,
3+
is
4+
} from 'bpmn-js/lib/util/ModelUtil';
5+
6+
import { isFeelEntryEdited } from '@bpmn-io/properties-panel';
7+
8+
import {
9+
getExtensionElementsList
10+
} from '../../../utils/ExtensionElementsUtil';
11+
12+
import {
13+
createElement
14+
} from '../../../utils/ElementUtil';
15+
16+
import {
17+
useService
18+
} from '../../../hooks';
19+
20+
import { FeelEntryWithVariableContext } from '../../../entries/FeelEntryWithContext';
21+
22+
23+
export function PriorityDefinitionProps(props) {
24+
const {
25+
element
26+
} = props;
27+
28+
if (!is(element, 'bpmn:UserTask')) {
29+
return [];
30+
}
31+
32+
return [
33+
{
34+
id: 'priorityDefinitionPriority',
35+
component: Priority,
36+
isEdited: isFeelEntryEdited
37+
}
38+
];
39+
}
40+
41+
function Priority(props) {
42+
const {
43+
element
44+
} = props;
45+
46+
const commandStack = useService('commandStack');
47+
const bpmnFactory = useService('bpmnFactory');
48+
const translate = useService('translate');
49+
const debounce = useService('debounceInput');
50+
51+
const getValue = () => {
52+
return (getPriorityDefinition(element) || {}).priority;
53+
};
54+
55+
const setValue = (value) => {
56+
const commands = [];
57+
58+
const businessObject = getBusinessObject(element);
59+
60+
let extensionElements = businessObject.get('extensionElements');
61+
62+
// (1) ensure extension elements
63+
if (!extensionElements) {
64+
extensionElements = createElement(
65+
'bpmn:ExtensionElements',
66+
{ values: [] },
67+
businessObject,
68+
bpmnFactory
69+
);
70+
71+
commands.push({
72+
cmd: 'element.updateModdleProperties',
73+
context: {
74+
element,
75+
moddleElement: businessObject,
76+
properties: { extensionElements }
77+
}
78+
});
79+
}
80+
81+
// (2) ensure PriorityDefinition
82+
let priorityDefinition = getPriorityDefinition(element);
83+
const isNullValue = value === null || value === '' || value === undefined;
84+
85+
if (priorityDefinition && isNullValue) {
86+
87+
// (3a) remove priority definition if it exists and priority is set to null
88+
commands.push({
89+
cmd: 'element.updateModdleProperties',
90+
context: {
91+
element,
92+
moddleElement: extensionElements,
93+
properties: {
94+
values: extensionElements.get('values').filter(v => v !== priorityDefinition)
95+
}
96+
}
97+
});
98+
99+
} else if (priorityDefinition && !isNullValue) {
100+
101+
// (3b) update priority definition if it already exists
102+
commands.push({
103+
cmd: 'element.updateModdleProperties',
104+
context: {
105+
element,
106+
moddleElement: priorityDefinition,
107+
properties: { priority: value }
108+
}
109+
});
110+
111+
} else if (!priorityDefinition && !isNullValue) {
112+
113+
// (3c) create priority definition if it does not exist
114+
priorityDefinition = createElement(
115+
'zeebe:PriorityDefinition',
116+
{ priority: value },
117+
extensionElements,
118+
bpmnFactory
119+
);
120+
121+
commands.push({
122+
cmd: 'element.updateModdleProperties',
123+
context: {
124+
element,
125+
moddleElement: extensionElements,
126+
properties: {
127+
values: [ ...extensionElements.get('values'), priorityDefinition ]
128+
}
129+
}
130+
});
131+
}
132+
133+
// (4) commit all updates
134+
commandStack.execute('properties-panel.multi-command-executor', commands);
135+
};
136+
137+
return FeelEntryWithVariableContext({
138+
element,
139+
id: 'priorityDefinitionPriority',
140+
label: translate('Priority'),
141+
feel: 'optional',
142+
getValue,
143+
setValue,
144+
debounce
145+
});
146+
}
147+
148+
149+
// helper ///////////////////////
150+
151+
export function getPriorityDefinition(element) {
152+
const businessObject = getBusinessObject(element);
153+
154+
return getExtensionElementsList(businessObject, 'zeebe:PriorityDefinition')[0];
155+
}

src/provider/zeebe/properties/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export { MessageProps } from './MessageProps';
1313
export { MultiInstanceProps } from './MultiInstanceProps';
1414
export { OutputPropagationProps } from './OutputPropagationProps';
1515
export { OutputProps } from './OutputProps';
16+
export { PriorityDefinitionProps } from './PriorityDefinitionProps';
1617
export { ScriptImplementationProps } from './ScriptImplementationProps';
1718
export { ScriptProps } from './ScriptProps';
1819
export { SignalProps } from './SignalProps';
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?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:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0sp2msp" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.8.0-rc.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
3+
<bpmn:process id="Process_08jq0zy" isExecutable="true">
4+
<bpmn:serviceTask id="ServiceTask_1" name="ServiceTask_1" />
5+
<bpmn:userTask id="UserTask_1" name="UserTask_1">
6+
<bpmn:extensionElements>
7+
<zeebe:PriorityDefinition priority="=myPriorityValue" />
8+
</bpmn:extensionElements>
9+
</bpmn:userTask>
10+
<bpmn:userTask id="UserTask_2" name="UserTask_2" />
11+
<bpmn:userTask id="UserTask_3" name="UserTask_3">
12+
<bpmn:extensionElements>
13+
<zeebe:assignmentDefinition assignee="foo" />
14+
</bpmn:extensionElements>
15+
</bpmn:userTask>
16+
<bpmn:userTask id="UserTask_4" name="UserTask_4">
17+
<bpmn:extensionElements>
18+
<zeebe:PriorityDefinition priority="=myPriorityValue" />
19+
</bpmn:extensionElements>
20+
</bpmn:userTask>
21+
</bpmn:process>
22+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
23+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_08jq0zy">
24+
<bpmndi:BPMNShape id="Activity_1c08csw_di" bpmnElement="ServiceTask_1">
25+
<dc:Bounds x="160" y="80" width="100" height="80" />
26+
<bpmndi:BPMNLabel />
27+
</bpmndi:BPMNShape>
28+
<bpmndi:BPMNShape id="Activity_0618037_di" bpmnElement="UserTask_1">
29+
<dc:Bounds x="280" y="80" width="100" height="80" />
30+
<bpmndi:BPMNLabel />
31+
</bpmndi:BPMNShape>
32+
<bpmndi:BPMNShape id="Activity_13kad5p_di" bpmnElement="UserTask_2">
33+
<dc:Bounds x="400" y="80" width="100" height="80" />
34+
<bpmndi:BPMNLabel />
35+
</bpmndi:BPMNShape>
36+
<bpmndi:BPMNShape id="Activity_1puoc3v_di" bpmnElement="UserTask_3">
37+
<dc:Bounds x="520" y="80" width="100" height="80" />
38+
<bpmndi:BPMNLabel />
39+
</bpmndi:BPMNShape>
40+
<bpmndi:BPMNShape id="Activity_0zxgguv_di" bpmnElement="UserTask_4">
41+
<dc:Bounds x="280" y="180" width="100" height="80" />
42+
<bpmndi:BPMNLabel />
43+
</bpmndi:BPMNShape>
44+
</bpmndi:BPMNPlane>
45+
</bpmndi:BPMNDiagram>
46+
</bpmn:definitions>

0 commit comments

Comments
 (0)