-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable editing of
zeebe:priorityDefinition
Closes #1069
- Loading branch information
Showing
5 changed files
with
462 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
src/provider/zeebe/properties/PriorityDefinitionProps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
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 || '50'; | ||
}; | ||
|
||
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); | ||
}; | ||
|
||
const tooltip = `<div> | ||
<p>An integer value that defines the priority of a User Task. It can be set as an expression.</p> | ||
<p>The priority can range from 0 to 100, with a default value of 50.</p> | ||
<p>A higher value indicates a higher priority.</p> | ||
<p><a href="#">Read more about it here.</a></p> | ||
</div>`; | ||
|
||
return FeelEntryWithVariableContext({ | ||
element, | ||
id: 'priorityDefinitionPriority', | ||
label: translate('Priority'), | ||
feel: 'optional', | ||
tooltip, | ||
getValue, | ||
setValue, | ||
debounce | ||
}); | ||
} | ||
|
||
|
||
// helper /////////////////////// | ||
|
||
export function getPriorityDefinition(element) { | ||
const businessObject = getBusinessObject(element); | ||
|
||
return getExtensionElementsList(businessObject, 'zeebe:PriorityDefinition')[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.