2020-02-12 03:42:57 -06:00
|
|
|
import React from 'react';
|
|
|
|
import { config } from 'app/core/config';
|
2020-02-09 08:39:46 -06:00
|
|
|
import { css } from 'emotion';
|
2020-02-12 03:42:57 -06:00
|
|
|
import { TabsBar, Tab, stylesFactory, TabContent, TransformationsEditor } from '@grafana/ui';
|
|
|
|
import { DataTransformerConfig, LoadingState, PanelData } from '@grafana/data';
|
|
|
|
import { PanelEditorTab, PanelEditorTabId } from './types';
|
2020-02-09 08:39:46 -06:00
|
|
|
import { DashboardModel } from '../../state';
|
|
|
|
import { QueriesTab } from '../../panel_editor/QueriesTab';
|
|
|
|
import { PanelModel } from '../../state/PanelModel';
|
2020-02-09 10:39:26 -06:00
|
|
|
import { AlertTab } from 'app/features/alerting/AlertTab';
|
2020-02-12 05:54:58 -06:00
|
|
|
import { VisualizationTab } from './VisualizationTab';
|
2020-02-09 08:39:46 -06:00
|
|
|
|
|
|
|
interface PanelEditorTabsProps {
|
|
|
|
panel: PanelModel;
|
|
|
|
dashboard: DashboardModel;
|
2020-02-12 03:42:57 -06:00
|
|
|
tabs: PanelEditorTab[];
|
|
|
|
onChangeTab: (tab: PanelEditorTab) => void;
|
|
|
|
data: PanelData;
|
2020-02-09 08:39:46 -06:00
|
|
|
}
|
|
|
|
|
2020-02-12 03:42:57 -06:00
|
|
|
export const PanelEditorTabs: React.FC<PanelEditorTabsProps> = ({ panel, dashboard, tabs, data, onChangeTab }) => {
|
|
|
|
const styles = getPanelEditorTabsStyles();
|
|
|
|
const activeTab = tabs.find(item => item.active);
|
|
|
|
|
|
|
|
if (tabs.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onTransformersChange = (transformers: DataTransformerConfig[]) => {
|
|
|
|
panel.setTransformations(transformers);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<TabsBar className={styles.tabBar}>
|
|
|
|
{tabs.map(tab => {
|
2020-03-20 09:15:04 -05:00
|
|
|
return (
|
|
|
|
<Tab
|
|
|
|
key={tab.id}
|
|
|
|
label={tab.text}
|
|
|
|
active={tab.active}
|
|
|
|
onChangeTab={() => onChangeTab(tab)}
|
|
|
|
icon={tab.icon}
|
|
|
|
/>
|
|
|
|
);
|
2020-02-12 03:42:57 -06:00
|
|
|
})}
|
|
|
|
</TabsBar>
|
|
|
|
<TabContent className={styles.tabContent}>
|
|
|
|
{activeTab.id === PanelEditorTabId.Queries && <QueriesTab panel={panel} dashboard={dashboard} />}
|
|
|
|
{activeTab.id === PanelEditorTabId.Alert && <AlertTab panel={panel} dashboard={dashboard} />}
|
2020-02-12 05:54:58 -06:00
|
|
|
{activeTab.id === PanelEditorTabId.Visualization && <VisualizationTab panel={panel} />}
|
2020-02-12 03:42:57 -06:00
|
|
|
{activeTab.id === PanelEditorTabId.Transform && data.state !== LoadingState.NotStarted && (
|
|
|
|
<TransformationsEditor
|
|
|
|
transformations={panel.transformations || []}
|
|
|
|
onChange={onTransformersChange}
|
|
|
|
dataFrames={data.series}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TabContent>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-09 08:39:46 -06:00
|
|
|
const getPanelEditorTabsStyles = stylesFactory(() => {
|
2020-02-12 03:42:57 -06:00
|
|
|
const { theme } = config;
|
|
|
|
|
2020-02-09 08:39:46 -06:00
|
|
|
return {
|
|
|
|
wrapper: css`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
`,
|
2020-02-25 10:58:20 -06:00
|
|
|
tabBar: css`
|
2020-03-30 07:39:18 -05:00
|
|
|
padding-left: ${theme.spacing.md};
|
2020-02-25 10:58:20 -06:00
|
|
|
`,
|
2020-02-12 03:42:57 -06:00
|
|
|
tabContent: css`
|
|
|
|
padding: 0;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-02-09 08:39:46 -06:00
|
|
|
flex-grow: 1;
|
2020-02-12 03:42:57 -06:00
|
|
|
min-height: 0;
|
2020-03-24 04:30:53 -05:00
|
|
|
background: ${theme.colors.panelBg};
|
2020-03-30 07:39:18 -05:00
|
|
|
border-right: 1px solid ${theme.colors.pageHeaderBorder};
|
2020-02-12 03:42:57 -06:00
|
|
|
|
|
|
|
.toolbar {
|
|
|
|
background: transparent;
|
|
|
|
}
|
2020-02-09 08:39:46 -06:00
|
|
|
`,
|
|
|
|
};
|
|
|
|
});
|