diff --git a/public/app/features/dashboard/dashgrid/VizTypePicker.tsx b/public/app/features/dashboard/dashgrid/VizTypePicker.tsx index 2dd1b0284b6..fc5e19a9d5c 100644 --- a/public/app/features/dashboard/dashgrid/VizTypePicker.tsx +++ b/public/app/features/dashboard/dashgrid/VizTypePicker.tsx @@ -11,21 +11,22 @@ interface Props { } interface State { - pluginList: PanelPlugin[]; + searchQuery: string; } export class VizTypePicker extends PureComponent { searchInput: HTMLElement; + pluginList = this.getPanelPlugins(''); constructor(props) { super(props); this.state = { - pluginList: this.getPanelPlugins(''), + searchQuery: '', }; } - getPanelPlugins(filter) { + getPanelPlugins(filter): PanelPlugin[] { const panels = _.chain(config.panels) .filter({ hideFromList: false }) .map(item => item) @@ -35,7 +36,7 @@ export class VizTypePicker extends PureComponent { return _.sortBy(panels, 'sort'); } - renderVizPlugin = (plugin, index) => { + renderVizPlugin = (plugin: PanelPlugin, index: number) => { const cssClass = classNames({ 'viz-picker__item': true, 'viz-picker__item--selected': plugin.id === this.props.current.id, @@ -55,7 +56,27 @@ export class VizTypePicker extends PureComponent { }, 300); } - renderFilters() { + getFilteredPluginList = (): PanelPlugin[] => { + const { searchQuery } = this.state; + const regex = new RegExp(searchQuery, 'i'); + const pluginList = this.pluginList; + + const filtered = pluginList.filter(item => { + return regex.test(item.name); + }); + + return filtered; + }; + + onSearchQueryChange = evt => { + const value = evt.target.value; + this.setState(prevState => ({ + ...prevState, + searchQuery: value, + })); + }; + + renderFilters = () => { return ( <> ); - } + }; render() { - const { pluginList } = this.state; + const filteredPluginList = this.getFilteredPluginList(); return ( <> @@ -81,7 +103,7 @@ export class VizTypePicker extends PureComponent {
-
{pluginList.map(this.renderVizPlugin)}
+
{filteredPluginList.map(this.renderVizPlugin)}
); }