annotations_srv.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { cloneDeep } from 'lodash';
  2. import { AnnotationEvent, deprecationWarning } from '@grafana/data';
  3. import { deleteAnnotation, saveAnnotation, updateAnnotation } from 'app/features/annotations/api';
  4. import { AnnotationQueryOptions } from 'app/features/annotations/types';
  5. /**
  6. * @deprecated AnnotationsSrv is deprecated in favor of DashboardQueryRunner
  7. */
  8. export class AnnotationsSrv {
  9. /**
  10. * @deprecated clearPromiseCaches is deprecated
  11. */
  12. clearPromiseCaches() {
  13. deprecationWarning('annotations_srv.ts', 'clearPromiseCaches', 'DashboardQueryRunner');
  14. }
  15. /**
  16. * @deprecated getAnnotations is deprecated in favor of DashboardQueryRunner.getResult
  17. */
  18. getAnnotations(options: AnnotationQueryOptions) {
  19. deprecationWarning('annotations_srv.ts', 'getAnnotations', 'DashboardQueryRunner.getResult');
  20. return Promise.resolve({ annotations: [], alertState: undefined });
  21. }
  22. /**
  23. * @deprecated getAlertStates is deprecated in favor of DashboardQueryRunner.getResult
  24. */
  25. getAlertStates(options: any) {
  26. deprecationWarning('annotations_srv.ts', 'getAlertStates', 'DashboardQueryRunner.getResult');
  27. return Promise.resolve(undefined);
  28. }
  29. /**
  30. * @deprecated getGlobalAnnotations is deprecated in favor of DashboardQueryRunner.getResult
  31. */
  32. getGlobalAnnotations(options: AnnotationQueryOptions) {
  33. deprecationWarning('annotations_srv.ts', 'getGlobalAnnotations', 'DashboardQueryRunner.getResult');
  34. return Promise.resolve([]);
  35. }
  36. /**
  37. * @deprecated saveAnnotationEvent is deprecated
  38. */
  39. saveAnnotationEvent(annotation: AnnotationEvent) {
  40. deprecationWarning('annotations_srv.ts', 'saveAnnotationEvent', 'api/saveAnnotation');
  41. return saveAnnotation(annotation);
  42. }
  43. /**
  44. * @deprecated updateAnnotationEvent is deprecated
  45. */
  46. updateAnnotationEvent(annotation: AnnotationEvent) {
  47. deprecationWarning('annotations_srv.ts', 'updateAnnotationEvent', 'api/updateAnnotation');
  48. return updateAnnotation(annotation);
  49. }
  50. /**
  51. * @deprecated deleteAnnotationEvent is deprecated
  52. */
  53. deleteAnnotationEvent(annotation: AnnotationEvent) {
  54. deprecationWarning('annotations_srv.ts', 'deleteAnnotationEvent', 'api/deleteAnnotation');
  55. return deleteAnnotation(annotation);
  56. }
  57. /**
  58. * @deprecated translateQueryResult is deprecated in favor of DashboardQueryRunner/utils/translateQueryResult
  59. */
  60. translateQueryResult(annotation: any, results: any) {
  61. deprecationWarning('annotations_srv.ts', 'translateQueryResult', 'DashboardQueryRunner/utils/translateQueryResult');
  62. // if annotation has snapshotData
  63. // make clone and remove it
  64. if (annotation.snapshotData) {
  65. annotation = cloneDeep(annotation);
  66. delete annotation.snapshotData;
  67. }
  68. for (const item of results) {
  69. item.source = annotation;
  70. item.color = annotation.iconColor;
  71. item.type = annotation.name;
  72. item.isRegion = item.timeEnd && item.time !== item.timeEnd;
  73. }
  74. return results;
  75. }
  76. }