Commit 27bbadce by Johannes Schill

feat: Add EmptySearchResult ui component and use it in VizTypePicker

parent b6305c2d
import React, { FC } from 'react';
export interface Props {
children: JSX.Element | string;
}
const EmptySearchResult: FC<Props> = ({ children }) => {
return (
<div className="empty-search-result">{children}</div>
);
};
export { EmptySearchResult };
.empty-search-result {
background-color: $empty-list-cta-bg;
padding: $spacer;
border-radius: $border-radius;
margin-bottom: $spacer*2;
}
\ No newline at end of file
...@@ -8,3 +8,4 @@ ...@@ -8,3 +8,4 @@
@import 'ColorPicker/ColorPicker'; @import 'ColorPicker/ColorPicker';
@import 'ValueMappingsEditor/ValueMappingsEditor'; @import 'ValueMappingsEditor/ValueMappingsEditor';
@import "FormField/FormField"; @import "FormField/FormField";
@import "EmptySearchResult/EmptySearchResult";
\ No newline at end of file
...@@ -23,3 +23,4 @@ export { PanelOptionsGrid } from './PanelOptionsGrid/PanelOptionsGrid'; ...@@ -23,3 +23,4 @@ export { PanelOptionsGrid } from './PanelOptionsGrid/PanelOptionsGrid';
export { ValueMappingsEditor } from './ValueMappingsEditor/ValueMappingsEditor'; export { ValueMappingsEditor } from './ValueMappingsEditor/ValueMappingsEditor';
export { Gauge } from './Gauge/Gauge'; export { Gauge } from './Gauge/Gauge';
export { Switch } from './Switch/Switch'; export { Switch } from './Switch/Switch';
export { EmptySearchResult } from './EmptySearchResult/EmptySearchResult';
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
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 { EmptySearchResult } from '@grafana/ui';
export interface Props { export interface Props {
current: PanelPlugin; current: PanelPlugin;
...@@ -14,9 +14,9 @@ export interface Props { ...@@ -14,9 +14,9 @@ export interface Props {
export class VizTypePicker extends PureComponent<Props> { export class VizTypePicker extends PureComponent<Props> {
searchInput: HTMLElement; searchInput: HTMLElement;
pluginList = this.getPanelPlugins(''); pluginList = this.getPanelPlugins;
constructor(props) { constructor(props: Props) {
super(props); super(props);
} }
...@@ -25,14 +25,13 @@ export class VizTypePicker extends PureComponent<Props> { ...@@ -25,14 +25,13 @@ export class VizTypePicker extends PureComponent<Props> {
return filteredPluginList.length - 1; return filteredPluginList.length - 1;
} }
getPanelPlugins(filter): PanelPlugin[] { get getPanelPlugins(): PanelPlugin[] {
const panels = _.chain(config.panels) const allPanels = config.panels;
.filter({ hideFromList: false })
.map(item => item)
.value();
// add sort by sort property return Object.keys(allPanels)
return _.sortBy(panels, 'sort'); .filter(key => allPanels[key]['hideFromList'] === false)
.map(key => allPanels[key])
.sort((a: PanelPlugin, b: PanelPlugin) => a.sort - b.sort);
} }
renderVizPlugin = (plugin: PanelPlugin, index: number) => { renderVizPlugin = (plugin: PanelPlugin, index: number) => {
...@@ -63,11 +62,13 @@ export class VizTypePicker extends PureComponent<Props> { ...@@ -63,11 +62,13 @@ export class VizTypePicker extends PureComponent<Props> {
render() { render() {
const filteredPluginList = this.getFilteredPluginList(); const filteredPluginList = this.getFilteredPluginList();
const hasResults = filteredPluginList.length > 0;
return ( return (
<div className="viz-picker"> <div className="viz-picker">
<div className="viz-picker-list"> <div className="viz-picker-list">
{filteredPluginList.map((plugin, index) => this.renderVizPlugin(plugin, index))} {hasResults ?
filteredPluginList.map((plugin, index) => this.renderVizPlugin(plugin, index))
: <EmptySearchResult>No panels matching your query were found</EmptySearchResult>}
</div> </div>
</div> </div>
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment