import React, { useState } from 'react'; import { useAsync } from 'react-use'; import { AnnotationQuery, DataSourceInstanceSettings, getDataSourceRef } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { DataSourcePicker, getDataSourceSrv } from '@grafana/runtime'; import { Checkbox, CollapsableSection, ColorValueEditor, Field, HorizontalGroup, Input } from '@grafana/ui'; import StandardAnnotationQueryEditor from 'app/features/annotations/components/StandardAnnotationQueryEditor'; import { DashboardModel } from '../../state/DashboardModel'; import { AngularEditorLoader } from './AngularEditorLoader'; type Props = { editIdx: number; dashboard: DashboardModel; }; export const newAnnotationName = 'New annotation'; export const AnnotationSettingsEdit: React.FC = ({ editIdx, dashboard }) => { const [annotation, setAnnotation] = useState(dashboard.annotations.list[editIdx]); const { value: ds } = useAsync(() => { return getDataSourceSrv().get(annotation.datasource); }, [annotation.datasource]); const onUpdate = (annotation: AnnotationQuery) => { const list = [...dashboard.annotations.list]; list.splice(editIdx, 1, annotation); setAnnotation(annotation); dashboard.annotations.list = list; }; const onNameChange = (ev: React.FocusEvent) => { onUpdate({ ...annotation, name: ev.currentTarget.value, }); }; const onDataSourceChange = (ds: DataSourceInstanceSettings) => { onUpdate({ ...annotation, datasource: getDataSourceRef(ds), }); }; const onChange = (ev: React.FocusEvent) => { const target = ev.currentTarget; onUpdate({ ...annotation, [target.name]: target.type === 'checkbox' ? target.checked : target.value, }); }; const onColorChange = (color: string) => { onUpdate({ ...annotation, iconColor: color, }); }; const isNewAnnotation = annotation.name === newAnnotationName; return (
{ds?.annotations && ( )} {ds && !ds.annotations && }
); }; AnnotationSettingsEdit.displayName = 'AnnotationSettingsEdit';