Skip to content

Commit c81dc4f

Browse files
zxuanhongphilippfromme
authored andcommitted
feat: header displays element template icon found in XML
Closes #1011
1 parent 5d8bd68 commit c81dc4f

File tree

2 files changed

+23
-115
lines changed

2 files changed

+23
-115
lines changed

src/render/PanelHeaderProvider.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ export const PanelHeaderProvider = {
8787
getElementIcon: (element) => {
8888
const concreteType = getConcreteType(element);
8989

90-
const elementTemplates = getTemplatesService();
90+
// eslint-disable-next-line react-hooks/rules-of-hooks
91+
const config = useService('config.elementTemplateIconRenderer', false);
9192

92-
if (elementTemplates) {
93-
const template = getTemplate(element, elementTemplates);
93+
const { iconProperty = 'zeebe:modelerTemplateIcon' } = config || {};
9494

95-
if (template && template.icon) {
96-
return () => <img class="bio-properties-panel-header-template-icon" width="32" height="32" src={ template.icon.contents } />;
97-
}
95+
const templateIcon = getBusinessObject(element).get(iconProperty);
96+
97+
if (templateIcon) {
98+
return () => <img class="bio-properties-panel-header-template-icon" width="32" height="32" src={ templateIcon } />;
9899
}
99100

100101
return iconsByType[ concreteType ];

test/spec/PanelHeaderProvider.spec.js

Lines changed: 16 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010

1111
import BpmnModdle from 'bpmn-moddle';
1212

13+
import ZeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe';
14+
1315
import {
1416
insertCoreStyles
1517
} from 'test/TestHelper';
@@ -37,7 +39,9 @@ const noopElement = {
3739
}
3840
};
3941

40-
const moddle = new BpmnModdle();
42+
const moddle = new BpmnModdle({
43+
zeebe: ZeebeModdle
44+
});
4145

4246

4347
describe('<PanelHeaderProvider>', function() {
@@ -184,7 +188,7 @@ describe('<PanelHeaderProvider>', function() {
184188

185189
describe('#getElementIcon', function() {
186190

187-
it('should get icon - no element templates', function() {
191+
it('should get icon - no template', function() {
188192

189193
// given
190194
const element = createElement('bpmn:Task');
@@ -201,138 +205,41 @@ describe('<PanelHeaderProvider>', function() {
201205
});
202206

203207

204-
it('should get icon - no template icon', function() {
205-
206-
// given
207-
const element = createElement('bpmn:Task');
208-
209-
const elementTemplates = {
210-
get: () => { return { id: 'foo' }; },
211-
getTemplateId: () => 'foo'
212-
};
213-
214-
const context = {
215-
getService: () => {
216-
return new ElementTemplates(elementTemplates);
217-
}
218-
};
219-
220-
// when
221-
const result = createHeader({ container, element, context });
222-
223-
const iconNode = domQuery('.bio-properties-panel-header-icon', result.container);
224-
const templateIconNode = domQuery('.bio-properties-panel-header-template-icon', iconNode);
225-
226-
// then
227-
expect(iconNode).to.exist;
228-
expect(templateIconNode).to.not.exist;
229-
});
230-
231-
232208
it('should get template icon - data URI', function() {
233209

234210
// given
235-
const element = createElement('bpmn:Task');
236-
237-
const template = {
238-
id: 'foo',
239-
icon: {
240-
contents: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='100' width='100'%3E%3Ccircle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' /%3E%3C/svg%3E"
241-
}
242-
};
243-
244-
const elementTemplates = {
245-
get: () => { return template; },
246-
getTemplateId: () => 'foo'
247-
};
248-
249-
const context = {
250-
getService: () => {
251-
return new ElementTemplates(elementTemplates);
252-
}
253-
};
211+
const element = createElement('bpmn:Task', {
212+
'zeebe:modelerTemplateIcon': "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='100' width='100'%3E%3Ccircle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' /%3E%3C/svg%3E"
213+
});
254214

255215
// when
256-
const result = createHeader({ container, element, context });
216+
const result = createHeader({ container, element });
257217

258218
const iconNode = domQuery('.bio-properties-panel-header-icon', result.container);
259219
const templateIconNode = domQuery('.bio-properties-panel-header-template-icon', iconNode);
260220

261221
// then
262222
expect(templateIconNode).to.exist;
263-
expect(templateIconNode.src).to.eql(template.icon.contents);
223+
expect(templateIconNode.src).to.eql(element.businessObject.get('zeebe:modelerTemplateIcon'));
264224
});
265225

266226

267227
it('should get template icon - https URI', function() {
268228

269229
// given
270-
const element = createElement('bpmn:Task');
271-
272-
const template = {
273-
id: 'foo',
274-
icon: {
275-
contents: 'https://camunda.com/wp-content/uploads/2020/05/logo-camunda-black.svg'
276-
}
277-
};
278-
279-
const elementTemplates = {
280-
get: () => { return template; },
281-
getTemplateId: () => 'foo'
282-
};
283-
284-
const context = {
285-
getService: () => {
286-
return new ElementTemplates(elementTemplates);
287-
}
288-
};
289-
290-
// when
291-
const result = createHeader({ container, element, context });
292-
293-
const iconNode = domQuery('.bio-properties-panel-header-icon', result.container);
294-
const templateIconNode = domQuery('.bio-properties-panel-header-template-icon', iconNode);
295-
296-
// then
297-
expect(templateIconNode).to.exist;
298-
expect(templateIconNode.src).to.eql(template.icon.contents);
299-
});
300-
301-
302-
it('should get template icon - versioned', function() {
303-
304-
// given
305-
const element = createElement('bpmn:Task');
306-
307-
const template = {
308-
id: 'foo',
309-
version: 1,
310-
icon: {
311-
contents: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='100' width='100'%3E%3Ccircle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' /%3E%3C/svg%3E"
312-
}
313-
};
314-
315-
const elementTemplates = {
316-
get: () => { return template; },
317-
getTemplateId: () => 'foo',
318-
getTemplateVersion: () => 1
319-
};
320-
321-
const context = {
322-
getService: () => {
323-
return new ElementTemplates(elementTemplates);
324-
}
325-
};
230+
const element = createElement('bpmn:Task', {
231+
'zeebe:modelerTemplateIcon': 'https://camunda.com/wp-content/uploads/2020/05/logo-camunda-black.svg'
232+
});
326233

327234
// when
328-
const result = createHeader({ container, element, context });
235+
const result = createHeader({ container, element });
329236

330237
const iconNode = domQuery('.bio-properties-panel-header-icon', result.container);
331238
const templateIconNode = domQuery('.bio-properties-panel-header-template-icon', iconNode);
332239

333240
// then
334241
expect(templateIconNode).to.exist;
335-
expect(templateIconNode.src).to.eql(template.icon.contents);
242+
expect(templateIconNode.src).to.eql(element.businessObject.get('zeebe:modelerTemplateIcon'));
336243
});
337244

338245
});

0 commit comments

Comments
 (0)