import React, { useState } from 'react'; import { arrayUtils } from '@grafana/data'; import { getDataSourceSrv } from '@grafana/runtime'; import { DeleteButton, Icon, IconButton, VerticalGroup } from '@grafana/ui'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import { DashboardModel } from '../../state/DashboardModel'; import { ListNewButton } from '../DashboardSettings/ListNewButton'; type Props = { dashboard: DashboardModel; onNew: () => void; onEdit: (idx: number) => void; }; export const AnnotationSettingsList: React.FC = ({ dashboard, onNew, onEdit }) => { const [annotations, updateAnnotations] = useState(dashboard.annotations.list); const onMove = (idx: number, direction: number) => { dashboard.annotations.list = arrayUtils.moveItemImmutably(annotations, idx, idx + direction); updateAnnotations(dashboard.annotations.list); }; const onDelete = (idx: number) => { dashboard.annotations.list = [...annotations.slice(0, idx), ...annotations.slice(idx + 1)]; updateAnnotations(dashboard.annotations.list); }; const showEmptyListCTA = annotations.length === 0 || (annotations.length === 1 && annotations[0].builtIn); const dataSourceSrv = getDataSourceSrv(); return ( {annotations.length > 0 && ( {dashboard.annotations.list.map((annotation, idx) => ( {annotation.builtIn ? ( ) : ( )} ))}
Query name Data source
onEdit(idx)}>   {annotation.name} (Built-in) onEdit(idx)}>   {annotation.name} onEdit(idx)}> {dataSourceSrv.getInstanceSettings(annotation.datasource)?.name || annotation.datasource?.uid} {idx !== 0 && onMove(idx, -1)} />} {dashboard.annotations.list.length > 1 && idx !== dashboard.annotations.list.length - 1 ? ( onMove(idx, 1)} /> ) : null} onDelete(idx)} aria-label={`Delete query with title "${annotation.name}"`} />
)} {showEmptyListCTA && ( Annotations provide a way to integrate event data into your graphs. They are visualized as vertical lines and icons on all graph panels. When you hover over an annotation icon you can get event text & tags for the event. You can add annotation events directly from grafana by holding CTRL or CMD + click on graph (or drag region). These will be stored in Grafana's annotation database.

Checkout the Annotations documentation for more information.`, }} /> )} {!showEmptyListCTA && New query}
); };