Skip to content

Commit

Permalink
fix: only show priority assignment in zeebe:userTask
Browse files Browse the repository at this point in the history
Closes #21772
  • Loading branch information
Skaiir authored and nikku committed Sep 13, 2024
1 parent 1b23597 commit 86d8c39
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
37 changes: 12 additions & 25 deletions src/provider/zeebe/properties/PriorityDefinitionProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function PriorityDefinitionProps(props) {
element
} = props;

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

Expand Down Expand Up @@ -59,32 +59,13 @@ function Priority(props) {

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
// (1) 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
// (2a) remove priority definition if it exists and priority is set to null
commands.push({
cmd: 'element.updateModdleProperties',
context: {
Expand All @@ -98,7 +79,7 @@ function Priority(props) {

} else if (priorityDefinition && !isNullValue) {

// (3b) update priority definition if it already exists
// (2b) update priority definition if it already exists
commands.push({
cmd: 'element.updateModdleProperties',
context: {
Expand All @@ -110,7 +91,7 @@ function Priority(props) {

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

// (3c) create priority definition if it does not exist
// (2c) create priority definition if it does not exist
priorityDefinition = createElement(
'zeebe:PriorityDefinition',
{ priority: value },
Expand All @@ -130,7 +111,7 @@ function Priority(props) {
});
}

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

Expand All @@ -153,3 +134,9 @@ export function getPriorityDefinition(element) {

return getExtensionElementsList(businessObject, 'zeebe:PriorityDefinition')[0];
}

function isZeebeUserTask(element) {
const businessObject = getBusinessObject(element);

return is(element, 'bpmn:UserTask') && !!getExtensionElementsList(businessObject, 'zeebe:UserTask')[0];
}
14 changes: 11 additions & 3 deletions test/spec/provider/zeebe/PriorityDefinitionProps.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
<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_0" name="UserTask_0" />
<bpmn:userTask id="UserTask_1" name="UserTask_1">
<bpmn:extensionElements>
<zeebe:PriorityDefinition priority="=myPriorityValue" />
<zeebe:userTask />
<zeebe:priorityDefinition priority="=myPriorityValue" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="UserTask_2" name="UserTask_2">
<bpmn:extensionElements>
<zeebe:userTask />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="UserTask_2" name="UserTask_2" />
<bpmn:userTask id="UserTask_3" name="UserTask_3">
<bpmn:extensionElements>
<zeebe:userTask />
<zeebe:assignmentDefinition assignee="foo" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="UserTask_4" name="UserTask_4">
<bpmn:extensionElements>
<zeebe:PriorityDefinition priority="=myPriorityValue" />
<zeebe:userTask />
<zeebe:priorityDefinition priority="=myPriorityValue" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
Expand Down
27 changes: 23 additions & 4 deletions test/spec/provider/zeebe/PriorityDefinitionProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import zeebeModdleExtensions from 'zeebe-bpmn-moddle/resources/zeebe';

import diagramXML from './PriorityDefinitionProps.bpmn';
import { setEditorValue } from '../../../TestHelper';
import { getExtensionElementsList } from '../../../../src/utils/ExtensionElementsUtil';


describe('provider/zeebe - PriorityDefinitionProps', function() {
Expand Down Expand Up @@ -83,6 +84,23 @@ describe('provider/zeebe - PriorityDefinitionProps', function() {
}));


it('should NOT display for user task without zeebe:UserTask', inject(async function(elementRegistry, selection) {

// given
const userTask = elementRegistry.get('UserTask_0');

await act(() => {
selection.select(userTask);
});

// when
const priorityInput = domQuery('input[name=priorityDefinitionPriority]', container);

// then
expect(priorityInput).to.not.exist;
}));


it('should display for user task', inject(async function(elementRegistry, selection) {

// given
Expand Down Expand Up @@ -153,14 +171,14 @@ describe('provider/zeebe - PriorityDefinitionProps', function() {
);


it('should create non-existing extension elements and priority definition',
it('should create priority definition',
inject(async function(elementRegistry, selection) {

// given
const userTask = elementRegistry.get('UserTask_2');

// assume
expect(getBusinessObject(userTask).get('extensionElements')).to.not.exist;
expect(getExtensionElementsList(getBusinessObject(userTask), 'zeebe:priorityDefinition')).to.be.empty;

await act(() => {
selection.select(userTask);
Expand All @@ -171,7 +189,8 @@ describe('provider/zeebe - PriorityDefinitionProps', function() {
changeInput(priorityInput, 'newValue');

// then
expect(getBusinessObject(userTask).get('extensionElements')).to.exist;
const priorityDefinitionElement = getExtensionElementsList(getBusinessObject(userTask), 'zeebe:PriorityDefinition')[0];
expect(priorityDefinitionElement).to.exist;
})
);

Expand All @@ -197,7 +216,7 @@ describe('provider/zeebe - PriorityDefinitionProps', function() {
// then
const extensionElements = getBusinessObject(userTask).get('extensionElements');
expect(getPriorityDefinition(userTask).get('priority')).to.eql('newValue');
expect(extensionElements.values).to.have.length(2);
expect(extensionElements.values).to.have.length(3);
})
);

Expand Down

0 comments on commit 86d8c39

Please sign in to comment.