Skip to content

Commit 9c8ca11

Browse files
committed
fix: update dropdown on external change
1 parent 73368b7 commit 9c8ca11

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

packages/dmn-js-drd/src/features/type-ref-dropdown/TypeRefDropdown.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default class TypeRefDropdown {
2525
this._modeling = modeling;
2626
this._translate = translate;
2727

28+
this._current = null;
29+
2830
this._eventBus.on('selection.changed', (event) => {
2931

3032
// clean up any existing overlays
@@ -38,22 +40,52 @@ export default class TypeRefDropdown {
3840
this.open(target);
3941
}
4042
});
43+
44+
this._eventBus.on('elements.changed', event => {
45+
if (!this._current) {
46+
return;
47+
}
48+
49+
const { element } = this._current;
50+
51+
if (event.elements.includes(element)) {
52+
this._update();
53+
}
54+
});
4155
}
4256

4357
open(element) {
58+
const container = this._getOverlayNode(element);
59+
this._current = {
60+
element,
61+
container
62+
};
63+
4464
this._overlays.add(element, 'type-ref-dropdown', {
4565
position: {
4666
top: 60,
4767
left: 0
4868
},
49-
html: this._getOverlayNode(element)
69+
html: container
5070
});
5171
}
5272

5373
close() {
74+
this._current = null;
5475
this._overlays.remove({ type: 'type-ref-dropdown' });
5576
}
5677

78+
_update() {
79+
if (!this._current) {
80+
return;
81+
}
82+
83+
const { element, container } = this._current;
84+
85+
const select = container.querySelector('select');
86+
select.value = this._getTypeRef(element);
87+
}
88+
5789
_getOverlayNode(element) {
5890
const container = document.createElement('div');
5991
container.className = 'dms-type-ref-dropdown';

packages/dmn-js-drd/test/spec/features/type-ref-dropdown/TypeRefDropdownSpec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,45 @@ describe('features - type-ref-dropdown', function() {
320320
});
321321

322322

323+
describe('external changes', function() {
324+
325+
it('should update select value on undo', inject(
326+
function(elementRegistry, selection, commandStack) {
327+
328+
// given
329+
const element = elementRegistry.get('withVariable_id');
330+
selection.select(element);
331+
triggerSelectChange(querySelect('withVariable_id'), 'number');
332+
333+
// when
334+
commandStack.undo();
335+
336+
// then
337+
expect(querySelect('withVariable_id').value).to.equal('boolean');
338+
}
339+
));
340+
341+
342+
it('should update select value on redo', inject(
343+
function(elementRegistry, selection, commandStack) {
344+
345+
// given
346+
const element = elementRegistry.get('withVariable_id');
347+
selection.select(element);
348+
triggerSelectChange(querySelect('withVariable_id'), 'number');
349+
commandStack.undo();
350+
351+
// when
352+
commandStack.redo();
353+
354+
// then
355+
expect(querySelect('withVariable_id').value).to.equal('number');
356+
}
357+
));
358+
359+
});
360+
361+
323362
// helpers //////////////
324363

325364
function queryOverlay(elementId) {

0 commit comments

Comments
 (0)