mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* setup menu as a render prop sent down from PanelStateWrapper to PanelChrome * let the Dropdown take care of opening the menu in PanelChrome * menu and leftItems are on the right side of the header together * add storybook examples with menu * menu does not need to be a callback because it's opened in a Dropdown anyway * pass down to getPanelMenu whether or not data is streaming atm * stop loading data as well as streaming from menu * override menu's style where needed * reduce snapshot matching in tests
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
|
|
import { PanelMenuItem } from '@grafana/data';
|
|
|
|
import { PanelHeaderMenuItem } from './PanelHeaderMenuItem';
|
|
|
|
export interface Props {
|
|
items: PanelMenuItem[];
|
|
style?: React.CSSProperties;
|
|
}
|
|
|
|
export class PanelHeaderMenu extends PureComponent<Props> {
|
|
renderItems = (menu: PanelMenuItem[], isSubMenu = false) => {
|
|
return (
|
|
<ul
|
|
className="dropdown-menu dropdown-menu--menu panel-menu"
|
|
style={this.props.style}
|
|
role={isSubMenu ? '' : 'menu'}
|
|
>
|
|
{menu.map((menuItem, idx: number) => {
|
|
return (
|
|
<PanelHeaderMenuItem
|
|
key={`${menuItem.text}${idx}`}
|
|
type={menuItem.type}
|
|
text={menuItem.text}
|
|
iconClassName={menuItem.iconClassName}
|
|
onClick={menuItem.onClick}
|
|
shortcut={menuItem.shortcut}
|
|
>
|
|
{menuItem.subMenu && this.renderItems(menuItem.subMenu, true)}
|
|
</PanelHeaderMenuItem>
|
|
);
|
|
})}
|
|
</ul>
|
|
);
|
|
};
|
|
|
|
render() {
|
|
return <div className="panel-menu-container dropdown open">{this.renderItems(this.props.items)}</div>;
|
|
}
|
|
}
|