diff --git a/src/render/PanelHeaderProvider.js b/src/render/PanelHeaderProvider.js index 40f11ddba..433123a41 100644 --- a/src/render/PanelHeaderProvider.js +++ b/src/render/PanelHeaderProvider.js @@ -68,6 +68,16 @@ export function getConcreteType(element) { export const PanelHeaderProvider = { + getDocumentationRef: (element) => { + + // eslint-disable-next-line react-hooks/rules-of-hooks + const elementTemplates = useService('elementTemplates', false); + + if (elementTemplates) { + return getTemplateDocumentation(element, elementTemplates); + } + }, + getElementLabel: (element) => { if (is(element, 'bpmn:Process')) { return getBusinessObject(element).name; @@ -164,4 +174,10 @@ function isPlane(element) { function getTemplate(element, elementTemplates) { const templateId = elementTemplates._getTemplateId(element); return templateId && elementTemplates.get(templateId); +} + +function getTemplateDocumentation(element, elementTemplates) { + const template = getTemplate(element, elementTemplates); + + return template && template.documentationRef; } \ No newline at end of file diff --git a/test/spec/PanelHeaderProvider.spec.js b/test/spec/PanelHeaderProvider.spec.js index f92562588..96e017a79 100644 --- a/test/spec/PanelHeaderProvider.spec.js +++ b/test/spec/PanelHeaderProvider.spec.js @@ -670,6 +670,84 @@ describe('', function() { }); + + describe('#getDocumentationRef', function() { + + it('should NOT get documentationRef - no element templates', function() { + + // given + const element = createElement('bpmn:Task', { + name: 'foo' + }); + + // when + const result = createHeader({ container, element }); + + const documentationNode = domQuery('.bio-properties-panel-header-link', result.container); + + // then + expect(documentationNode).to.not.exist; + }); + + + it('should NOT get documentationRef - no value', function() { + + // given + const element = createElement('bpmn:Task', { + name: 'foo' + }); + + const elementTemplates = { + get: () => { return { id: 'foo' }; }, + getTemplateId: () => true + }; + + const context = { + getService: () => { + return new ElementTemplates(elementTemplates); + } + }; + + // when + const result = createHeader({ container, element, context }); + + const documentationNode = domQuery('.bio-properties-panel-header-link', result.container); + + // then + expect(documentationNode).to.not.exist; + }); + + + it('should get element template documentationRef', function() { + + // given + const element = createElement('bpmn:Task', { + name: 'foo' + }); + + const elementTemplates = { + get: () => { return { id: 'foo', documentationRef: 'https://example.com/' }; }, + getTemplateId: () => true + }; + + const context = { + getService: () => { + return new ElementTemplates(elementTemplates); + } + }; + + // when + const result = createHeader({ container, element, context }); + + const documentationNode = domQuery('.bio-properties-panel-header-link', result.container); + + // then + expect(documentationNode).to.exist; + expect(documentationNode.href).to.eql('https://example.com/'); + }); + + }); + }); diff --git a/test/spec/provider/cloud-element-templates/fixtures/complex.bpmn b/test/spec/provider/cloud-element-templates/fixtures/complex.bpmn index 205c4419f..cedc336ba 100644 --- a/test/spec/provider/cloud-element-templates/fixtures/complex.bpmn +++ b/test/spec/provider/cloud-element-templates/fixtures/complex.bpmn @@ -54,6 +54,7 @@ + @@ -92,6 +93,9 @@ + + + diff --git a/test/spec/provider/cloud-element-templates/fixtures/complex.json b/test/spec/provider/cloud-element-templates/fixtures/complex.json index bb06d7b4d..d08856284 100644 --- a/test/spec/provider/cloud-element-templates/fixtures/complex.json +++ b/test/spec/provider/cloud-element-templates/fixtures/complex.json @@ -525,5 +525,24 @@ "feel": "required" } ] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "REST Connector (with Docs)", + "id": "io.camunda.connectors.RestConnector-documentationRef", + "description": "A generic REST service.", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "documentationRef": "https://docs.camunda.io", + "properties": [ + { + "type": "Hidden", + "value": "http", + "binding": { + "type": "zeebe:taskDefinition:type" + } + } + ] } ] \ No newline at end of file diff --git a/test/spec/provider/element-templates/fixtures/complex.bpmn b/test/spec/provider/element-templates/fixtures/complex.bpmn index de71a2ed0..d2f413612 100644 --- a/test/spec/provider/element-templates/fixtures/complex.bpmn +++ b/test/spec/provider/element-templates/fixtures/complex.bpmn @@ -1,5 +1,5 @@ - + Flow_08c5khp @@ -109,7 +109,7 @@ Flow_10mgmi5 - + @@ -134,7 +134,7 @@ Flow_0s9gmd7 Flow_14l7z7l - + ${ customer.vip } @@ -178,6 +178,7 @@ + @@ -285,6 +286,9 @@ + + + diff --git a/test/spec/provider/element-templates/fixtures/complex.json b/test/spec/provider/element-templates/fixtures/complex.json index a265b9bb3..47cb71017 100644 --- a/test/spec/provider/element-templates/fixtures/complex.json +++ b/test/spec/provider/element-templates/fixtures/complex.json @@ -710,5 +710,15 @@ } } ] + }, + { + "$schema": "https://unpkg.com/@camunda/element-templates-json-schema/resources/schema.json", + "name": "Documentation Reference", + "id": "com.camunda.example.DocumentationRef", + "documentationRef": "https://docs.camunda.io", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [] } ]