import { css } from '@emotion/css'; import React, { FC } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { GrafanaTheme } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { ToolbarButton, ButtonGroup, useStyles } from '@grafana/ui'; import { StoreState } from 'app/types'; import { PanelModel } from '../../state'; import { getPanelPluginWithFallback } from '../../state/selectors'; import { setPanelEditorUIState, toggleVizPicker } from './state/reducers'; type Props = { panel: PanelModel; }; export const VisualizationButton: FC = ({ panel }) => { const styles = useStyles(getStyles); const dispatch = useDispatch(); const plugin = useSelector(getPanelPluginWithFallback(panel.type)); const isPanelOptionsVisible = useSelector((state: StoreState) => state.panelEditor.ui.isPanelOptionsVisible); const isVizPickerOpen = useSelector((state: StoreState) => state.panelEditor.isVizPickerOpen); const onToggleOpen = () => { dispatch(toggleVizPicker(!isVizPickerOpen)); }; const onToggleOptionsPane = () => { dispatch(setPanelEditorUIState({ isPanelOptionsVisible: !isPanelOptionsVisible })); }; if (!plugin) { return null; } return (
{plugin.meta.name}
); }; VisualizationButton.displayName = 'VisualizationTab'; const getStyles = (theme: GrafanaTheme) => { return { wrapper: css` display: flex; flex-direction: column; `, vizButton: css` text-align: left; `, }; };