From 2feaad8b0d352ea57bfd790d90262e23abb9cc9f Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Sun, 9 Feb 2020 10:50:58 +0100 Subject: [PATCH] New Editor: add a tabs row for the query section (#22037) --- .../components/PanelEditor/PanelEditor.tsx | 62 +++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx index d8ca3636174..8d92e0f1073 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx @@ -1,6 +1,15 @@ import React, { PureComponent } from 'react'; import { GrafanaTheme, FieldConfigSource, PanelData, LoadingState, DefaultTimeRange, PanelEvents } from '@grafana/data'; -import { stylesFactory, Forms, FieldConfigEditor, CustomScrollbar, selectThemeVariant } from '@grafana/ui'; +import { + stylesFactory, + Forms, + FieldConfigEditor, + CustomScrollbar, + selectThemeVariant, + TabContent, + Tab, + TabsBar, +} from '@grafana/ui'; import { css, cx } from 'emotion'; import config from 'app/core/config'; @@ -83,6 +92,18 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { }; }); +enum EditorTab { + Query = 'query', + Alerts = 'alerts', + Transform = 'xform', +} + +const allTabs = [ + { tab: EditorTab.Query, label: 'Query', show: (panel: PanelModel) => true }, + { tab: EditorTab.Alerts, label: 'Alerts', show: (panel: PanelModel) => true }, + { tab: EditorTab.Transform, label: 'Transform', show: (panel: PanelModel) => true }, +]; + interface Props { dashboard: DashboardModel; sourcePanel: PanelModel; @@ -93,6 +114,7 @@ interface State { pluginLoadedCounter: number; panel: PanelModel; data: PanelData; + tab: EditorTab; } export class PanelEditor extends PureComponent { @@ -106,6 +128,7 @@ export class PanelEditor extends PureComponent { const panel = props.sourcePanel.getEditClone(); this.state = { panel, + tab: EditorTab.Query, pluginLoadedCounter: 0, data: { state: LoadingState.NotStarted, @@ -233,6 +256,37 @@ export class PanelEditor extends PureComponent { this.forceUpdate(); }; + renderBottomOptions() { + const { dashboard } = this.props; + const { panel, tab } = this.state; + + return ( +
+ + {allTabs.map(t => { + if (t.show(panel)) { + return ( + { + this.setState({ tab: t.tab }); + }} + /> + ); + } + return null; + })} + + + {tab === EditorTab.Query && } + {tab === EditorTab.Alerts &&
TODO: Show Alerts
} + {tab === EditorTab.Transform &&
TODO: Show Transform
} +
+
+ ); + } + render() { const { dashboard } = this.props; const { panel } = this.state; @@ -269,7 +323,7 @@ export class PanelEditor extends PureComponent { > { isInView={true} /> -
- -
+
{this.renderBottomOptions()}