mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
wip
This commit is contained in:
parent
7161b2dc9b
commit
21e1d7b05b
@ -5,7 +5,7 @@ import { FadeIn } from 'app/core/components/Animations/FadeIn';
|
|||||||
interface Props {
|
interface Props {
|
||||||
children: JSX.Element;
|
children: JSX.Element;
|
||||||
heading: string;
|
heading: string;
|
||||||
renderToolbar?: () => JSX.Element;
|
renderToolbar?: () => JSX.Element | JSX.Element[];
|
||||||
toolbarItems?: EditorToolBarView[];
|
toolbarItems?: EditorToolBarView[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ export class VisualizationTab extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isVizPickerOpen: false,
|
isVizPickerOpen: false,
|
||||||
|
searchQuery: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,8 +139,16 @@ export class VisualizationTab extends PureComponent<Props, State> {
|
|||||||
this.setState({ isVizPickerOpen: true });
|
this.setState({ isVizPickerOpen: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
renderToolbar = () => {
|
onSearchQueryChange = evt => {
|
||||||
|
const value = evt.target.value;
|
||||||
|
this.setState({
|
||||||
|
searchQuery: value,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
renderToolbar = (): JSX.Element => {
|
||||||
const { plugin } = this.props;
|
const { plugin } = this.props;
|
||||||
|
const { searchQuery } = this.state;
|
||||||
|
|
||||||
if (this.state.isVizPickerOpen) {
|
if (this.state.isVizPickerOpen) {
|
||||||
return (
|
return (
|
||||||
@ -148,6 +157,8 @@ export class VisualizationTab extends PureComponent<Props, State> {
|
|||||||
type="text"
|
type="text"
|
||||||
className="gf-form-input width-13"
|
className="gf-form-input width-13"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
|
onChange={this.onSearchQueryChange}
|
||||||
|
value={searchQuery}
|
||||||
ref={elem => (this.searchInput = elem)}
|
ref={elem => (this.searchInput = elem)}
|
||||||
/>
|
/>
|
||||||
<i className="gf-form-input-icon fa fa-search" />
|
<i className="gf-form-input-icon fa fa-search" />
|
||||||
@ -164,9 +175,14 @@ export class VisualizationTab extends PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onTypeChanged = (plugin: PanelPlugin) => {
|
||||||
|
// this.setState({ isVizPickerOpen: false });
|
||||||
|
this.props.onTypeChanged(plugin);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { plugin, onTypeChanged } = this.props;
|
const { plugin } = this.props;
|
||||||
const { isVizPickerOpen } = this.state;
|
const { isVizPickerOpen, searchQuery } = this.state;
|
||||||
|
|
||||||
const panelHelp = {
|
const panelHelp = {
|
||||||
title: '',
|
title: '',
|
||||||
@ -176,7 +192,7 @@ export class VisualizationTab extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<EditorTabBody heading="Visualization" renderToolbar={this.renderToolbar} toolbarItems={[panelHelp]}>
|
<EditorTabBody heading="Visualization" renderToolbar={this.renderToolbar} toolbarItems={[panelHelp]}>
|
||||||
{isVizPickerOpen && <VizTypePicker current={plugin} onTypeChanged={onTypeChanged} />}
|
{isVizPickerOpen && <VizTypePicker current={plugin} onTypeChanged={this.onTypeChanged} searchQuery={searchQuery} />}
|
||||||
{this.renderPanelOptions()}
|
{this.renderPanelOptions()}
|
||||||
</EditorTabBody>
|
</EditorTabBody>
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,6 @@ import _ from 'lodash';
|
|||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
import { PanelPlugin } from 'app/types/plugins';
|
import { PanelPlugin } from 'app/types/plugins';
|
||||||
import VizTypePickerPlugin from './VizTypePickerPlugin';
|
import VizTypePickerPlugin from './VizTypePickerPlugin';
|
||||||
import KeyboardNavigation, { KeyboardNavigationProps } from './KeyboardNavigation';
|
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
current: PanelPlugin;
|
current: PanelPlugin;
|
||||||
@ -12,16 +11,12 @@ export interface Props {
|
|||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class VizTypePicker extends PureComponent<Props, State> {
|
export class VizTypePicker extends PureComponent<Props> {
|
||||||
searchInput: HTMLElement;
|
searchInput: HTMLElement;
|
||||||
pluginList = this.getPanelPlugins('');
|
pluginList = this.getPanelPlugins('');
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
|
||||||
searchQuery: '',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get maxSelectedIndex() {
|
get maxSelectedIndex() {
|
||||||
@ -29,12 +24,6 @@ export class VizTypePicker extends PureComponent<Props, State> {
|
|||||||
return filteredPluginList.length - 1;
|
return filteredPluginList.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.searchInput.focus();
|
|
||||||
}, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
getPanelPlugins(filter): PanelPlugin[] {
|
getPanelPlugins(filter): PanelPlugin[] {
|
||||||
const panels = _.chain(config.panels)
|
const panels = _.chain(config.panels)
|
||||||
.filter({ hideFromList: false })
|
.filter({ hideFromList: false })
|
||||||
@ -45,27 +34,23 @@ export class VizTypePicker extends PureComponent<Props, State> {
|
|||||||
return _.sortBy(panels, 'sort');
|
return _.sortBy(panels, 'sort');
|
||||||
}
|
}
|
||||||
|
|
||||||
renderVizPlugin = (plugin: PanelPlugin, index: number, keyNavProps: KeyboardNavigationProps) => {
|
renderVizPlugin = (plugin: PanelPlugin, index: number) => {
|
||||||
const { onTypeChanged } = this.props;
|
const { onTypeChanged } = this.props;
|
||||||
const { selected, onMouseEnter } = keyNavProps;
|
|
||||||
const isSelected = selected === index;
|
|
||||||
const isCurrent = plugin.id === this.props.current.id;
|
const isCurrent = plugin.id === this.props.current.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VizTypePickerPlugin
|
<VizTypePickerPlugin
|
||||||
key={plugin.id}
|
key={plugin.id}
|
||||||
isSelected={isSelected}
|
|
||||||
isCurrent={isCurrent}
|
isCurrent={isCurrent}
|
||||||
plugin={plugin}
|
plugin={plugin}
|
||||||
onMouseEnter={() => {
|
isSelected={false}
|
||||||
onMouseEnter(index);
|
|
||||||
}}
|
|
||||||
onClick={() => onTypeChanged(plugin)}
|
onClick={() => onTypeChanged(plugin)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
getFilteredPluginList = (): PanelPlugin[] => {
|
getFilteredPluginList = (): PanelPlugin[] => {
|
||||||
const { searchQuery } = this.state;
|
const { searchQuery } = this.props;
|
||||||
const regex = new RegExp(searchQuery, 'i');
|
const regex = new RegExp(searchQuery, 'i');
|
||||||
const pluginList = this.pluginList;
|
const pluginList = this.pluginList;
|
||||||
|
|
||||||
@ -76,57 +61,11 @@ export class VizTypePicker extends PureComponent<Props, State> {
|
|||||||
return filtered;
|
return filtered;
|
||||||
};
|
};
|
||||||
|
|
||||||
onSearchQueryChange = evt => {
|
|
||||||
const value = evt.target.value;
|
|
||||||
this.setState(prevState => ({
|
|
||||||
...prevState,
|
|
||||||
searchQuery: value,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
renderFilters = ({ onKeyDown, selected }: KeyboardNavigationProps) => {
|
|
||||||
const { searchQuery } = this.state;
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<label className="gf-form--has-input-icon">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="gf-form-input width-13"
|
|
||||||
placeholder=""
|
|
||||||
ref={elem => (this.searchInput = elem)}
|
|
||||||
onChange={this.onSearchQueryChange}
|
|
||||||
value={searchQuery}
|
|
||||||
onKeyDown={evt => {
|
|
||||||
onKeyDown(evt, this.maxSelectedIndex, () => {
|
|
||||||
const { onTypeChanged } = this.props;
|
|
||||||
const vizType = this.getFilteredPluginList()[selected];
|
|
||||||
onTypeChanged(vizType);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<i className="gf-form-input-icon fa fa-search" />
|
|
||||||
</label>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const filteredPluginList = this.getFilteredPluginList();
|
const filteredPluginList = this.getFilteredPluginList();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KeyboardNavigation
|
<div className="viz-picker">{filteredPluginList.map((plugin, index) => this.renderVizPlugin(plugin, index))}</div>
|
||||||
render={(keyNavProps: KeyboardNavigationProps) => (
|
|
||||||
<>
|
|
||||||
<div className="cta-form__bar">
|
|
||||||
{this.renderFilters(keyNavProps)}
|
|
||||||
<div className="gf-form--grow" />
|
|
||||||
</div>
|
|
||||||
<div className="viz-picker">
|
|
||||||
{filteredPluginList.map((plugin, index) => this.renderVizPlugin(plugin, index, keyNavProps))}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.viz-picker {
|
.viz-picker {
|
||||||
|
background: $panel-editor-toolbar-view-bg;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
margin: -40px -20px;
|
||||||
margin-bottom: 13px;
|
margin-bottom: 13px;
|
||||||
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.viz-picker__item {
|
.viz-picker__item {
|
||||||
|
Loading…
Reference in New Issue
Block a user