import { css } from '@emotion/css'; import React, { useEffect, useState } from 'react'; import { AnnotationQuery, EventBus, GrafanaTheme2 } from '@grafana/data'; import { InlineField, InlineFieldRow, InlineSwitch, useStyles2 } from '@grafana/ui'; import { LoadingIndicator } from '@grafana/ui/src/components/PanelChrome/LoadingIndicator'; import { AnnotationQueryFinished, AnnotationQueryStarted } from '../../../../types/events'; import { getDashboardQueryRunner } from '../../../query/state/DashboardQueryRunner/DashboardQueryRunner'; export interface AnnotationPickerProps { events: EventBus; annotation: AnnotationQuery; onEnabledChanged: (annotation: AnnotationQuery) => void; } export const AnnotationPicker = ({ annotation, events, onEnabledChanged }: AnnotationPickerProps): JSX.Element => { const [loading, setLoading] = useState(false); const styles = useStyles2(getStyles); const onCancel = () => getDashboardQueryRunner().cancel(annotation); useEffect(() => { const started = events.getStream(AnnotationQueryStarted).subscribe({ next: (event) => { if (event.payload === annotation) { setLoading(true); } }, }); const stopped = events.getStream(AnnotationQueryFinished).subscribe({ next: (event) => { if (event.payload === annotation) { setLoading(false); } }, }); return () => { started.unsubscribe(); stopped.unsubscribe(); }; }); return (