mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
do not pass 'sortOrder' to EuiContextMenuItem in share context menu (#26890)
* do not pass 'sortOrder' to EuiContextMenuItem in share context menu * add unit test for sortOrder * avoid using lodash * fix merge conflicts with internationization PR
This commit is contained in:
parent
56fcc6df10
commit
f06ec83458
3 changed files with 111 additions and 11 deletions
|
@ -1,5 +1,60 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`shareContextMenuExtensions should sort ascending on sort order first and then ascending on name 1`] = `
|
||||
<EuiContextMenu
|
||||
data-test-subj="shareContextMenu"
|
||||
initialPanelId={4}
|
||||
panels={
|
||||
Array [
|
||||
Object {
|
||||
"content": <InjectIntl(UrlPanelContentUI)
|
||||
getUnhashableStates={[Function]}
|
||||
objectType="dashboard"
|
||||
/>,
|
||||
"id": 1,
|
||||
"title": "Permalink",
|
||||
},
|
||||
Object {
|
||||
"content": <div>
|
||||
panel content
|
||||
</div>,
|
||||
"id": 2,
|
||||
"title": "AAA panel",
|
||||
},
|
||||
Object {
|
||||
"content": <div>
|
||||
panel content
|
||||
</div>,
|
||||
"id": 3,
|
||||
"title": "ZZZ panel",
|
||||
},
|
||||
Object {
|
||||
"id": 4,
|
||||
"items": Array [
|
||||
Object {
|
||||
"data-test-subj": "sharePanel-Permalinks",
|
||||
"icon": "link",
|
||||
"name": "Permalinks",
|
||||
"panel": 1,
|
||||
},
|
||||
Object {
|
||||
"data-test-subj": "sharePanel-ZZZpanel",
|
||||
"name": "ZZZ panel",
|
||||
"panel": 3,
|
||||
},
|
||||
Object {
|
||||
"data-test-subj": "sharePanel-AAApanel",
|
||||
"name": "AAA panel",
|
||||
"panel": 2,
|
||||
},
|
||||
],
|
||||
"title": "Share this dashboard",
|
||||
},
|
||||
]
|
||||
}
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`should only render permalink panel when there are no other panels 1`] = `
|
||||
<EuiContextMenu
|
||||
data-test-subj="shareContextMenu"
|
||||
|
@ -50,14 +105,12 @@ exports[`should render context menu panel when there are more than one panel 1`]
|
|||
"icon": "console",
|
||||
"name": "Embed code",
|
||||
"panel": 2,
|
||||
"sortOrder": 0,
|
||||
},
|
||||
Object {
|
||||
"data-test-subj": "sharePanel-Permalinks",
|
||||
"icon": "link",
|
||||
"name": "Permalinks",
|
||||
"panel": 1,
|
||||
"sortOrder": 0,
|
||||
},
|
||||
],
|
||||
"title": "Share this dashboard",
|
||||
|
|
|
@ -43,3 +43,50 @@ test('should only render permalink panel when there are no other panels', () =>
|
|||
/>);
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe('shareContextMenuExtensions', () => {
|
||||
const shareContextMenuExtensions = [
|
||||
{
|
||||
getShareActions: () => {
|
||||
return [
|
||||
{
|
||||
panel: {
|
||||
title: 'AAA panel',
|
||||
content: (<div>panel content</div>),
|
||||
},
|
||||
shareMenuItem: {
|
||||
name: 'AAA panel',
|
||||
sortOrder: 5,
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
},
|
||||
{
|
||||
getShareActions: () => {
|
||||
return [
|
||||
{
|
||||
panel: {
|
||||
title: 'ZZZ panel',
|
||||
content: (<div>panel content</div>),
|
||||
},
|
||||
shareMenuItem: {
|
||||
name: 'ZZZ panel',
|
||||
sortOrder: 0,
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
test('should sort ascending on sort order first and then ascending on name', () => {
|
||||
const component = shallowWithIntl(<ShareContextMenu.WrappedComponent
|
||||
allowEmbed={false}
|
||||
objectType="dashboard"
|
||||
getUnhashableStates={() => {}}
|
||||
shareContextMenuExtensions={shareContextMenuExtensions}
|
||||
/>);
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -155,25 +155,25 @@ class ShareContextMenuUI extends Component<Props> {
|
|||
}
|
||||
),
|
||||
items: menuItems
|
||||
.map(menuItem => {
|
||||
menuItem['data-test-subj'] = `sharePanel-${menuItem.name.replace(' ', '')}`;
|
||||
if (!menuItem.sortOrder) {
|
||||
menuItem.sortOrder = 0;
|
||||
}
|
||||
return menuItem;
|
||||
})
|
||||
// Sorts ascending on sort order first and then ascending on name
|
||||
.sort((a, b) => {
|
||||
if (a.sortOrder > b.sortOrder) {
|
||||
const aSortOrder = a.sortOrder || 0;
|
||||
const bSortOrder = b.sortOrder || 0;
|
||||
if (aSortOrder > bSortOrder) {
|
||||
return 1;
|
||||
}
|
||||
if (a.sortOrder < b.sortOrder) {
|
||||
if (aSortOrder < bSortOrder) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name.toLowerCase().localeCompare(b.name.toLowerCase()) > 0) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
})
|
||||
.map(menuItem => {
|
||||
menuItem['data-test-subj'] = `sharePanel-${menuItem.name.replace(' ', '')}`;
|
||||
delete menuItem.sortOrder;
|
||||
return menuItem;
|
||||
}),
|
||||
};
|
||||
panels.push(topLevelMenuPanel);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue