diff --git a/public/app/plugins/datasource/opentsdb/components/ConfigEditor.tsx b/public/app/plugins/datasource/opentsdb/components/ConfigEditor.tsx new file mode 100644 index 00000000000..dc0bc712c0a --- /dev/null +++ b/public/app/plugins/datasource/opentsdb/components/ConfigEditor.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { DataSourceHttpSettings } from '@grafana/ui'; +import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; +import { OpenTsdbDetails } from './OpenTsdbDetails'; +import { OpenTsdbOptions } from '../types'; + +export const ConfigEditor = (props: DataSourcePluginOptionsEditorProps) => { + const { options, onOptionsChange } = props; + + return ( + <> + + + + ); +}; diff --git a/public/app/plugins/datasource/opentsdb/components/OpenTsdbDetails.tsx b/public/app/plugins/datasource/opentsdb/components/OpenTsdbDetails.tsx new file mode 100644 index 00000000000..52fd75d2374 --- /dev/null +++ b/public/app/plugins/datasource/opentsdb/components/OpenTsdbDetails.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import { FormLabel, Select } from '@grafana/ui'; +import { DataSourceSettings, SelectableValue } from '@grafana/data'; +import { OpenTsdbOptions } from '../types'; + +const tsdbVersions = [ + { label: '<=2.1', value: 1 }, + { label: '==2.2', value: 2 }, + { label: '==2.3', value: 3 }, +]; + +const tsdbResolutions = [ + { label: 'second', value: 1 }, + { label: 'millisecond', value: 2 }, +]; + +interface Props { + value: DataSourceSettings; + onChange: (value: DataSourceSettings) => void; +} + +export const OpenTsdbDetails = (props: Props) => { + const { onChange, value } = props; + + return ( + <> +
OpenTSDB settings
+
+ Version + resolution.value === value.jsonData.tsdbResolution) ?? tsdbResolutions[0] + } + onChange={onChangeHandler('tsdbResolution', value, onChange)} + /> +
+ + ); +}; + +const onChangeHandler = (key: keyof OpenTsdbOptions, value: Props['value'], onChange: Props['onChange']) => ( + newValue: SelectableValue +) => { + onChange({ + ...value, + jsonData: { + ...value.jsonData, + [key]: newValue.value, + }, + }); +}; diff --git a/public/app/plugins/datasource/opentsdb/config_ctrl.ts b/public/app/plugins/datasource/opentsdb/config_ctrl.ts deleted file mode 100644 index 2e301d09baf..00000000000 --- a/public/app/plugins/datasource/opentsdb/config_ctrl.ts +++ /dev/null @@ -1,22 +0,0 @@ -export class OpenTsConfigCtrl { - static templateUrl = 'public/app/plugins/datasource/opentsdb/partials/config.html'; - current: any; - - /** @ngInject */ - constructor($scope: any) { - this.current.jsonData = this.current.jsonData || {}; - this.current.jsonData.tsdbVersion = this.current.jsonData.tsdbVersion || 1; - this.current.jsonData.tsdbResolution = this.current.jsonData.tsdbResolution || 1; - } - - tsdbVersions = [ - { name: '<=2.1', value: 1 }, - { name: '==2.2', value: 2 }, - { name: '==2.3', value: 3 }, - ]; - - tsdbResolutions = [ - { name: 'second', value: 1 }, - { name: 'millisecond', value: 2 }, - ]; -} diff --git a/public/app/plugins/datasource/opentsdb/datasource.ts b/public/app/plugins/datasource/opentsdb/datasource.ts index 5dc0962b07c..ea4a7766363 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.ts +++ b/public/app/plugins/datasource/opentsdb/datasource.ts @@ -1,10 +1,11 @@ import angular, { IQService } from 'angular'; import _ from 'lodash'; -import { dateMath, DataQueryRequest } from '@grafana/data'; +import { dateMath, DataQueryRequest, DataSourceApi } from '@grafana/data'; import { BackendSrv } from 'app/core/services/backend_srv'; import { TemplateSrv } from 'app/features/templating/template_srv'; +import { OpenTsdbOptions, OpenTsdbQuery } from './types'; -export default class OpenTsDatasource { +export default class OpenTsDatasource extends DataSourceApi { type: any; url: any; name: any; @@ -24,6 +25,7 @@ export default class OpenTsDatasource { private backendSrv: BackendSrv, private templateSrv: TemplateSrv ) { + super(instanceSettings); this.type = 'opentsdb'; this.url = instanceSettings.url; this.name = instanceSettings.name; diff --git a/public/app/plugins/datasource/opentsdb/module.ts b/public/app/plugins/datasource/opentsdb/module.ts index 1526a59dbf9..768025c026f 100644 --- a/public/app/plugins/datasource/opentsdb/module.ts +++ b/public/app/plugins/datasource/opentsdb/module.ts @@ -1,14 +1,13 @@ import OpenTsDatasource from './datasource'; import { OpenTsQueryCtrl } from './query_ctrl'; -import { OpenTsConfigCtrl } from './config_ctrl'; +import { DataSourcePlugin } from '@grafana/data'; +import { ConfigEditor } from './components/ConfigEditor'; class AnnotationsQueryCtrl { static templateUrl = 'partials/annotations.editor.html'; } -export { - OpenTsDatasource as Datasource, - OpenTsQueryCtrl as QueryCtrl, - OpenTsConfigCtrl as ConfigCtrl, - AnnotationsQueryCtrl, -}; +export const plugin = new DataSourcePlugin(OpenTsDatasource) + .setQueryCtrl(OpenTsQueryCtrl) + .setConfigEditor(ConfigEditor) + .setAnnotationQueryCtrl(AnnotationsQueryCtrl); diff --git a/public/app/plugins/datasource/opentsdb/partials/config.html b/public/app/plugins/datasource/opentsdb/partials/config.html deleted file mode 100644 index b15f22dcc5b..00000000000 --- a/public/app/plugins/datasource/opentsdb/partials/config.html +++ /dev/null @@ -1,19 +0,0 @@ - - -
OpenTSDB settings
-
- - Version - - - - -
-
- - Resolution - - - - -
diff --git a/public/app/plugins/datasource/opentsdb/types.ts b/public/app/plugins/datasource/opentsdb/types.ts new file mode 100644 index 00000000000..37c7de81f44 --- /dev/null +++ b/public/app/plugins/datasource/opentsdb/types.ts @@ -0,0 +1,8 @@ +import { DataQuery, DataSourceJsonData } from '@grafana/data'; + +export interface OpenTsdbQuery extends DataQuery {} + +export interface OpenTsdbOptions extends DataSourceJsonData { + tsdbVersion: number; + tsdbResolution: number; +}