diff --git a/src/ui/public/share/components/__snapshots__/share_context_menu.test.js.snap b/src/ui/public/share/components/__snapshots__/share_context_menu.test.js.snap
index d92769d3101f7..df50f1d4a78ba 100644
--- a/src/ui/public/share/components/__snapshots__/share_context_menu.test.js.snap
+++ b/src/ui/public/share/components/__snapshots__/share_context_menu.test.js.snap
@@ -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`] = `
+,
+ "id": 1,
+ "title": "Permalink",
+ },
+ Object {
+ "content":
+ panel content
+
,
+ "id": 2,
+ "title": "AAA panel",
+ },
+ Object {
+ "content":
+ panel content
+
,
+ "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`] = `
/>);
expect(component).toMatchSnapshot();
});
+
+describe('shareContextMenuExtensions', () => {
+ const shareContextMenuExtensions = [
+ {
+ getShareActions: () => {
+ return [
+ {
+ panel: {
+ title: 'AAA panel',
+ content: (panel content
),
+ },
+ shareMenuItem: {
+ name: 'AAA panel',
+ sortOrder: 5,
+ }
+ }
+ ];
+ }
+ },
+ {
+ getShareActions: () => {
+ return [
+ {
+ panel: {
+ title: 'ZZZ panel',
+ content: (panel content
),
+ },
+ shareMenuItem: {
+ name: 'ZZZ panel',
+ sortOrder: 0,
+ }
+ }
+ ];
+ }
+ }
+ ];
+
+ test('should sort ascending on sort order first and then ascending on name', () => {
+ const component = shallowWithIntl( {}}
+ shareContextMenuExtensions={shareContextMenuExtensions}
+ />);
+ expect(component).toMatchSnapshot();
+ });
+});
diff --git a/src/ui/public/share/components/share_context_menu.tsx b/src/ui/public/share/components/share_context_menu.tsx
index b68d75b40bc56..e31cbad767250 100644
--- a/src/ui/public/share/components/share_context_menu.tsx
+++ b/src/ui/public/share/components/share_context_menu.tsx
@@ -155,25 +155,25 @@ class ShareContextMenuUI extends Component {
}
),
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);