Skip to content

Commit

Permalink
feat(popup-menu): allow to initially hide elements
Browse files Browse the repository at this point in the history
Allows integrators to assign a priority < 0 to hide elements from
the initial list of items. These items will appear once searched for.

Related to bpmn-io/bpmn-js#1621
  • Loading branch information
nikku committed Feb 3, 2023
1 parent 44c52f8 commit bd7ba9f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/features/popup-menu/PopupMenuComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function PopupMenuComponent(props) {

const filter = entry => {
if (!value) {
return true;
return (entry.priority || 0) >= 0;
}

const search = [
Expand Down
96 changes: 96 additions & 0 deletions test/spec/features/popup-menu/PopupMenuSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,80 @@ describe('features/popup-menu', function() {
expect(popupMenu.isOpen()).to.be.true;
}));


describe('priority + search', function() {

var testMenuProvider = {
getEntries: function() {
return [
{
id: 'A',
label: 'A'
},
{
id: 'B',
label: 'B'
},
{
id: 'C',
label: 'C'
},
{
id: 'D',
label: 'D',
priority: 1
},
{
id: 'E',
label: 'E',
priority: 0
},
{
id: 'F',
label: 'F (hide initially)',
priority: -1
}
];
}
};


it('should hide priority < 0 items', inject(async function(popupMenu) {

// given
popupMenu.registerProvider('test-menu', testMenuProvider);

// when
popupMenu.open({}, 'test-menu', { x: 100, y: 100 }, { search: true });

await whenStable();

// then
var shownEntries = queryPopupAll('.entry');

expect(shownEntries).to.have.length(5);
}));


it('should show priority < 0 if filtered', inject(async function(popupMenu) {

// given
popupMenu.registerProvider('test-menu', testMenuProvider);
popupMenu.open({}, 'test-menu', { x: 100, y: 100 }, { search: true });

// when
triggerSearch('hide ini');

await whenStable();

// then
var shownEntries = queryPopupAll('.entry');

expect(shownEntries).to.have.length(1);
}));

});

});


Expand Down Expand Up @@ -2010,3 +2084,25 @@ function getGroup(groupName) {
function whenStable() {
return new Promise(resolve => setTimeout(resolve, 200));
}

/**
* @param { string } key
*
* @return { KeyboardEvent }
*/
function keyUp(key) {
return new KeyboardEvent('keyup', { key, bubbles: true });
}

/**
* @param {string} value
*/
function triggerSearch(value) {

var searchInput = queryPopup('.djs-popup-search input');

expect(searchInput, 'search exists').to.exist;

searchInput.value = value;
searchInput.dispatchEvent(keyUp('ArrowRight'));
}

0 comments on commit bd7ba9f

Please sign in to comment.