// Libraries import { memo } from 'react'; import { AnnotationQuery } from '@grafana/data'; import { EditorField, EditorRow } from '@grafana/plugin-ui'; import { Input, Stack } from '@grafana/ui'; // Types import { getNormalizedLokiQuery } from '../queryUtils'; import { LokiQuery, LokiQueryType } from '../types'; import { LokiOptionFields } from './LokiOptionFields'; import { LokiQueryField } from './LokiQueryField'; import { LokiQueryEditorProps } from './types'; type Props = LokiQueryEditorProps & { annotation?: AnnotationQuery; onAnnotationChange?: (annotation: AnnotationQuery) => void; }; export const LokiAnnotationsQueryEditor = memo(function LokiAnnotationQueryEditor(props: Props) { const { annotation, onAnnotationChange, history } = props; // this should never happen, but we want to keep typescript happy if (annotation === undefined || onAnnotationChange === undefined) { return null; } const onChangeQuery = (query: LokiQuery) => { // the current version of annotations only stores an optional boolean // field `instant` to handle the instant/range switch. // we need to maintain compatibility for now, so we do the same. // we explicitly call `getNormalizedLokiQuery` to make sure `queryType` // is set up correctly. const instant = getNormalizedLokiQuery(query).queryType === LokiQueryType.Instant; onAnnotationChange({ ...annotation, expr: query.expr, maxLines: query.maxLines, instant, }); }; const queryWithRefId: LokiQuery = { refId: '', expr: annotation.expr, maxLines: annotation.maxLines, instant: annotation.instant, queryType: annotation.queryType, }; return ( {}} history={history} ExtraFieldElement={ {}} onChange={onChangeQuery} /> } /> { onAnnotationChange({ ...annotation, titleFormat: event.currentTarget.value, }); }} /> { onAnnotationChange({ ...annotation, tagKeys: event.currentTarget.value, }); }} /> { onAnnotationChange({ ...annotation, textFormat: event.currentTarget.value, }); }} /> ); });