2020-04-02 04:09:14 +08:00
|
|
|
import React, { FC, useState } from 'react';
|
2020-02-12 19:54:58 +08:00
|
|
|
import { css } from 'emotion';
|
|
|
|
|
import { GrafanaTheme, PanelPlugin, PanelPluginMeta } from '@grafana/data';
|
2020-04-03 16:04:19 +08:00
|
|
|
import { CustomScrollbar, useTheme, stylesFactory, Icon, Input } from '@grafana/ui';
|
2020-02-12 19:54:58 +08:00
|
|
|
import { changePanelPlugin } from '../../state/actions';
|
|
|
|
|
import { StoreState } from 'app/types';
|
|
|
|
|
import { PanelModel } from '../../state/PanelModel';
|
|
|
|
|
import { connect, MapStateToProps, MapDispatchToProps } from 'react-redux';
|
|
|
|
|
import { VizTypePicker } from '../../panel_editor/VizTypePicker';
|
|
|
|
|
|
|
|
|
|
interface OwnProps {
|
|
|
|
|
panel: PanelModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ConnectedProps {
|
|
|
|
|
plugin?: PanelPlugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DispatchProps {
|
|
|
|
|
changePanelPlugin: typeof changePanelPlugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Props = OwnProps & ConnectedProps & DispatchProps;
|
|
|
|
|
|
|
|
|
|
export const VisualizationTabUnconnected: FC<Props> = ({ panel, plugin, changePanelPlugin }) => {
|
2020-04-02 04:09:14 +08:00
|
|
|
const [searchQuery, setSearchQuery] = useState('');
|
2020-02-12 19:54:58 +08:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const styles = getStyles(theme);
|
|
|
|
|
|
|
|
|
|
if (!plugin) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onPluginTypeChange = (meta: PanelPluginMeta) => {
|
|
|
|
|
changePanelPlugin(panel, meta.id);
|
|
|
|
|
};
|
2020-04-03 14:39:57 +08:00
|
|
|
const suffix =
|
|
|
|
|
searchQuery !== '' ? (
|
|
|
|
|
<span className={styles.searchClear} onClick={() => setSearchQuery('')}>
|
|
|
|
|
<Icon name="times" />
|
|
|
|
|
Clear filter
|
|
|
|
|
</span>
|
|
|
|
|
) : null;
|
2020-02-12 19:54:58 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.wrapper}>
|
2020-04-02 04:09:14 +08:00
|
|
|
<div className={styles.search}>
|
2020-04-03 16:04:19 +08:00
|
|
|
<Input
|
2020-04-02 04:09:14 +08:00
|
|
|
value={searchQuery}
|
|
|
|
|
onChange={e => setSearchQuery(e.currentTarget.value)}
|
|
|
|
|
prefix={<Icon name="filter" className={styles.icon} />}
|
2020-04-03 14:39:57 +08:00
|
|
|
suffix={suffix}
|
2020-04-02 04:09:14 +08:00
|
|
|
placeholder="Filter visualisations"
|
|
|
|
|
autoFocus
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.visList}>
|
|
|
|
|
<CustomScrollbar>
|
|
|
|
|
<VizTypePicker
|
|
|
|
|
current={plugin.meta}
|
|
|
|
|
onTypeChange={onPluginTypeChange}
|
|
|
|
|
searchQuery={searchQuery}
|
|
|
|
|
onClose={() => {}}
|
|
|
|
|
/>
|
|
|
|
|
</CustomScrollbar>
|
|
|
|
|
</div>
|
2020-02-12 19:54:58 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
|
|
|
|
return {
|
2020-04-02 04:09:14 +08:00
|
|
|
icon: css`
|
|
|
|
|
color: ${theme.colors.gray33};
|
|
|
|
|
`,
|
2020-02-12 19:54:58 +08:00
|
|
|
wrapper: css`
|
2020-04-02 04:09:14 +08:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
max-height: 100%;
|
|
|
|
|
`,
|
|
|
|
|
search: css`
|
|
|
|
|
padding: ${theme.spacing.sm} ${theme.spacing.md};
|
|
|
|
|
flex-grow: 0;
|
|
|
|
|
flex-shrink: 1;
|
|
|
|
|
margin-bottom: ${theme.spacing.sm};
|
|
|
|
|
`,
|
2020-04-03 14:39:57 +08:00
|
|
|
searchClear: css`
|
|
|
|
|
color: ${theme.colors.gray60};
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
`,
|
2020-04-02 04:09:14 +08:00
|
|
|
visList: css`
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
padding-left: ${theme.spacing.md};
|
2020-02-12 19:54:58 +08:00
|
|
|
`,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state, props) => {
|
|
|
|
|
return {
|
|
|
|
|
plugin: state.plugins.panels[props.panel.type],
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = { changePanelPlugin };
|
|
|
|
|
|
|
|
|
|
export const VisualizationTab = connect(mapStateToProps, mapDispatchToProps)(VisualizationTabUnconnected);
|