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