diff --git a/lib/modeler/Linting.js b/lib/modeler/Linting.js index c2457df..1d47d5f 100644 --- a/lib/modeler/Linting.js +++ b/lib/modeler/Linting.js @@ -1,3 +1,5 @@ +import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil'; + import { getErrors } from '../utils/properties-panel'; export default class Linting { @@ -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); @@ -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; diff --git a/test/spec/modeler/Linting.spec.js b/test/spec/modeler/Linting.spec.js index 6fa97fe..7cbebf4 100644 --- a/test/spec/modeler/Linting.spec.js +++ b/test/spec/modeler/Linting.spec.js @@ -4,6 +4,8 @@ import { insertCSS } from 'bpmn-js/test/helper'; +import { getBusinessObject, is, isAny } 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'; @@ -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'; @@ -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 ]); + } + )); + + }); + }); @@ -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; + } + )); }); }); diff --git a/test/spec/modeler/linting-collaboration-cloud.bpmn b/test/spec/modeler/linting-collaboration-cloud.bpmn new file mode 100644 index 0000000..8330bb2 --- /dev/null +++ b/test/spec/modeler/linting-collaboration-cloud.bpmn @@ -0,0 +1,14 @@ + + + + + + + + + + + + + +