Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] do not pass 'sortOrder' to EuiContextMenuItem in share context menu (#26890) #26976

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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",
Expand Down
47 changes: 47 additions & 0 deletions src/ui/public/share/components/share_context_menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
18 changes: 9 additions & 9 deletions src/ui/public/share/components/share_context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down