From 21e1d7b05b29f0cb35309a96b3d1aeae1b85c6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 12 Dec 2018 11:24:18 +0100 Subject: [PATCH] wip --- .../dashboard/dashgrid/EditorTabBody.tsx | 2 +- .../dashboard/dashgrid/VisualizationTab.tsx | 24 +++++- .../dashboard/dashgrid/VizTypePicker.tsx | 73 ++----------------- public/sass/components/_panel_editor.scss | 3 + 4 files changed, 30 insertions(+), 72 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/EditorTabBody.tsx b/public/app/features/dashboard/dashgrid/EditorTabBody.tsx index 0603139ff65..e76edb1840a 100644 --- a/public/app/features/dashboard/dashgrid/EditorTabBody.tsx +++ b/public/app/features/dashboard/dashgrid/EditorTabBody.tsx @@ -5,7 +5,7 @@ import { FadeIn } from 'app/core/components/Animations/FadeIn'; interface Props { children: JSX.Element; heading: string; - renderToolbar?: () => JSX.Element; + renderToolbar?: () => JSX.Element | JSX.Element[]; toolbarItems?: EditorToolBarView[]; } diff --git a/public/app/features/dashboard/dashgrid/VisualizationTab.tsx b/public/app/features/dashboard/dashgrid/VisualizationTab.tsx index 7411c59a91e..e33ba4355c0 100644 --- a/public/app/features/dashboard/dashgrid/VisualizationTab.tsx +++ b/public/app/features/dashboard/dashgrid/VisualizationTab.tsx @@ -36,6 +36,7 @@ export class VisualizationTab extends PureComponent { this.state = { isVizPickerOpen: false, + searchQuery: '', }; } @@ -138,8 +139,16 @@ export class VisualizationTab extends PureComponent { this.setState({ isVizPickerOpen: true }); }; - renderToolbar = () => { + onSearchQueryChange = evt => { + const value = evt.target.value; + this.setState({ + searchQuery: value, + }); + }; + + renderToolbar = (): JSX.Element => { const { plugin } = this.props; + const { searchQuery } = this.state; if (this.state.isVizPickerOpen) { return ( @@ -148,6 +157,8 @@ export class VisualizationTab extends PureComponent { type="text" className="gf-form-input width-13" placeholder="" + onChange={this.onSearchQueryChange} + value={searchQuery} ref={elem => (this.searchInput = elem)} /> @@ -164,9 +175,14 @@ export class VisualizationTab extends PureComponent { } }; + onTypeChanged = (plugin: PanelPlugin) => { + // this.setState({ isVizPickerOpen: false }); + this.props.onTypeChanged(plugin); + }; + render() { - const { plugin, onTypeChanged } = this.props; - const { isVizPickerOpen } = this.state; + const { plugin } = this.props; + const { isVizPickerOpen, searchQuery } = this.state; const panelHelp = { title: '', @@ -176,7 +192,7 @@ export class VisualizationTab extends PureComponent { return ( - {isVizPickerOpen && } + {isVizPickerOpen && } {this.renderPanelOptions()} ); diff --git a/public/app/features/dashboard/dashgrid/VizTypePicker.tsx b/public/app/features/dashboard/dashgrid/VizTypePicker.tsx index d246c069f22..c1f5f0fac7a 100644 --- a/public/app/features/dashboard/dashgrid/VizTypePicker.tsx +++ b/public/app/features/dashboard/dashgrid/VizTypePicker.tsx @@ -4,7 +4,6 @@ import _ from 'lodash'; import config from 'app/core/config'; import { PanelPlugin } from 'app/types/plugins'; import VizTypePickerPlugin from './VizTypePickerPlugin'; -import KeyboardNavigation, { KeyboardNavigationProps } from './KeyboardNavigation'; export interface Props { current: PanelPlugin; @@ -12,16 +11,12 @@ export interface Props { searchQuery: string; } -export class VizTypePicker extends PureComponent { +export class VizTypePicker extends PureComponent { searchInput: HTMLElement; pluginList = this.getPanelPlugins(''); constructor(props) { super(props); - - this.state = { - searchQuery: '', - }; } get maxSelectedIndex() { @@ -29,12 +24,6 @@ export class VizTypePicker extends PureComponent { return filteredPluginList.length - 1; } - componentDidMount() { - setTimeout(() => { - this.searchInput.focus(); - }, 300); - } - getPanelPlugins(filter): PanelPlugin[] { const panels = _.chain(config.panels) .filter({ hideFromList: false }) @@ -45,27 +34,23 @@ export class VizTypePicker extends PureComponent { return _.sortBy(panels, 'sort'); } - renderVizPlugin = (plugin: PanelPlugin, index: number, keyNavProps: KeyboardNavigationProps) => { + renderVizPlugin = (plugin: PanelPlugin, index: number) => { const { onTypeChanged } = this.props; - const { selected, onMouseEnter } = keyNavProps; - const isSelected = selected === index; const isCurrent = plugin.id === this.props.current.id; + return ( { - onMouseEnter(index); - }} + isSelected={false} onClick={() => onTypeChanged(plugin)} /> ); }; getFilteredPluginList = (): PanelPlugin[] => { - const { searchQuery } = this.state; + const { searchQuery } = this.props; const regex = new RegExp(searchQuery, 'i'); const pluginList = this.pluginList; @@ -76,57 +61,11 @@ export class VizTypePicker extends PureComponent { return filtered; }; - onSearchQueryChange = evt => { - const value = evt.target.value; - this.setState(prevState => ({ - ...prevState, - searchQuery: value, - })); - }; - - renderFilters = ({ onKeyDown, selected }: KeyboardNavigationProps) => { - const { searchQuery } = this.state; - return ( - <> - - - ); - }; - render() { const filteredPluginList = this.getFilteredPluginList(); return ( - ( - <> -
- {this.renderFilters(keyNavProps)} -
-
-
- {filteredPluginList.map((plugin, index) => this.renderVizPlugin(plugin, index, keyNavProps))} -
- - )} - /> +
{filteredPluginList.map((plugin, index) => this.renderVizPlugin(plugin, index))}
); } } diff --git a/public/sass/components/_panel_editor.scss b/public/sass/components/_panel_editor.scss index d90cf098885..c7d69766633 100644 --- a/public/sass/components/_panel_editor.scss +++ b/public/sass/components/_panel_editor.scss @@ -133,9 +133,12 @@ } .viz-picker { + background: $panel-editor-toolbar-view-bg; display: flex; flex-wrap: wrap; + margin: -40px -20px; margin-bottom: 13px; + padding: 20px; } .viz-picker__item {