import React, { PureComponent } from 'react'; import classNames from 'classnames'; import { QueriesTab } from './QueriesTab'; import { VizTypePicker } from './VizTypePicker'; import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar'; import { store } from 'app/store/configureStore'; import { updateLocation } from 'app/core/actions'; import { PanelModel } from '../panel_model'; import { DashboardModel } from '../dashboard_model'; import { PanelPlugin } from 'app/types/plugins'; interface PanelEditorProps { panel: PanelModel; dashboard: DashboardModel; plugin: PanelPlugin; 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' }, { id: 'alert', text: 'Alert', icon: 'gicon gicon-alert' }, ]; } renderQueriesTab() { return ; } renderPanelOptions() { const { plugin, panel } = this.props; const { PanelOptionsComponent } = plugin.exports; if (PanelOptionsComponent) { return ; } else { return

Visualization has no options

; } } onPanelOptionsChanged = (options: any) => { this.props.panel.updateOptions(options); this.forceUpdate(); }; renderVizTab() { return (
{this.renderPanelOptions()}
); } onChangeTab = (tab: PanelEditorTab) => { store.dispatch( updateLocation({ query: { tab: tab.id }, partial: true, }) ); this.forceUpdate(); }; onClose = () => { store.dispatch( updateLocation({ query: { tab: null, fullscreen: null, edit: null }, partial: true, }) ); }; render() { const { location } = store.getState(); const activeTab = location.query.tab || 'queries'; return (

Edit Panel

{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({ 'panel-editor__aside-item': true, active: activeTab === tab.id, }); return ( onClick(tab)}> {tab.text} ); }