import React, { PureComponent } from 'react'; import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem'; import { store } from 'app/store/configureStore'; import { updateLocation } from 'app/core/actions'; import { removePanel, duplicatePanel, copyPanel } from 'app/features/dashboard/utils/panel'; import appEvents from 'app/core/app_events'; export interface PanelHeaderMenuProps { panelId: number; dashboard: DashboardModel; } export class PanelHeaderMenu extends PureComponent { getPanel = () => { // Pass in panel as prop instead? const { panelId, dashboard } = this.props; const panelInfo = dashboard.getPanelInfoById(panelId); return panelInfo.panel; }; 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 = () => { const { dashboard } = this.props; const panel = this.getPanel(); removePanel(dashboard, panel, true); }; onSharePanel = () => { const { dashboard } = this.props; const panel = this.getPanel(); appEvents.emit('show-modal', { src: 'public/app/features/dashboard/partials/shareModal.html', model: { panel: panel, dashboard: dashboard, }, }); }; onDuplicatePanel = () => { const { dashboard } = this.props; const panel = this.getPanel(); duplicatePanel(dashboard, panel); }; onCopyPanel = () => { const panel = this.getPanel(); copyPanel(panel); }; render() { return (
); } }