From 19b239fba099d852fd1fbc5f9680f9f224ad0c4f Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Tue, 25 Jul 2023 22:34:14 +0200 Subject: [PATCH] Alerting: Fix inconsistencies in alert rule form depending on alert type (#72287) * Fix inconsistencies in alert rule form depending on alert type * Fix default annotations when comming from dashboard panel * Update texts following pr review comments * Fix texts --------- Co-authored-by: Virginia Cepeda --- .../components/rule-editor/AlertRuleForm.tsx | 11 +++++++++-- .../rule-editor/CloudEvaluationBehavior.tsx | 13 +++++++++++-- .../unified/components/rule-editor/DetailsStep.tsx | 7 ++++--- .../components/rule-editor/FolderAndGroup.tsx | 2 +- .../rule-editor/GrafanaEvaluationBehavior.tsx | 2 +- .../components/rule-editor/NotificationsStep.tsx | 2 +- .../QueryAndExpressionsStep.tsx | 9 ++++++--- .../features/alerting/unified/utils/constants.ts | 6 +++--- .../features/alerting/unified/utils/rule-form.ts | 5 +++-- 9 files changed, 39 insertions(+), 18 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx index e8715f33eb0..038a776fb35 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx @@ -21,7 +21,13 @@ import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelect import { deleteRuleAction, saveRuleFormAction } from '../../state/actions'; import { RuleFormType, RuleFormValues } from '../../types/rule-form'; import { initialAsyncRequestState } from '../../utils/redux'; -import { getDefaultFormValues, getDefaultQueries, MINUTE, rulerRuleToFormValues } from '../../utils/rule-form'; +import { + getDefaultFormValues, + getDefaultQueries, + MINUTE, + normalizeDefaultAnnotations, + rulerRuleToFormValues, +} from '../../utils/rule-form'; import * as ruleId from '../../utils/rule-id'; import { CloudEvaluationBehavior } from './CloudEvaluationBehavior'; @@ -50,7 +56,7 @@ const AlertRuleNameInput = () => { const ruleFormType = watch('type'); return ( - + { } = useFormContext(); const type = watch('type'); + const dataSourceName = watch('dataSourceName'); // cloud recording rules do not have alert conditions if (type === RuleFormType.cloudRecording) { @@ -28,8 +30,11 @@ export const CloudEvaluationBehavior = () => { } return ( - - + +
{ />
+ {type === RuleFormType.cloudAlerting && dataSourceName && ( + + )} +
); diff --git a/public/app/features/alerting/unified/components/rule-editor/DetailsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/DetailsStep.tsx index ad777757ee6..be14d996704 100644 --- a/public/app/features/alerting/unified/components/rule-editor/DetailsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/DetailsStep.tsx @@ -56,11 +56,12 @@ export function DetailsStep() { return ( - {(ruleFormType === RuleFormType.cloudRecording || ruleFormType === RuleFormType.cloudAlerting) && - dataSourceName && } + {ruleFormType === RuleFormType.cloudRecording && dataSourceName && ( + + )} {type !== RuleFormType.cloudRecording && } diff --git a/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx b/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx index 64bb430b056..4b88fed73e9 100644 --- a/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx @@ -182,7 +182,7 @@ export function FolderAndGroup({ groupfoldersForGrafana }: { groupfoldersForGraf Pending period diff --git a/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx index 0b0c6780189..f3c4cf41984 100644 --- a/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx @@ -86,7 +86,7 @@ export const NotificationsStep = ({ alertUid }: NotificationsStepProps) => { return ( + {/* This is the cloud data source selector */} {(type === RuleFormType.cloudRecording || type === RuleFormType.cloudAlerting) && ( @@ -436,7 +439,7 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P /> {/* Expression Queries */} Expressions -
Manipulate data returned from queries with math and other operations
+
Manipulate data returned from queries with math and other operations.
= { }; export const annotationDescriptions: Record = { - [Annotation.description]: 'Description of what the alert rule does', - [Annotation.summary]: 'Short summary of what happened and why', - [Annotation.runbookURL]: 'Webpage where you keep your runbook for the alert', + [Annotation.description]: 'Description of what the alert rule does.', + [Annotation.summary]: 'Short summary of what happened and why.', + [Annotation.runbookURL]: 'Webpage where you keep your runbook for the alert.', [Annotation.dashboardUID]: '', [Annotation.panelID]: '', [Annotation.alertId]: '', diff --git a/public/app/features/alerting/unified/utils/rule-form.ts b/public/app/features/alerting/unified/utils/rule-form.ts index bb5f3af1ad6..63eb52d6a68 100644 --- a/public/app/features/alerting/unified/utils/rule-form.ts +++ b/public/app/features/alerting/unified/utils/rule-form.ts @@ -94,7 +94,7 @@ export function formValuesToRulerRuleDTO(values: RuleFormValues): RulerRuleDTO { throw new Error(`unexpected rule type: ${type}`); } -function listifyLabelsOrAnnotations( +export function listifyLabelsOrAnnotations( item: Labels | Annotations | undefined, addEmpty: boolean ): Array<{ key: string; value: string }> { @@ -106,7 +106,7 @@ function listifyLabelsOrAnnotations( } //make sure default annotations are always shown in order even if empty -function normalizeDefaultAnnotations(annotations: Array<{ key: string; value: string }>) { +export function normalizeDefaultAnnotations(annotations: Array<{ key: string; value: string }>) { const orderedAnnotations = [...annotations]; const defaultAnnotationKeys = defaultAnnotations.map((annotation) => annotation.key); @@ -179,6 +179,7 @@ export function rulerRuleToFormValues(ruleWithLocation: RuleWithLocation): RuleF return { ...defaultFormValues, ...alertingRuleValues, + annotations: normalizeDefaultAnnotations(listifyLabelsOrAnnotations(rule.annotations, false)), type: RuleFormType.cloudAlerting, dataSourceName: ruleSourceName, namespace,