import React, { PureComponent } from 'react'; import classNames from 'classnames'; import { QueriesTab } from './QueriesTab'; import { VizTypePicker } from './VizTypePicker'; import { store } from 'app/store/store'; import { updateLocation } from 'app/core/actions'; import { PanelModel } from '../panel_model'; import { DashboardModel } from '../dashboard_model'; import { PanelPlugin, PluginExports } from 'app/types/plugins'; interface PanelEditorProps { panel: PanelModel; dashboard: DashboardModel; panelType: string; pluginExports: PluginExports; onTypeChanged: (newType: PanelPlugin) => void; } interface PanelEditorTab { id: string; text: string; icon: string; } export class PanelEditor extends PureComponent { tabs: PanelEditorTab[]; constructor(props) { super(props); this.tabs = [ { id: 'queries', text: 'Queries', icon: 'fa fa-database' }, { id: 'visualization', text: 'Visualization', icon: 'fa fa-line-chart' }, ]; } renderQueriesTab() { return ; } renderPanelOptions() { const { pluginExports, panel } = this.props; if (pluginExports.PanelOptionsComponent) { const OptionsComponent = pluginExports.PanelOptionsComponent; return ; } else { return

Visualization has no options

; } } onPanelOptionsChanged = (options: any) => { this.props.panel.updateOptions(options); this.forceUpdate(); }; renderVizTab() { return (
Options
{this.renderPanelOptions()}
); } onChangeTab = (tab: PanelEditorTab) => { store.dispatch( updateLocation({ query: { tab: tab.id }, partial: true, }) ); this.forceUpdate(); }; render() { const { location } = store.getState(); const activeTab = location.query.tab || 'queries'; return (
    {this.tabs.map(tab => { return ; })}
{activeTab === 'queries' && this.renderQueriesTab()} {activeTab === 'visualization' && this.renderVizTab()}
); } } interface TabItemParams { tab: PanelEditorTab; activeTab: string; onClick: (tab: PanelEditorTab) => void; } function TabItem({ tab, activeTab, onClick }: TabItemParams) { const tabClasses = classNames({ 'gf-tabs-link': true, active: activeTab === tab.id, }); return (
  • onClick(tab)}> {tab.text}
  • ); }