mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* feat(dashboard): introduce selector with fallback for unknown plugin * refactor(dashboard): replace redux connect with redux hooks * fix(dashboard): add a fallback for vizpicker when a panel plugin cannot be found * feat(dashboard): add an icon for fallback plugins for vizpicker * refactor(dashboard): prefer HOF selector
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import React, { FC } from 'react';
|
|
import { css } from '@emotion/css';
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
import { ToolbarButton, ButtonGroup, useStyles } from '@grafana/ui';
|
|
import { StoreState } from 'app/types';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { setPanelEditorUIState, toggleVizPicker } from './state/reducers';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { PanelModel } from '../../state';
|
|
import { getPanelPluginWithFallback } from '../../state/selectors';
|
|
|
|
type Props = {
|
|
panel: PanelModel;
|
|
};
|
|
|
|
export const VisualizationButton: FC<Props> = ({ 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 (
|
|
<div className={styles.wrapper}>
|
|
<ButtonGroup>
|
|
<ToolbarButton
|
|
className={styles.vizButton}
|
|
tooltip="Click to change visualization"
|
|
imgSrc={plugin.meta.info.logos.small}
|
|
isOpen={isVizPickerOpen}
|
|
onClick={onToggleOpen}
|
|
aria-label={selectors.components.PanelEditor.toggleVizPicker}
|
|
fullWidth
|
|
>
|
|
{plugin.meta.name}
|
|
</ToolbarButton>
|
|
<ToolbarButton
|
|
tooltip={isPanelOptionsVisible ? 'Close options pane' : 'Show options pane'}
|
|
icon={isPanelOptionsVisible ? 'angle-right' : 'angle-left'}
|
|
onClick={onToggleOptionsPane}
|
|
aria-label={selectors.components.PanelEditor.toggleVizOptions}
|
|
/>
|
|
</ButtonGroup>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
VisualizationButton.displayName = 'VisualizationTab';
|
|
|
|
const getStyles = (theme: GrafanaTheme) => {
|
|
return {
|
|
wrapper: css`
|
|
display: flex;
|
|
flex-direction: column;
|
|
`,
|
|
vizButton: css`
|
|
text-align: left;
|
|
`,
|
|
};
|
|
};
|