mirror of https://github.com/grafana/grafana
Chore: Convert internal grafana datasource from angular to react (#27870)
parent
26f86ba823
commit
71a01a1053
@ -0,0 +1,20 @@ |
|||||||
|
import { SelectableValue } from '@grafana/data'; |
||||||
|
import { GrafanaAnnotationType } from './types'; |
||||||
|
|
||||||
|
export const annotationTypes: Array<SelectableValue<GrafanaAnnotationType>> = [ |
||||||
|
{ 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'; |
||||||
|
} |
@ -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<GrafanaDatasource, GrafanaQuery>; |
||||||
|
|
||||||
|
export class QueryEditor extends PureComponent<Props> { |
||||||
|
queryTypes: Array<SelectableValue<GrafanaQueryType>> = [ |
||||||
|
{ |
||||||
|
label: 'Random Walk', |
||||||
|
value: GrafanaQueryType.RandomWalk, |
||||||
|
description: 'Random signal within the selected time rage', |
||||||
|
}, |
||||||
|
]; |
||||||
|
|
||||||
|
onQueryTypeChange = (sel: SelectableValue<GrafanaQueryType>) => { |
||||||
|
const { onChange, query, onRunQuery } = this.props; |
||||||
|
onChange({ ...query, queryType: sel.value! }); |
||||||
|
onRunQuery(); |
||||||
|
}; |
||||||
|
|
||||||
|
render() { |
||||||
|
const query = defaults(this.props.query, defaultQuery); |
||||||
|
return ( |
||||||
|
<div className="gf-form"> |
||||||
|
<InlineField label="Query type" grow={true}> |
||||||
|
<Select |
||||||
|
options={this.queryTypes} |
||||||
|
value={this.queryTypes.find(v => v.value === query.queryType) || this.queryTypes[0]} |
||||||
|
onChange={this.onQueryTypeChange} |
||||||
|
/> |
||||||
|
</InlineField> |
||||||
|
</div> |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -1,29 +1,9 @@ |
|||||||
|
import { DataSourcePlugin } from '@grafana/data'; |
||||||
import { GrafanaDatasource } from './datasource'; |
import { GrafanaDatasource } from './datasource'; |
||||||
import { QueryCtrl } from 'app/plugins/sdk'; |
import { QueryEditor } from './components/QueryEditor'; |
||||||
|
import { GrafanaQuery } from './types'; |
||||||
|
import { GrafanaAnnotationsQueryCtrl } from './annotation_ctrl'; |
||||||
|
|
||||||
class GrafanaQueryCtrl extends QueryCtrl { |
export const plugin = new DataSourcePlugin<GrafanaDatasource, GrafanaQuery>(GrafanaDatasource) |
||||||
static templateUrl = 'partials/query.editor.html'; |
.setQueryEditor(QueryEditor) |
||||||
} |
.setAnnotationQueryCtrl(GrafanaAnnotationsQueryCtrl); |
||||||
|
|
||||||
class GrafanaAnnotationsQueryCtrl { |
|
||||||
annotation: any; |
|
||||||
|
|
||||||
types = [ |
|
||||||
{ text: 'Dashboard', value: 'dashboard' }, |
|
||||||
{ text: 'Tags', value: 'tags' }, |
|
||||||
]; |
|
||||||
|
|
||||||
constructor() { |
|
||||||
this.annotation.type = this.annotation.type || 'tags'; |
|
||||||
this.annotation.limit = this.annotation.limit || 100; |
|
||||||
} |
|
||||||
|
|
||||||
static templateUrl = 'partials/annotations.editor.html'; |
|
||||||
} |
|
||||||
|
|
||||||
export { |
|
||||||
GrafanaDatasource, |
|
||||||
GrafanaDatasource as Datasource, |
|
||||||
GrafanaQueryCtrl as QueryCtrl, |
|
||||||
GrafanaAnnotationsQueryCtrl as AnnotationsQueryCtrl, |
|
||||||
}; |
|
||||||
|
@ -1,11 +0,0 @@ |
|||||||
<query-editor-row query-ctrl="ctrl" can-collapse="false"> |
|
||||||
<div class="gf-form-inline"> |
|
||||||
<div class="gf-form"> |
|
||||||
<label class="gf-form-label">Test data: random walk</label> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="gf-form gf-form--grow"> |
|
||||||
<div class="gf-form-label gf-form-label--grow"></div> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</query-editor-row> |
|
@ -0,0 +1,36 @@ |
|||||||
|
import { AnnotationQuery, DataQuery } from '@grafana/data'; |
||||||
|
|
||||||
|
//----------------------------------------------
|
||||||
|
// Query
|
||||||
|
//----------------------------------------------
|
||||||
|
|
||||||
|
export enum GrafanaQueryType { |
||||||
|
RandomWalk = 'randomWalk', |
||||||
|
RandomStream = 'randomStream', |
||||||
|
HostMetrics = 'hostmetrics', |
||||||
|
} |
||||||
|
|
||||||
|
export interface GrafanaQuery extends DataQuery { |
||||||
|
queryType: GrafanaQueryType; // RandomWalk by default
|
||||||
|
} |
||||||
|
|
||||||
|
export const defaultQuery: GrafanaQuery = { |
||||||
|
refId: 'A', |
||||||
|
queryType: GrafanaQueryType.RandomWalk, |
||||||
|
}; |
||||||
|
|
||||||
|
//----------------------------------------------
|
||||||
|
// Annotations
|
||||||
|
//----------------------------------------------
|
||||||
|
|
||||||
|
export enum GrafanaAnnotationType { |
||||||
|
Dashboard = 'dashboard', |
||||||
|
Tags = 'tags', |
||||||
|
} |
||||||
|
|
||||||
|
export interface GrafanaAnnotationQuery extends AnnotationQuery<GrafanaQuery> { |
||||||
|
type: GrafanaAnnotationType; // tags
|
||||||
|
limit: number; // 100
|
||||||
|
tags?: string[]; |
||||||
|
matchAny?: boolean; // By default Grafana only shows annotations that match all tags in the query. Enabling this returns annotations that match any of the tags in the query.
|
||||||
|
} |
Loading…
Reference in new issue