2018-10-25 05:47:09 -05:00
|
|
|
|
import React, { PureComponent } from 'react';
|
2018-10-25 06:58:26 -05:00
|
|
|
|
import { DashboardModel } from 'app/features/dashboard/dashboard_model';
|
2018-10-25 05:47:09 -05:00
|
|
|
|
import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem';
|
|
|
|
|
import { store } from 'app/store/configureStore';
|
|
|
|
|
import { updateLocation } from 'app/core/actions';
|
2018-10-31 07:43:21 -05:00
|
|
|
|
import {
|
|
|
|
|
removePanel,
|
|
|
|
|
duplicatePanel,
|
|
|
|
|
copyPanel,
|
|
|
|
|
editPanelJson,
|
|
|
|
|
sharePanel,
|
|
|
|
|
toggleLegend,
|
|
|
|
|
} from 'app/features/dashboard/utils/panel';
|
2018-10-25 05:47:09 -05:00
|
|
|
|
|
|
|
|
|
export interface PanelHeaderMenuProps {
|
|
|
|
|
panelId: number;
|
2018-10-25 06:58:26 -05:00
|
|
|
|
dashboard: DashboardModel;
|
2018-10-25 05:47:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
|
2018-10-30 08:21:47 -05:00
|
|
|
|
getPanel = () => {
|
|
|
|
|
// Pass in panel as prop instead?
|
|
|
|
|
const { panelId, dashboard } = this.props;
|
|
|
|
|
const panelInfo = dashboard.getPanelInfoById(panelId);
|
|
|
|
|
return panelInfo.panel;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-25 05:47:09 -05:00
|
|
|
|
onEditPanel = () => {
|
|
|
|
|
store.dispatch(
|
|
|
|
|
updateLocation({
|
|
|
|
|
query: {
|
|
|
|
|
panelId: this.props.panelId,
|
|
|
|
|
edit: true,
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onViewPanel = () => {
|
|
|
|
|
store.dispatch(
|
|
|
|
|
updateLocation({
|
|
|
|
|
query: {
|
|
|
|
|
panelId: this.props.panelId,
|
|
|
|
|
edit: false,
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onRemovePanel = () => {
|
2018-10-30 08:21:47 -05:00
|
|
|
|
const { dashboard } = this.props;
|
|
|
|
|
const panel = this.getPanel();
|
|
|
|
|
removePanel(dashboard, panel, true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onSharePanel = () => {
|
|
|
|
|
const { dashboard } = this.props;
|
|
|
|
|
const panel = this.getPanel();
|
|
|
|
|
|
2018-10-30 10:39:08 -05:00
|
|
|
|
sharePanel(dashboard, panel);
|
2018-10-25 05:47:09 -05:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-30 08:38:18 -05:00
|
|
|
|
onDuplicatePanel = () => {
|
|
|
|
|
const { dashboard } = this.props;
|
|
|
|
|
const panel = this.getPanel();
|
|
|
|
|
|
|
|
|
|
duplicatePanel(dashboard, panel);
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-30 08:53:04 -05:00
|
|
|
|
onCopyPanel = () => {
|
|
|
|
|
const panel = this.getPanel();
|
|
|
|
|
copyPanel(panel);
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-30 10:07:59 -05:00
|
|
|
|
onEditPanelJson = () => {
|
|
|
|
|
const { dashboard } = this.props;
|
|
|
|
|
const panel = this.getPanel();
|
|
|
|
|
editPanelJson(dashboard, panel);
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-31 07:43:21 -05:00
|
|
|
|
onToggleLegend = () => {
|
|
|
|
|
const panel = this.getPanel();
|
|
|
|
|
toggleLegend(panel);
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-25 05:47:09 -05:00
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="panel-menu-container dropdown">
|
|
|
|
|
<ul className="dropdown-menu dropdown-menu--menu panel-menu" role="menu">
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="View"
|
|
|
|
|
iconClassName="fa fa-fw fa-eye"
|
|
|
|
|
handleClick={this.onViewPanel}
|
|
|
|
|
shortcut="v"
|
|
|
|
|
/>
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="Edit"
|
|
|
|
|
iconClassName="fa fa-fw fa-edit"
|
|
|
|
|
handleClick={this.onEditPanel}
|
|
|
|
|
shortcut="e"
|
|
|
|
|
/>
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="Share"
|
|
|
|
|
iconClassName="fa fa-fw fa-share"
|
2018-10-30 08:21:47 -05:00
|
|
|
|
handleClick={this.onSharePanel}
|
2018-10-25 05:47:09 -05:00
|
|
|
|
shortcut="p s"
|
|
|
|
|
/>
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.SubMenu}
|
|
|
|
|
text="More ..."
|
|
|
|
|
iconClassName="fa fa-fw fa-cube"
|
2018-10-30 08:53:04 -05:00
|
|
|
|
handleClick={null}
|
2018-10-25 05:47:09 -05:00
|
|
|
|
>
|
|
|
|
|
<ul className="dropdown-menu dropdown-menu--menu panel-menu">
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="Duplicate"
|
|
|
|
|
iconClassName=""
|
2018-10-30 08:38:18 -05:00
|
|
|
|
handleClick={this.onDuplicatePanel}
|
2018-10-25 05:47:09 -05:00
|
|
|
|
shortcut="p d"
|
|
|
|
|
/>
|
2018-10-30 08:53:04 -05:00
|
|
|
|
<PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={this.onCopyPanel} />
|
2018-10-30 10:07:59 -05:00
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="Panel JSON"
|
|
|
|
|
handleClick={this.onEditPanelJson}
|
|
|
|
|
/>
|
2018-10-25 05:47:09 -05:00
|
|
|
|
<PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Export CSV" handleClick={() => {}} />
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="Toggle legend"
|
2018-10-31 07:43:21 -05:00
|
|
|
|
handleClick={this.onToggleLegend}
|
2018-10-25 05:47:09 -05:00
|
|
|
|
shortcut="p l"
|
|
|
|
|
/>
|
|
|
|
|
</ul>
|
|
|
|
|
</PanelHeaderMenuItem>
|
|
|
|
|
<PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Divider} />
|
|
|
|
|
<PanelHeaderMenuItem
|
|
|
|
|
type={PanelHeaderMenuItemTypes.Link}
|
|
|
|
|
text="Remove"
|
|
|
|
|
iconClassName="fa fa-fw fa-trash"
|
|
|
|
|
handleClick={this.onRemovePanel}
|
|
|
|
|
shortcut="p r"
|
|
|
|
|
/>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|