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 29, 2024
1 parent 7da92d0 commit 58c09cf
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
28 changes: 22 additions & 6 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,14 +24,16 @@ export default class Linting {
propertiesPanel = {}
} = report;

const element = this._elementRegistry.get(id);
const selectableElement = this._getSelectableElement(id);

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

if (element !== this._canvas.getRootElement()) {
this._selection.select(element);
} else {
this._selection.select();
if (selectableElement === this._canvas.getRootElement()) {
this._selection.select();
} else {
this._selection.select(selectableElement);
}
}

const { entryIds = [] } = propertiesPanel;
Expand Down Expand Up @@ -77,6 +81,18 @@ export default class Linting {
});
}

_getSelectableElement(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;
}

_getSelectedElement() {
const selection = this._selection.get();

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 } from 'bpmn-js/lib/util/ModelUtil';

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 58c09cf

Please sign in to comment.