api.ts 793 B

123456789101112131415161718192021222324
  1. import { AnnotationEvent } from '@grafana/data';
  2. import { getBackendSrv } from '@grafana/runtime';
  3. import { AnnotationTagsResponse } from './types';
  4. export function saveAnnotation(annotation: AnnotationEvent) {
  5. return getBackendSrv().post('/api/annotations', annotation);
  6. }
  7. export function updateAnnotation(annotation: AnnotationEvent) {
  8. return getBackendSrv().put(`/api/annotations/${annotation.id}`, annotation);
  9. }
  10. export function deleteAnnotation(annotation: AnnotationEvent) {
  11. return getBackendSrv().delete(`/api/annotations/${annotation.id}`);
  12. }
  13. export async function getAnnotationTags() {
  14. const response: AnnotationTagsResponse = await getBackendSrv().get('/api/annotations/tags');
  15. return response.result.tags.map(({ tag, count }) => ({
  16. term: tag,
  17. count,
  18. }));
  19. }