mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Core: add hideFromMenu for child items (#22494)
This commit is contained in:
parent
72628c8ea0
commit
1db26d354f
@ -32,4 +32,19 @@ describe('Render', () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not render hideFromMenu children', () => {
|
||||||
|
const wrapper = setup({
|
||||||
|
link: {
|
||||||
|
text: 'link',
|
||||||
|
children: [
|
||||||
|
{ id: 1, hideFromMenu: false },
|
||||||
|
{ id: 2, hideFromMenu: true },
|
||||||
|
{ id: 3, hideFromMenu: false },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
import DropDownChild from './DropDownChild';
|
import DropDownChild from './DropDownChild';
|
||||||
import { NavModelItem } from '@grafana/data';
|
import { NavModelItem } from '@grafana/data';
|
||||||
|
|
||||||
@ -8,6 +9,11 @@ interface Props {
|
|||||||
|
|
||||||
const SideMenuDropDown: FC<Props> = props => {
|
const SideMenuDropDown: FC<Props> = props => {
|
||||||
const { link } = props;
|
const { link } = props;
|
||||||
|
let childrenLinks: NavModelItem[] = [];
|
||||||
|
if (link.children) {
|
||||||
|
childrenLinks = _.filter(link.children, item => !item.hideFromMenu);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className="dropdown-menu dropdown-menu--sidemenu" role="menu">
|
<ul className="dropdown-menu dropdown-menu--sidemenu" role="menu">
|
||||||
<li className="side-menu-header">
|
<li className="side-menu-header">
|
||||||
@ -15,10 +21,9 @@ const SideMenuDropDown: FC<Props> = props => {
|
|||||||
<span className="sidemenu-item-text">{link.text}</span>
|
<span className="sidemenu-item-text">{link.text}</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{link.children &&
|
{childrenLinks.map((child, index) => {
|
||||||
link.children.map((child, index) => {
|
return <DropDownChild child={child} key={`${child.url}-${index}`} />;
|
||||||
return <DropDownChild child={child} key={`${child.url}-${index}`} />;
|
})}
|
||||||
})}
|
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,44 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Render should not render hideFromMenu children 1`] = `
|
||||||
|
<ul
|
||||||
|
className="dropdown-menu dropdown-menu--sidemenu"
|
||||||
|
role="menu"
|
||||||
|
>
|
||||||
|
<li
|
||||||
|
className="side-menu-header"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="side-menu-header-link"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="sidemenu-item-text"
|
||||||
|
>
|
||||||
|
link
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<DropDownChild
|
||||||
|
child={
|
||||||
|
Object {
|
||||||
|
"hideFromMenu": false,
|
||||||
|
"id": 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key="undefined-0"
|
||||||
|
/>
|
||||||
|
<DropDownChild
|
||||||
|
child={
|
||||||
|
Object {
|
||||||
|
"hideFromMenu": false,
|
||||||
|
"id": 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key="undefined-1"
|
||||||
|
/>
|
||||||
|
</ul>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Render should render children 1`] = `
|
exports[`Render should render children 1`] = `
|
||||||
<ul
|
<ul
|
||||||
className="dropdown-menu dropdown-menu--sidemenu"
|
className="dropdown-menu dropdown-menu--sidemenu"
|
||||||
|
Loading…
Reference in New Issue
Block a user