import React from 'react'; import _ from 'lodash'; import { TemplateSrv } from 'app/features/templating/template_srv'; import StackdriverDatasource from '../datasource'; import { Metrics } from './Metrics'; import { Filter } from './Filter'; import { AnnotationTarget } from '../types'; import { AnnotationsHelp } from './AnnotationsHelp'; export interface Props { onQueryChange: (target: AnnotationTarget) => void; target: AnnotationTarget; datasource: StackdriverDatasource; templateSrv: TemplateSrv; } interface State extends AnnotationTarget { [key: string]: any; } const DefaultTarget: State = { defaultProject: 'loading project...', metricType: '', filters: [], metricKind: '', valueType: '', refId: 'annotationQuery', title: '', text: '', }; export class AnnotationQueryEditor extends React.Component { state: State = DefaultTarget; componentDidMount() { this.setState({ ...this.props.target, }); } onMetricTypeChange = ({ valueType, metricKind, type, unit }) => { const { onQueryChange } = this.props; this.setState( { metricType: type, unit, valueType, metricKind, }, () => { onQueryChange(this.state); } ); }; onChange(prop, value) { this.setState({ [prop]: value }, () => { this.props.onQueryChange(this.state); }); } render() { const { defaultProject, metricType, filters, refId, title, text } = this.state; const { datasource, templateSrv } = this.props; return ( <> {metric => ( <> this.onChange('filters', value)} filters={filters} refId={refId} hideGroupBys={true} templateSrv={templateSrv} datasource={datasource} metricType={metric ? metric.type : ''} /> )}
Title this.onChange('title', e.target.value)} />
Text this.onChange('text', e.target.value)} />
); } }