From 5f0ca1429b7b93867c9d2c55d147e59e52e84872 Mon Sep 17 00:00:00 2001 From: Adela Almasan <88068998+adela-almasan@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:39:10 -0600 Subject: [PATCH] Annotations: Fix annotation title (#85614) --- .betterer.results | 3 ++- .../app/features/alerting/state/alertDef.ts | 20 +++++++++++++++++++ .../annotations2/AnnotationTooltip2.tsx | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.betterer.results b/.betterer.results index 16d6a4be916..6141514e717 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1533,7 +1533,8 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"] + [0, 0, 0, "Unexpected any. Specify a different type.", "3"], + [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], "public/app/features/alerting/state/query_part.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], diff --git a/public/app/features/alerting/state/alertDef.ts b/public/app/features/alerting/state/alertDef.ts index 7ce82133ac5..348d89f91bc 100644 --- a/public/app/features/alerting/state/alertDef.ts +++ b/public/app/features/alerting/state/alertDef.ts @@ -207,6 +207,25 @@ function getAlertAnnotationInfo(ah: any) { return ''; } +// Copy of getAlertAnnotationInfo, used in annotation tooltip +function getAlertAnnotationText(annotationData: any) { + // backward compatibility, can be removed in grafana 5.x + // old way stored evalMatches in data property directly, + // new way stores it in evalMatches property on new data object + + if (isArray(annotationData)) { + return joinEvalMatches(annotationData, ', '); + } else if (isArray(annotationData.evalMatches)) { + return joinEvalMatches(annotationData.evalMatches, ', '); + } + + if (annotationData.error) { + return 'Error: ' + annotationData.error; + } + + return ''; +} + export default { alertQueryDef: alertQueryDef, getStateDisplayModel: getStateDisplayModel, @@ -218,5 +237,6 @@ export default { reducerTypes: reducerTypes, createReducerPart: createReducerPart, getAlertAnnotationInfo: getAlertAnnotationInfo, + getAlertAnnotationText: getAlertAnnotationText, alertStateSortScore: alertStateSortScore, }; diff --git a/public/app/plugins/panel/timeseries/plugins/annotations2/AnnotationTooltip2.tsx b/public/app/plugins/panel/timeseries/plugins/annotations2/AnnotationTooltip2.tsx index 641f0044a43..b7c7f5290eb 100644 --- a/public/app/plugins/panel/timeseries/plugins/annotations2/AnnotationTooltip2.tsx +++ b/public/app/plugins/panel/timeseries/plugins/annotations2/AnnotationTooltip2.tsx @@ -54,9 +54,9 @@ export const AnnotationTooltip2 = ({ annoVals, annoIdx, timeZone, onEdit }: Prop ); - // alertText = alertDef.getAlertAnnotationInfo(annotation); // @TODO ?? + alertText = annoVals.data?.[annoIdx] ? alertDef.getAlertAnnotationText(annoVals.data[annoIdx]) : ''; } else if (annoVals.title?.[annoIdx]) { - text = annoVals.title[annoIdx] + text ? `
${text}` : ''; + text = annoVals.title[annoIdx] + (text ? `
${text}` : ''); } return (