2021-09-27 15:23:54 +02:00
|
|
|
import { cloneDeep } from 'lodash';
|
2021-11-10 11:05:36 +01:00
|
|
|
import { AnnotationEvent, deprecationWarning } from '@grafana/data';
|
2021-08-19 06:38:31 +02:00
|
|
|
|
2021-11-10 11:05:36 +01:00
|
|
|
import { deleteAnnotation, saveAnnotation, updateAnnotation } from 'app/features/annotations/api';
|
|
|
|
|
import { AnnotationQueryOptions } from 'app/features/annotations/types';
|
2020-09-11 08:09:44 -07:00
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated AnnotationsSrv is deprecated in favor of DashboardQueryRunner
|
|
|
|
|
*/
|
2016-09-08 14:31:30 +02:00
|
|
|
export class AnnotationsSrv {
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated clearPromiseCaches is deprecated
|
|
|
|
|
*/
|
2019-01-28 18:19:12 +01:00
|
|
|
clearPromiseCaches() {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'clearPromiseCaches', 'DashboardQueryRunner');
|
2016-09-08 14:31:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated getAnnotations is deprecated in favor of DashboardQueryRunner.getResult
|
|
|
|
|
*/
|
2020-09-11 08:09:44 -07:00
|
|
|
getAnnotations(options: AnnotationQueryOptions) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'getAnnotations', 'DashboardQueryRunner.getResult');
|
|
|
|
|
return Promise.resolve({ annotations: [], alertState: undefined });
|
2016-09-09 11:30:55 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated getAlertStates is deprecated in favor of DashboardQueryRunner.getResult
|
|
|
|
|
*/
|
2019-06-27 13:21:04 +02:00
|
|
|
getAlertStates(options: any) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'getAlertStates', 'DashboardQueryRunner.getResult');
|
|
|
|
|
return Promise.resolve(undefined);
|
2016-09-30 17:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated getGlobalAnnotations is deprecated in favor of DashboardQueryRunner.getResult
|
|
|
|
|
*/
|
2020-09-11 08:09:44 -07:00
|
|
|
getGlobalAnnotations(options: AnnotationQueryOptions) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'getGlobalAnnotations', 'DashboardQueryRunner.getResult');
|
|
|
|
|
return Promise.resolve([]);
|
2016-09-08 14:31:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated saveAnnotationEvent is deprecated
|
|
|
|
|
*/
|
2019-08-01 14:38:34 +02:00
|
|
|
saveAnnotationEvent(annotation: AnnotationEvent) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'saveAnnotationEvent', 'api/saveAnnotation');
|
2021-04-26 06:13:03 +02:00
|
|
|
return saveAnnotation(annotation);
|
2017-04-08 13:32:16 +03:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated updateAnnotationEvent is deprecated
|
|
|
|
|
*/
|
2019-08-01 14:38:34 +02:00
|
|
|
updateAnnotationEvent(annotation: AnnotationEvent) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'updateAnnotationEvent', 'api/updateAnnotation');
|
2021-04-26 06:13:03 +02:00
|
|
|
return updateAnnotation(annotation);
|
2017-10-07 10:31:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated deleteAnnotationEvent is deprecated
|
|
|
|
|
*/
|
2019-08-01 14:38:34 +02:00
|
|
|
deleteAnnotationEvent(annotation: AnnotationEvent) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'deleteAnnotationEvent', 'api/deleteAnnotation');
|
2021-04-26 06:13:03 +02:00
|
|
|
return deleteAnnotation(annotation);
|
2017-10-07 10:31:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 15:23:54 +02:00
|
|
|
/**
|
|
|
|
|
* @deprecated translateQueryResult is deprecated in favor of DashboardQueryRunner/utils/translateQueryResult
|
|
|
|
|
*/
|
2019-06-27 13:21:04 +02:00
|
|
|
translateQueryResult(annotation: any, results: any) {
|
2021-09-27 15:23:54 +02:00
|
|
|
deprecationWarning('annotations_srv.ts', 'translateQueryResult', 'DashboardQueryRunner/utils/translateQueryResult');
|
2017-04-25 14:27:41 +02:00
|
|
|
// if annotation has snapshotData
|
|
|
|
|
// make clone and remove it
|
|
|
|
|
if (annotation.snapshotData) {
|
2020-01-21 09:08:07 +00:00
|
|
|
annotation = cloneDeep(annotation);
|
2017-04-25 14:27:41 +02:00
|
|
|
delete annotation.snapshotData;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 14:27:29 +02:00
|
|
|
for (const item of results) {
|
2016-09-09 11:30:55 +02:00
|
|
|
item.source = annotation;
|
2020-09-24 21:01:31 +02:00
|
|
|
item.color = annotation.iconColor;
|
|
|
|
|
item.type = annotation.name;
|
2019-09-05 02:14:06 -04:00
|
|
|
item.isRegion = item.timeEnd && item.time !== item.timeEnd;
|
2016-09-08 14:31:30 +02:00
|
|
|
}
|
2019-09-05 02:14:06 -04:00
|
|
|
|
2016-09-09 11:30:55 +02:00
|
|
|
return results;
|
2016-09-08 14:31:30 +02:00
|
|
|
}
|
|
|
|
|
}
|