Commit 2feaad8b by Ryan McKinley Committed by GitHub

New Editor: add a tabs row for the query section (#22037)

parent 66191f94
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { GrafanaTheme, FieldConfigSource, PanelData, LoadingState, DefaultTimeRange, PanelEvents } from '@grafana/data'; 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 { css, cx } from 'emotion';
import config from 'app/core/config'; import config from 'app/core/config';
...@@ -83,6 +92,18 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { ...@@ -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 { interface Props {
dashboard: DashboardModel; dashboard: DashboardModel;
sourcePanel: PanelModel; sourcePanel: PanelModel;
...@@ -93,6 +114,7 @@ interface State { ...@@ -93,6 +114,7 @@ interface State {
pluginLoadedCounter: number; pluginLoadedCounter: number;
panel: PanelModel; panel: PanelModel;
data: PanelData; data: PanelData;
tab: EditorTab;
} }
export class PanelEditor extends PureComponent<Props, State> { export class PanelEditor extends PureComponent<Props, State> {
...@@ -106,6 +128,7 @@ export class PanelEditor extends PureComponent<Props, State> { ...@@ -106,6 +128,7 @@ export class PanelEditor extends PureComponent<Props, State> {
const panel = props.sourcePanel.getEditClone(); const panel = props.sourcePanel.getEditClone();
this.state = { this.state = {
panel, panel,
tab: EditorTab.Query,
pluginLoadedCounter: 0, pluginLoadedCounter: 0,
data: { data: {
state: LoadingState.NotStarted, state: LoadingState.NotStarted,
...@@ -233,6 +256,37 @@ export class PanelEditor extends PureComponent<Props, State> { ...@@ -233,6 +256,37 @@ export class PanelEditor extends PureComponent<Props, State> {
this.forceUpdate(); this.forceUpdate();
}; };
renderBottomOptions() {
const { dashboard } = this.props;
const { panel, tab } = this.state;
return (
<div>
<TabsBar>
{allTabs.map(t => {
if (t.show(panel)) {
return (
<Tab
label={t.label}
active={tab === t.tab}
onChangeTab={() => {
this.setState({ tab: t.tab });
}}
/>
);
}
return null;
})}
</TabsBar>
<TabContent>
{tab === EditorTab.Query && <QueriesTab panel={panel} dashboard={dashboard} />}
{tab === EditorTab.Alerts && <div>TODO: Show Alerts</div>}
{tab === EditorTab.Transform && <div>TODO: Show Transform</div>}
</TabContent>
</div>
);
}
render() { render() {
const { dashboard } = this.props; const { dashboard } = this.props;
const { panel } = this.state; const { panel } = this.state;
...@@ -269,7 +323,7 @@ export class PanelEditor extends PureComponent<Props, State> { ...@@ -269,7 +323,7 @@ export class PanelEditor extends PureComponent<Props, State> {
> >
<SplitPane <SplitPane
split="horizontal" split="horizontal"
minSize={50} minSize={100}
primary="second" primary="second"
defaultSize="40%" defaultSize="40%"
resizerClassName={styles.resizerH} resizerClassName={styles.resizerH}
...@@ -286,9 +340,7 @@ export class PanelEditor extends PureComponent<Props, State> { ...@@ -286,9 +340,7 @@ export class PanelEditor extends PureComponent<Props, State> {
isInView={true} isInView={true}
/> />
</div> </div>
<div className={styles.noScrollPaneContent}> <div className={styles.noScrollPaneContent}>{this.renderBottomOptions()}</div>
<QueriesTab panel={panel} dashboard={dashboard} />
</div>
</SplitPane> </SplitPane>
<div className={styles.noScrollPaneContent}> <div className={styles.noScrollPaneContent}>
<CustomScrollbar> <CustomScrollbar>
......
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