Commit 6d65432c by Torkel Ödegaard

Merge branch 'toggle-panel-menu-withreact' into develop

parents 8ad37ea9 a9b5cbf3
import { PureComponent } from 'react';
import ReactDOM from 'react-dom';
export interface Props {
onClick: () => void;
}
interface State {
hasEventListener: boolean;
}
export class ClickOutsideWrapper extends PureComponent<Props, State> {
state = {
hasEventListener: false,
};
componentDidMount() {
window.addEventListener('click', this.onOutsideClick, false);
}
componentWillUnmount() {
window.removeEventListener('click', this.onOutsideClick, false);
}
onOutsideClick = event => {
const domNode = ReactDOM.findDOMNode(this) as Element;
if (!domNode || !domNode.contains(event.target)) {
this.props.onClick();
}
};
render() {
return this.props.children;
}
}
...@@ -5,6 +5,7 @@ import { PanelHeaderMenu } from './PanelHeaderMenu'; ...@@ -5,6 +5,7 @@ import { PanelHeaderMenu } from './PanelHeaderMenu';
import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { DashboardModel } from 'app/features/dashboard/dashboard_model';
import { PanelModel } from 'app/features/dashboard/panel_model'; import { PanelModel } from 'app/features/dashboard/panel_model';
import { ClickOutsideWrapper } from 'app/core/components/ClickOutsideWrapper/ClickOutsideWrapper';
export interface Props { export interface Props {
panel: PanelModel; panel: PanelModel;
...@@ -12,7 +13,29 @@ export interface Props { ...@@ -12,7 +13,29 @@ export interface Props {
timeInfo: string; timeInfo: string;
} }
export class PanelHeader extends PureComponent<Props> { interface State {
panelMenuOpen: boolean;
}
export class PanelHeader extends PureComponent<Props, State> {
state = {
panelMenuOpen: false,
};
onMenuToggle = event => {
event.stopPropagation();
this.setState(prevState => ({
panelMenuOpen: !prevState.panelMenuOpen,
}));
};
closeMenu = () => {
this.setState({
panelMenuOpen: false,
});
};
render() { render() {
const isFullscreen = false; const isFullscreen = false;
const isLoading = false; const isLoading = false;
...@@ -32,14 +55,19 @@ export class PanelHeader extends PureComponent<Props> { ...@@ -32,14 +55,19 @@ export class PanelHeader extends PureComponent<Props> {
</span> </span>
)} )}
<div className="panel-title-container"> <div className="panel-title-container" onClick={this.onMenuToggle}>
<div className="panel-title"> <div className="panel-title">
<span className="icon-gf panel-alert-icon" /> <span className="icon-gf panel-alert-icon" />
<span className="panel-title-text" data-toggle="dropdown"> <span className="panel-title-text">
{panel.title} <span className="fa fa-caret-down panel-menu-toggle" /> {panel.title} <span className="fa fa-caret-down panel-menu-toggle" />
</span> </span>
<PanelHeaderMenu panel={panel} dashboard={dashboard} /> {this.state.panelMenuOpen && (
<ClickOutsideWrapper onClick={this.closeMenu}>
<PanelHeaderMenu panel={panel} dashboard={dashboard} />
</ClickOutsideWrapper>
)}
{timeInfo && ( {timeInfo && (
<span className="panel-time-info"> <span className="panel-time-info">
<i className="fa fa-clock-o" /> {timeInfo} <i className="fa fa-clock-o" /> {timeInfo}
......
...@@ -35,6 +35,7 @@ export class PanelHeaderMenu extends PureComponent<Props> { ...@@ -35,6 +35,7 @@ export class PanelHeaderMenu extends PureComponent<Props> {
render() { render() {
const { dashboard, panel } = this.props; const { dashboard, panel } = this.props;
const menu = getPanelMenu(dashboard, panel); const menu = getPanelMenu(dashboard, panel);
return <div className="panel-menu-container dropdown">{this.renderItems(menu)}</div>;
return <div className="panel-menu-container dropdown open">{this.renderItems(menu)}</div>;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment