Skip to content

Commit

Permalink
feat: enable editing of zeebe:priorityDefinition
Browse files Browse the repository at this point in the history
Closes #1069
  • Loading branch information
Skaiir committed Aug 15, 2024
1 parent 9aab764 commit 2dab16b
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/contextProvider/zeebe/TooltipProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ const TooltipProvider = {
</p>
</div>
);
},
'priorityDefinitionPriority': (element) => {

const translate = useService('translate');

return (
<div>
<p>{ translate('An integer value that can range from 0 to 100, where a higher value indicates a higher priority.') }</p>
<p>{ translate('If unset, the default value is 50.') }</p>
</div>
);
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/provider/zeebe/ZeebePropertiesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MultiInstanceProps,
OutputPropagationProps,
OutputProps,
PriorityDefinitionProps,
ScriptImplementationProps,
ScriptProps,
SignalProps,
Expand Down Expand Up @@ -293,7 +294,8 @@ function AssignmentDefinitionGroup(element, injector) {
label: translate('Assignment'),
entries: [
...AssignmentDefinitionProps({ element }),
...TaskScheduleProps({ element })
...TaskScheduleProps({ element }),
...PriorityDefinitionProps({ element })
],
component: Group
};
Expand Down
155 changes: 155 additions & 0 deletions src/provider/zeebe/properties/PriorityDefinitionProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import {
getBusinessObject,
is
} from 'bpmn-js/lib/util/ModelUtil';

import { isFeelEntryEdited } from '@bpmn-io/properties-panel';

import {
getExtensionElementsList
} from '../../../utils/ExtensionElementsUtil';

import {
createElement
} from '../../../utils/ElementUtil';

import {
useService
} from '../../../hooks';

import { FeelEntryWithVariableContext } from '../../../entries/FeelEntryWithContext';


export function PriorityDefinitionProps(props) {
const {
element
} = props;

if (!is(element, 'bpmn:UserTask')) {
return [];
}

return [
{
id: 'priorityDefinitionPriority',
component: Priority,
isEdited: isFeelEntryEdited
}
];
}

function Priority(props) {
const {
element
} = props;

const commandStack = useService('commandStack');
const bpmnFactory = useService('bpmnFactory');
const translate = useService('translate');
const debounce = useService('debounceInput');

const getValue = () => {
return (getPriorityDefinition(element) || {}).priority;
};

const setValue = (value) => {
const commands = [];

const businessObject = getBusinessObject(element);

let extensionElements = businessObject.get('extensionElements');

// (1) ensure extension elements
if (!extensionElements) {
extensionElements = createElement(
'bpmn:ExtensionElements',
{ values: [] },
businessObject,
bpmnFactory
);

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: businessObject,
properties: { extensionElements }
}
});
}

// (2) ensure PriorityDefinition
let priorityDefinition = getPriorityDefinition(element);
const isNullValue = value === null || value === '' || value === undefined;

if (priorityDefinition && isNullValue) {

// (3a) remove priority definition if it exists and priority is set to null
commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: extensionElements,
properties: {
values: extensionElements.get('values').filter(v => v !== priorityDefinition)
}
}
});

} else if (priorityDefinition && !isNullValue) {

// (3b) update priority definition if it already exists
commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: priorityDefinition,
properties: { priority: value }
}
});

} else if (!priorityDefinition && !isNullValue) {

// (3c) create priority definition if it does not exist
priorityDefinition = createElement(
'zeebe:PriorityDefinition',
{ priority: value },
extensionElements,
bpmnFactory
);

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: extensionElements,
properties: {
values: [ ...extensionElements.get('values'), priorityDefinition ]
}
}
});
}

// (4) commit all updates
commandStack.execute('properties-panel.multi-command-executor', commands);
};

return FeelEntryWithVariableContext({
element,
id: 'priorityDefinitionPriority',
label: translate('Priority'),
feel: 'optional',
getValue,
setValue,
debounce
});
}


// helper ///////////////////////

export function getPriorityDefinition(element) {
const businessObject = getBusinessObject(element);

return getExtensionElementsList(businessObject, 'zeebe:PriorityDefinition')[0];
}
1 change: 1 addition & 0 deletions src/provider/zeebe/properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { MessageProps } from './MessageProps';
export { MultiInstanceProps } from './MultiInstanceProps';
export { OutputPropagationProps } from './OutputPropagationProps';
export { OutputProps } from './OutputProps';
export { PriorityDefinitionProps } from './PriorityDefinitionProps';
export { ScriptImplementationProps } from './ScriptImplementationProps';
export { ScriptProps } from './ScriptProps';
export { SignalProps } from './SignalProps';
Expand Down
46 changes: 46 additions & 0 deletions test/spec/provider/zeebe/PriorityDefinitionProps.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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_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">
<bpmn:process id="Process_08jq0zy" isExecutable="true">
<bpmn:serviceTask id="ServiceTask_1" name="ServiceTask_1" />
<bpmn:userTask id="UserTask_1" name="UserTask_1">
<bpmn:extensionElements>
<zeebe:PriorityDefinition priority="=myPriorityValue" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="UserTask_2" name="UserTask_2" />
<bpmn:userTask id="UserTask_3" name="UserTask_3">
<bpmn:extensionElements>
<zeebe:assignmentDefinition assignee="foo" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="UserTask_4" name="UserTask_4">
<bpmn:extensionElements>
<zeebe:PriorityDefinition priority="=myPriorityValue" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_08jq0zy">
<bpmndi:BPMNShape id="Activity_1c08csw_di" bpmnElement="ServiceTask_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0618037_di" bpmnElement="UserTask_1">
<dc:Bounds x="280" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_13kad5p_di" bpmnElement="UserTask_2">
<dc:Bounds x="400" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1puoc3v_di" bpmnElement="UserTask_3">
<dc:Bounds x="520" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0zxgguv_di" bpmnElement="UserTask_4">
<dc:Bounds x="280" y="180" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading

0 comments on commit 2dab16b

Please sign in to comment.