Skip to content

Commit

Permalink
feat: adjust connector-properties error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed May 24, 2024
1 parent b2193f1 commit 281a981
Show file tree
Hide file tree
Showing 4 changed files with 414 additions and 2 deletions.
47 changes: 47 additions & 0 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export function getErrorMessage(report, context = {}) {
return getLoopNotAllowedErrorMessage(report, context);
}

if (type === ERROR_TYPES.CONNECTORS_PROPERTY_VALUE_NOT_ALLOWED) {
return getConnectorsPropertyValueNotAllowedErrorMessage(report, context);
}

return message;
}

Expand Down Expand Up @@ -754,6 +758,49 @@ function getLoopNotAllowedErrorMessage(report, context) {
return `A <Process> is not allowed to contain a straight-through processing loop: ${ elements.map(element => `<${ element }>`).join(', ') }`;
}

function getConnectorsPropertyValueNotAllowedErrorMessage(report, context) {
const {
data,
message
} = report;

const {
bpmnjs,
executionPlatform,
executionPlatformVersion
} = context;

if (!bpmnjs
|| !bpmnjs.get('elementTemplates', false)
|| !bpmnjs.get('elementTemplates', false).get(data.parentNode)) {
return message;
}

const elementTemplates = bpmnjs.get('elementTemplates', false);

const elementTemplate = elementTemplates.get(data.parentNode);

if (!elementTemplate) {
return message;
}

const property = elementTemplate.properties.find(property => {
const { binding } = property;

if (is(data.connectorProperty.node, 'zeebe:Property')) {
return binding
&& binding.type === 'zeebe:property'
&& binding.name === data.node.get(data.property);
}
});

if (!property || !property.label) {
return message;
}

return getSupportedMessage(`Connector property <${ property.label }>`, executionPlatform, executionPlatformVersion, data.allowedVersion);
}

function isEmptyString(value) {
return isString(value) && value.trim() === '';
}
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modeler/ElementTemplatesErrorLogger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ElementTemplatesErrorLogger {
constructor(eventBus) {
eventBus.on('elementTemplates.errors', ({ errors }) => {
console.error('elementTemplates.errors', errors.map(({ message }) => message));
});
}
}

ElementTemplatesErrorLogger.$inject = [ 'eventBus' ];

export default {
__init__: [ 'elementTemplatesErrorLogger' ],
elementTemplatesErrorLogger: [ 'type', ElementTemplatesErrorLogger ]
};
16 changes: 14 additions & 2 deletions test/spec/modeler/Linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import {

import camundaCloudBehaviors from 'camunda-bpmn-js-behaviors/lib/camunda-cloud';

import '@bpmn-io/element-template-chooser/dist/element-template-chooser.css';

import ElementTemplateChooserModule from '@bpmn-io/element-template-chooser';

import { domify } from 'min-dom';

import sinon from 'sinon';
Expand Down Expand Up @@ -107,6 +111,11 @@ insertCSS('test.css', `
}
`);

import ElementTemplatesErrorLogger from './ElementTemplatesErrorLogger';

import connectorTemplate from './connector-template.json';

const elementTemplates = [ connectorTemplate ];

const singleStart = window.__env__ && window.__env__.SINGLE_START;

Expand All @@ -124,12 +133,15 @@ describe('Linting', function() {
propertiesPanelModule,
bpmnPropertiesProviderModule,
camundaCloudBehaviors,
ElementTemplateChooserModule,
ElementTemplatesErrorLogger,
...additionalModules
],
moddleExtensions: {
modeler: modelerModdleExtension,
...moddleExtensions
}
},
elementTemplates
});
}

Expand Down Expand Up @@ -171,7 +183,7 @@ describe('Linting', function() {
const lint = () => {
const definitions = bpmnjs.getDefinitions();

linter.lint(definitions).then(reports => {
linter.lint(definitions, { bpmnjs }).then(reports => {
linting.setErrors(reports);

const container = panel.querySelector('.errorContainer');
Expand Down
Loading

0 comments on commit 281a981

Please sign in to comment.