From b761679d801c4637ea1dac7e2183f6982b40f72f Mon Sep 17 00:00:00 2001 From: Shavonn Brown Date: Tue, 10 Mar 2020 13:20:38 -0400 Subject: [PATCH] Graphite: Update config editor (#22553) * update config editor * inlining * move inline styles * removed inline style but emotion not working * fix styles, update types const --- .../configuration/ConfigEditor.styles.ts | 10 ++ .../graphite/configuration/ConfigEditor.tsx | 124 +++++++++++++++--- .../configuration/GraphiteDetails.tsx | 107 --------------- 3 files changed, 114 insertions(+), 127 deletions(-) create mode 100644 public/app/plugins/datasource/graphite/configuration/ConfigEditor.styles.ts delete mode 100644 public/app/plugins/datasource/graphite/configuration/GraphiteDetails.tsx diff --git a/public/app/plugins/datasource/graphite/configuration/ConfigEditor.styles.ts b/public/app/plugins/datasource/graphite/configuration/ConfigEditor.styles.ts new file mode 100644 index 00000000000..be9256dccdc --- /dev/null +++ b/public/app/plugins/datasource/graphite/configuration/ConfigEditor.styles.ts @@ -0,0 +1,10 @@ +import { css } from 'emotion'; + +const styles = { + helpbtn: css` + margin-left: 8px; + margin-top: 5px; + `, +}; + +export default styles; diff --git a/public/app/plugins/datasource/graphite/configuration/ConfigEditor.tsx b/public/app/plugins/datasource/graphite/configuration/ConfigEditor.tsx index e31d376785d..265185cd4be 100644 --- a/public/app/plugins/datasource/graphite/configuration/ConfigEditor.tsx +++ b/public/app/plugins/datasource/graphite/configuration/ConfigEditor.tsx @@ -1,20 +1,104 @@ -import React from 'react'; -import { DataSourceHttpSettings } from '@grafana/ui'; -import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; -import { GraphiteDetails } from './GraphiteDetails'; -import { GraphiteOptions } from '../types'; - -export const ConfigEditor = (props: DataSourcePluginOptionsEditorProps) => { - const { options, onOptionsChange } = props; - - return ( - <> - - - - ); -}; +import React, { PureComponent } from 'react'; +import { DataSourceHttpSettings, FormLabel, Button, Select } from '@grafana/ui'; +import { DataSourcePluginOptionsEditorProps, onUpdateDatasourceJsonDataOptionSelect } from '@grafana/data'; +import { GraphiteOptions, GraphiteType } from '../types'; +import styles from './ConfigEditor.styles'; + +const graphiteVersions = [ + { label: '0.9.x', value: '0.9' }, + { label: '1.0.x', value: '1.0' }, + { label: '1.1.x', value: '1.1' }, +]; + +const graphiteTypes = Object.entries(GraphiteType).map(([label, value]) => ({ + label, + value, +})); + +export type Props = DataSourcePluginOptionsEditorProps; + +interface State { + showMetricTankHelp: boolean; +} + +export class ConfigEditor extends PureComponent { + constructor(props: Props) { + super(props); + + this.state = { + showMetricTankHelp: false, + }; + } + + render() { + const { options, onOptionsChange } = this.props; + const { showMetricTankHelp } = this.state; + + const currentVersion = + graphiteVersions.find(item => item.value === options.jsonData.graphiteVersion) ?? graphiteVersions[2]; + + return ( + <> + +

Graphite details

+
+
+
+ + Version + + type.value === options.jsonData.graphiteType)} + width={8} + onChange={onUpdateDatasourceJsonDataOptionSelect(this.props, 'graphiteType')} + /> + +
+ +
+
+
+ {showMetricTankHelp && ( +
+
+

+ There are different types of Graphite compatible backends. Here you can specify the type you are + using. If you are using{' '} + + Metrictank + {' '} + then select that here. This will enable Metrictank specific features like query processing meta data. + Metrictank is a multi-tenant timeseries engine for Graphite and friends. +

+
+
+ )} +
+ + ); + } +} diff --git a/public/app/plugins/datasource/graphite/configuration/GraphiteDetails.tsx b/public/app/plugins/datasource/graphite/configuration/GraphiteDetails.tsx deleted file mode 100644 index 828b84ca470..00000000000 --- a/public/app/plugins/datasource/graphite/configuration/GraphiteDetails.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import React, { PureComponent } from 'react'; -import { DataSourceSettings, SelectableValue } from '@grafana/data'; -import { Button, FormLabel, Select } from '@grafana/ui'; -import { GraphiteOptions, GraphiteType } from '../types'; - -const graphiteVersions = [ - { label: '0.9.x', value: '0.9' }, - { label: '1.0.x', value: '1.0' }, - { label: '1.1.x', value: '1.1' }, -]; - -const graphiteTypes = Object.keys(GraphiteType).map((key: string) => ({ - label: key, - value: (GraphiteType as any)[key], -})); - -interface Props { - value: DataSourceSettings; - onChange: (value: DataSourceSettings) => void; -} - -interface State { - showMetricTankHelp: boolean; -} - -export class GraphiteDetails extends PureComponent { - constructor(props: Props) { - super(props); - - this.state = { - showMetricTankHelp: false, - }; - } - - onChangeHandler = (key: keyof GraphiteOptions) => (newValue: SelectableValue) => { - const { value, onChange } = this.props; - onChange({ - ...value, - jsonData: { - ...value.jsonData, - [key]: newValue.value, - }, - }); - }; - - render() { - const { value } = this.props; - const { showMetricTankHelp } = this.state; - - const currentVersion = - graphiteVersions.find(item => item.value === value.jsonData.graphiteVersion) ?? graphiteVersions[2]; - - return ( - <> -

Graphite details

-
-
- - Version - - type.value === value.jsonData.graphiteType)} - width={8} - onChange={this.onChangeHandler('graphiteType')} - /> - - -
- {showMetricTankHelp && ( -
-
-

- There are different types of Graphite compatible backends. Here you can specify the type you are - using. If you are using{' '} - - Metrictank - {' '} - then select that here. This will enable Metrictank specific features like query processing meta data. - Metrictank is a multi-tenant timeseries engine for Graphite and friends. -

-
-
- )} -
- - ); - } -}