diff --git a/public/app/features/annotations/standardAnnotationSupport.ts b/public/app/features/annotations/standardAnnotationSupport.ts index 710ded708ed..04a4906b4ad 100644 --- a/public/app/features/annotations/standardAnnotationSupport.ts +++ b/public/app/features/annotations/standardAnnotationSupport.ts @@ -235,12 +235,14 @@ export function getAnnotationsFromData( * Opt out of using the default mapping functionality on frontend. */ export function shouldUseMappingUI(datasource: DataSourceApi): boolean { - return datasource.type !== 'prometheus'; + const { type } = datasource; + return type !== 'prometheus' && type !== 'elasticsearch'; } /** * Use legacy runner. Used only as an escape hatch for easier transition to React based annotation editor. */ export function shouldUseLegacyRunner(datasource: DataSourceApi): boolean { - return datasource.type === 'prometheus'; + const { type } = datasource; + return type === 'prometheus' || type === 'elasticsearch'; } diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx new file mode 100644 index 00000000000..5107417d0ea --- /dev/null +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/AnnotationQueryEditor.tsx @@ -0,0 +1,91 @@ +import React from 'react'; + +import { AnnotationQuery } from '@grafana/data'; +import { EditorRow, EditorField } from '@grafana/experimental'; +import { Input } from '@grafana/ui'; + +import { ElasticsearchQuery } from '../../types'; + +import { ElasticQueryEditorProps, ElasticSearchQueryField } from './index'; + +type Props = ElasticQueryEditorProps & { + annotation?: AnnotationQuery; + onAnnotationChange?: (annotation: AnnotationQuery) => void; +}; + +export function ElasticsearchAnnotationsQueryEditor(props: Props) { + const annotation = props.annotation!; + const onAnnotationChange = props.onAnnotationChange!; + + return ( + <> +
+ { + onAnnotationChange({ + ...annotation, + query, + }); + }} + /> +
+ +
+
Field mappings
+ + + { + onAnnotationChange({ + ...annotation, + timeField: e.currentTarget.value, + }); + }} + /> + + + { + onAnnotationChange({ + ...annotation, + timeEndField: e.currentTarget.value, + }); + }} + /> + + + { + onAnnotationChange({ + ...annotation, + textField: e.currentTarget.value, + }); + }} + /> + + + { + onAnnotationChange({ + ...annotation, + tagsField: e.currentTarget.value, + }); + }} + /> + + +
+ + ); +} diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/index.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/index.tsx index 3c77d6c5800..5a2adced5f9 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/index.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/index.tsx @@ -53,13 +53,31 @@ interface Props { value: ElasticsearchQuery; } +export const ElasticSearchQueryField = ({ value, onChange }: { value?: string; onChange: (v: string) => void }) => { + const styles = useStyles2(getStyles); + + return ( +
+ {}} + onChange={onChange} + placeholder="Lucene Query" + portalOrigin="elasticsearch" + /> +
+ ); +}; + const QueryEditorForm = ({ value }: Props) => { const dispatch = useDispatch(); const nextId = useNextId(); const styles = useStyles2(getStyles); // To be considered a time series query, the last bucked aggregation must be a Date Histogram - const isTimeSeriesQuery = value.bucketAggs?.slice(-1)[0]?.type === 'date_histogram'; + const isTimeSeriesQuery = value?.bucketAggs?.slice(-1)[0]?.type === 'date_histogram'; const showBucketAggregationsEditor = value.metrics?.every( (metric) => !metricAggregationConfig[metric.type].isSingleMetric @@ -69,17 +87,8 @@ const QueryEditorForm = ({ value }: Props) => { <>
Query -
- {}} - onChange={(query) => dispatch(changeQuery(query))} - placeholder="Lucene Query" - portalOrigin="elasticsearch" - /> -
+ dispatch(changeQuery(query))} value={value?.query} /> + -
- Index name - -
-
-
- -
-
-
- -
-
Field mappings
-
-
- Time - -
-
- Time End - -
-
- Text - -
-
- Tags - -
-
- Title (deprecated) - -
-
-