From 71a01a10535b017e065e06ee4158d234b5393781 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 29 Sep 2020 10:39:31 -0700 Subject: [PATCH] Chore: Convert internal grafana datasource from angular to react (#27870) --- .../datasource/grafana/annotation_ctrl.ts | 20 +++++ .../grafana/components/QueryEditor.tsx | 40 +++++++++ .../grafana/{specs => }/datasource.test.ts | 24 +++--- .../plugins/datasource/grafana/datasource.ts | 83 ++++++++++--------- .../app/plugins/datasource/grafana/module.ts | 34 ++------ .../grafana/partials/query.editor.html | 11 --- .../app/plugins/datasource/grafana/types.ts | 36 ++++++++ 7 files changed, 161 insertions(+), 87 deletions(-) create mode 100644 public/app/plugins/datasource/grafana/annotation_ctrl.ts create mode 100644 public/app/plugins/datasource/grafana/components/QueryEditor.tsx rename public/app/plugins/datasource/grafana/{specs => }/datasource.test.ts (77%) delete mode 100644 public/app/plugins/datasource/grafana/partials/query.editor.html create mode 100644 public/app/plugins/datasource/grafana/types.ts diff --git a/public/app/plugins/datasource/grafana/annotation_ctrl.ts b/public/app/plugins/datasource/grafana/annotation_ctrl.ts new file mode 100644 index 00000000000..8876ddfb660 --- /dev/null +++ b/public/app/plugins/datasource/grafana/annotation_ctrl.ts @@ -0,0 +1,20 @@ +import { SelectableValue } from '@grafana/data'; +import { GrafanaAnnotationType } from './types'; + +export const annotationTypes: Array> = [ + { text: 'Dashboard', value: GrafanaAnnotationType.Dashboard }, + { text: 'Tags', value: GrafanaAnnotationType.Tags }, +]; + +export class GrafanaAnnotationsQueryCtrl { + annotation: any; + + types = annotationTypes; + + constructor() { + this.annotation.type = this.annotation.type || GrafanaAnnotationType.Tags; + this.annotation.limit = this.annotation.limit || 100; + } + + static templateUrl = 'partials/annotations.editor.html'; +} diff --git a/public/app/plugins/datasource/grafana/components/QueryEditor.tsx b/public/app/plugins/datasource/grafana/components/QueryEditor.tsx new file mode 100644 index 00000000000..6393b5038ad --- /dev/null +++ b/public/app/plugins/datasource/grafana/components/QueryEditor.tsx @@ -0,0 +1,40 @@ +import defaults from 'lodash/defaults'; + +import React, { PureComponent } from 'react'; +import { InlineField, Select } from '@grafana/ui'; +import { QueryEditorProps, SelectableValue } from '@grafana/data'; +import { GrafanaDatasource } from '../datasource'; +import { defaultQuery, GrafanaQuery, GrafanaQueryType } from '../types'; + +type Props = QueryEditorProps; + +export class QueryEditor extends PureComponent { + queryTypes: Array> = [ + { + label: 'Random Walk', + value: GrafanaQueryType.RandomWalk, + description: 'Random signal within the selected time rage', + }, + ]; + + onQueryTypeChange = (sel: SelectableValue) => { + const { onChange, query, onRunQuery } = this.props; + onChange({ ...query, queryType: sel.value! }); + onRunQuery(); + }; + + render() { + const query = defaults(this.props.query, defaultQuery); + return ( +
+ +