Skip to content

Commit

Permalink
fix: show error for process refs
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Apr 26, 2024
1 parent 7da92d0 commit b6904c8
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/modeler/Linting.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil';

import { getErrors } from '../utils/properties-panel';

export default class Linting {
Expand All @@ -22,9 +24,11 @@ export default class Linting {
propertiesPanel = {}
} = report;

const element = this._elementRegistry.get(id);
const element = this._getElement(id);

this._canvas.scrollToElement(element);
if (element) {
this._canvas.scrollToElement(element);
}

if (element !== this._canvas.getRootElement()) {
this._selection.select(element);
Expand All @@ -42,6 +46,18 @@ export default class Linting {
});
}

_getElement(id) {
let element = this._elementRegistry.get(id);

if (!element) {
element = this._elementRegistry.filter(element => {
return is(element, 'bpmn:Participant') && getBusinessObject(element).get('processRef').get('id') === id;
})[ 0 ];
}

return element;
}

setErrors(reports) {
this._reports = reports;

Expand Down
76 changes: 76 additions & 0 deletions test/spec/modeler/Linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
insertCSS
} from 'bpmn-js/test/helper';

import { getBusinessObject, is, isAny } from 'bpmn-js/lib/util/ModelUtil';

Check failure on line 7 in test/spec/modeler/Linting.spec.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'is' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in test/spec/modeler/Linting.spec.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'isAny' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in test/spec/modeler/Linting.spec.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'is' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in test/spec/modeler/Linting.spec.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'isAny' is defined but never used. Allowed unused vars must match /^_/u

import zeebeModdleExtension from 'zeebe-bpmn-moddle/resources/zeebe';
import camundaModdleExtension from 'camunda-bpmn-moddle/resources/camunda';
import modelerModdleExtension from 'modeler-moddle/resources/modeler';
Expand Down Expand Up @@ -42,6 +44,7 @@ import elementTemplatesCSS from 'bpmn-js-element-templates/dist/assets/element-t
import lintingCSS from '../../../assets/linting.css';

import diagramXMLCloud from './linting-cloud.bpmn';
import diagramCollaborationXMLCloud from './linting-collaboration-cloud.bpmn';
import diagramXMLCloudScroll from './linting-cloud-scroll.bpmn';
import diagramXMLPlatform from './linting-platform.bpmn';

Expand Down Expand Up @@ -625,6 +628,47 @@ describe('Linting', function() {
}
));


describe('collaboration', function() {

beforeEach(createModeler(diagramCollaborationXMLCloud,
[
zeebePropertiesProviderModule,
cloudElementTemplatesPropertiesProvider
],
{
zeebe: zeebeModdleExtension
})
);


it('should select participant', inject(
async function(linting, selection, elementRegistry) {

// given
const participant = elementRegistry.get('Participant_1');

const reports = [
{
id: getBusinessObject(participant).get('processRef').id,
message: 'foo'
}
];

linting.setErrors(reports);
linting.activate();

// when
linting.showError(reports[ 0 ]);
clock.tick();

// then
expect(selection.get()).to.eql([ participant ]);
}
));

});

});


Expand Down Expand Up @@ -730,6 +774,38 @@ describe('Linting', function() {
}
));


it('should not scroll if element not found', inject(
function(canvas, linting) {

// given
const reports = [
{
id: 'Foo',
message: 'foo'
}
];

linting.setErrors(reports);

linting.activate();

canvas.viewbox({
x: 10000,
y: 10000,
width: 1000,
height: 1000
});

const scrollToElementSpy = sinon.spy(canvas, 'scrollToElement');

// when
linting.showError(reports[ 0 ]);

// then
expect(scrollToElementSpy).not.to.have.been.called;
}
));
});

});
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modeler/linting-collaboration-cloud.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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_0umuwjr" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.22.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:collaboration id="Collaboration_1">
<bpmn:participant id="Participant_1" processRef="Process_1" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="true" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="Participant_1mwod53_di" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds x="129" y="52" width="600" height="250" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit b6904c8

Please sign in to comment.