Skip to content

Commit 6ddd524

Browse files
committed
fix(element-templates): trigger create mode if auto place not possible
Related to camunda/camunda-modeler#5193
1 parent 2d5e2a1 commit 6ddd524

File tree

4 files changed

+121
-19
lines changed

4 files changed

+121
-19
lines changed

lib/element-templates/append-menu/ElementTemplatesAppendProvider.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,45 @@ ElementTemplatesAppendProvider.prototype._filterTemplates = function(templates)
141141
* @returns {Object}
142142
*/
143143
ElementTemplatesAppendProvider.prototype._getEntryAction = function(element, template) {
144-
return {
145-
146-
click: () => {
147-
const newElement = this._elementTemplates.createElement(template);
148-
this._autoPlace.append(element, newElement);
149-
},
144+
const autoPlaceElement = () => {
145+
const newElement = this._elementTemplates.createElement(template);
150146

151-
dragstart: (event) => {
152-
const newElement = this._elementTemplates.createElement(template);
147+
this._autoPlace.append(element, newElement);
148+
};
153149

154-
if (event instanceof KeyboardEvent) {
155-
event = this._mouse.getLastMoveEvent();
156-
}
150+
const manualPlaceElement = (event) => {
151+
const newElement = this._elementTemplates.createElement(template);
157152

158-
this._create.start(event, newElement, {
159-
source: element
160-
});
153+
if (event instanceof KeyboardEvent) {
154+
event = this._mouse.getLastMoveEvent();
161155
}
156+
157+
return this._create.start(event, newElement, {
158+
source: element
159+
});
160+
};
161+
162+
return {
163+
click: canAutoPlaceElement(template) ? autoPlaceElement : manualPlaceElement,
164+
dragstart: manualPlaceElement
162165
};
163166
};
167+
168+
function canAutoPlaceElement(elementTemplate) {
169+
const {
170+
appliesTo = [],
171+
elementType = {}
172+
} = elementTemplate;
173+
174+
const type = elementType.value || appliesTo[0];
175+
176+
if (type === 'bpmn:BoundaryEvent') {
177+
return false;
178+
}
179+
180+
if (type === 'bpmn:IntermediateCatchEvent' && elementType.eventDefinition === 'bpmn:LinkEventDefinition') {
181+
return false;
182+
}
183+
184+
return true;
185+
}

test/fixtures/element-templates.json

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"type": "Boolean",
1212
"binding": {
1313
"type": "property",
14-
"name": "customProperty"
14+
"name": "foo"
1515
}
1616
}
1717
]
@@ -34,7 +34,7 @@
3434
{
3535
"binding": {
3636
"type": "property",
37-
"name": "someProp"
37+
"name": "foo"
3838
}
3939
}
4040
]
@@ -57,7 +57,7 @@
5757
{
5858
"binding": {
5959
"type": "property",
60-
"name": "someProp"
60+
"name": "foo"
6161
}
6262
}
6363
]
@@ -98,5 +98,45 @@
9898
"first keyword",
9999
"another keyword"
100100
]
101+
},
102+
{
103+
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
104+
"name": "Message Boundary Event Template",
105+
"id": "example.MessageBoundaryEventTemplate",
106+
"appliesTo": [
107+
"bpmn:BoundaryEvent"
108+
],
109+
"elementType": {
110+
"value": "bpmn:BoundaryEvent",
111+
"eventDefinition": "bpmn:MessageEventDefinition"
112+
},
113+
"properties": [
114+
{
115+
"binding": {
116+
"type": "property",
117+
"name": "foo"
118+
}
119+
}
120+
]
121+
},
122+
{
123+
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
124+
"name": "Link Intermediate Catch Event Template",
125+
"id": "example.LinkIntermediateCatchEventTemplate",
126+
"appliesTo": [
127+
"bpmn:IntermediateCatchEvent"
128+
],
129+
"elementType": {
130+
"value": "bpmn:IntermediateCatchEvent",
131+
"eventDefinition": "bpmn:LinkEventDefinition"
132+
},
133+
"properties": [
134+
{
135+
"binding": {
136+
"type": "property",
137+
"name": "foo"
138+
}
139+
}
140+
]
101141
}
102142
]

test/spec/create-append-anything/append-menu/AppendMenuProvider.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ describe('features/create-append-anything - append menu provider', function() {
430430

431431
// then
432432
expect(spy).to.have.been.called;
433-
434433
}));
435434

436435

@@ -450,7 +449,6 @@ describe('features/create-append-anything - append menu provider', function() {
450449

451450
// then
452451
expect(spy).to.have.been.called;
453-
454452
}));
455453

456454
});

test/spec/element-templates/append-menu/ElementTemplatesAppendProvider.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,48 @@ describe('<ElementTemplatesAppendProvider>', function() {
207207
expect(isTemplateApplied(newElement, template)).to.be.true;
208208
}));
209209

210+
211+
describe('should trigger create mode', function() {
212+
213+
it('boundary event', inject(function(elementRegistry, eventBus) {
214+
215+
// given
216+
const task = elementRegistry.get('Task_1');
217+
218+
const spy = sinon.spy();
219+
220+
eventBus.on('create.init', spy);
221+
222+
// when
223+
openPopup(task);
224+
225+
triggerAction('append.template-example.MessageBoundaryEventTemplate');
226+
227+
// then
228+
expect(spy).to.have.been.called;
229+
}));
230+
231+
232+
it('link intermediate catch event', inject(function(elementRegistry, eventBus) {
233+
234+
// given
235+
const task = elementRegistry.get('Task_1');
236+
237+
const spy = sinon.spy();
238+
239+
eventBus.on('create.init', spy);
240+
241+
// when
242+
openPopup(task);
243+
244+
triggerAction('append.template-example.LinkIntermediateCatchEventTemplate');
245+
246+
// then
247+
expect(spy).to.have.been.called;
248+
}));
249+
250+
});
251+
210252
});
211253

212254

0 commit comments

Comments
 (0)