Skip to content

Commit

Permalink
feat: support execution listeners in properties panel
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Jul 30, 2024
1 parent 3014907 commit 3bdcfc8
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,22 @@ export function getEntryIds(report) {
return [ 'waitForCompletion' ];
}

if (isPropertyError(data, 'type', 'zeebe:ExecutionListener')) {
const index = path[ path.length - 2 ];

return [ `${id}-executionListener-${index}-listenerType` ];
}

if (isPropertyValuesDuplicatedError(data, 'zeebe:ExecutionListeners')) {
const { properties, propertiesName } = data;

return properties.map(property => {
const index = data.node.get(propertiesName).indexOf(property);

return `${ id }-executionListener-${ index }-listenerType`;
});
}

return [];
}

Expand Down Expand Up @@ -528,6 +544,14 @@ export function getErrorMessage(id, report) {
if (id === 'waitForCompletion') {
return 'Must wait for completion.';
}

if (/^.+-executionListener-[0-9]+-listenerType$/.test(id)) {
if (type === ERROR_TYPES.PROPERTY_VALUES_DUPLICATED) {
return 'Must be unique.';
} else {
return 'Must be defined.';
}
}
}

function isExtensionElementNotAllowedError(data, extensionElement, type) {
Expand Down Expand Up @@ -580,6 +604,11 @@ function isPropertyValueDuplicatedError(data, propertiesName, duplicatedProperty
&& (!type || is(data.node, type));
}

function isPropertyValuesDuplicatedError(data, type) {
return data.type === ERROR_TYPES.PROPERTY_VALUES_DUPLICATED
&& (!type || is(data.node, type));
}

function isExpressionRequiredError(data, propertyName, type) {
return data.type === ERROR_TYPES.EXPRESSION_REQUIRED
&& data.property === propertyName
Expand Down
78 changes: 78 additions & 0 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,84 @@ describe('utils/properties-panel', function() {

expectErrorMessage(entryIds[ 0 ], 'Must wait for completion.', report);
});


describe('execution listener', async function() {

it('should mark type as required', async function() {

// given
const node = createElement('bpmn:ServiceTask', {
id: 'ServiceTask_1',
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:ExecutionListeners', {
listeners: [
createElement('zeebe:ExecutionListener', {
eventType: 'start'
})
]
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/execution-listener');

const report = await getLintError(node, rule);

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'ServiceTask_1-executionListener-0-listenerType' ]);

expectErrorMessage(entryIds[ 0 ], 'Must be defined.', report);
});


it('duplicated', async function() {

// given
const node = createElement('bpmn:ServiceTask', {
id: 'ServiceTask_1',
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:ExecutionListeners', {
listeners: [
createElement('zeebe:ExecutionListener', {
eventType: 'start',
type: 'foo'
}),
createElement('zeebe:ExecutionListener', {
eventType: 'start',
type: 'foo'
})
]
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/duplicate-execution-listeners');

const reports = await getLintErrors(node, rule);

// when
reports.forEach(report => {
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([
'ServiceTask_1-executionListener-0-listenerType',
'ServiceTask_1-executionListener-1-listenerType'
]);

expectErrorMessage(entryIds[ 0 ], 'Must be unique.', report);
});
});

});
});


Expand Down

0 comments on commit 3bdcfc8

Please sign in to comment.