From c7ddf29cdf6050839691d6f9d23ce348b5f65b46 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Tue, 27 Jun 2023 16:46:56 +0200 Subject: [PATCH] Alerting: Add NeedHelpInfo component in notifications step. (#70740) Add NeedHelpInfo component in notifications step and use it in annotations step (instead of HoverCard) for consistency --- .../rule-editor/AnnotationsField.tsx | 1 + .../components/rule-editor/DetailsStep.tsx | 63 +++++++------------ .../components/rule-editor/NeedHelpInfo.tsx | 6 +- .../rule-editor/NotificationsStep.tsx | 37 ++++++++++- .../QueryAndExpressionsStep.tsx | 1 + 5 files changed, 62 insertions(+), 46 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/AnnotationsField.tsx b/public/app/features/alerting/unified/components/rule-editor/AnnotationsField.tsx index 18529115b2e..3c5bf22ef95 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AnnotationsField.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AnnotationsField.tsx @@ -205,6 +205,7 @@ const getStyles = (theme: GrafanaTheme2) => ({ flexColumn: css` display: flex; flex-direction: column; + margin-top: ${theme.spacing(2)}; `, field: css` margin-bottom: ${theme.spacing(0.5)}; 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 43af268c8d0..ad777757ee6 100644 --- a/public/app/features/alerting/unified/components/rule-editor/DetailsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/DetailsStep.tsx @@ -3,13 +3,14 @@ import React from 'react'; import { useFormContext } from 'react-hook-form'; import { GrafanaTheme2 } from '@grafana/data'; -import { Icon, useStyles2 } from '@grafana/ui'; +import { Stack } from '@grafana/experimental'; +import { useStyles2 } from '@grafana/ui'; import { RuleFormType, RuleFormValues } from '../../types/rule-form'; -import { HoverCard } from '../HoverCard'; import AnnotationsField from './AnnotationsField'; import { GroupAndNamespaceFields } from './GroupAndNamespaceFields'; +import { NeedHelpInfo } from './NeedHelpInfo'; import { RuleEditorSection } from './RuleEditorSection'; function getDescription(ruleType: RuleFormType | undefined, styles: { [key: string]: string }) { @@ -21,46 +22,26 @@ function getDescription(ruleType: RuleFormType | undefined, styles: { [key: stri const docsLink = 'https://grafana.com/docs/grafana/latest/alerting/fundamentals/annotation-label/variables-label-annotation'; - const HelpContent = () => ( -
-
- Annotations -
-
- Annotations add metadata to provide more information on the alert in your alert notifications. For example, add - a Summary annotation to tell you which value caused the alert to fire or which server it happened on. -
-
Annotations can contain a combination of text and template code.
-
- - Read about annotations - -
-
+ const textToRender = + ruleType === RuleFormType.grafana + ? ` ${annotationsText} ` + : ruleType === RuleFormType.cloudAlerting + ? `Select the Namespace and evaluation group for your alert. ${annotationsText} ` + : ''; + + return ( + + {`${textToRender}`} + + ); - const LinkToDocs = () => ( - } placement={'bottom-start'}> - - Need help? - - - ); - if (ruleType === RuleFormType.grafana) { - return ( - - {` ${annotationsText} `} - - - ); - } - if (ruleType === RuleFormType.cloudAlerting) { - return ( - - {`Select the Namespace and evaluation group for your alert. ${annotationsText} `} - - ); - } - return ''; } export function DetailsStep() { diff --git a/public/app/features/alerting/unified/components/rule-editor/NeedHelpInfo.tsx b/public/app/features/alerting/unified/components/rule-editor/NeedHelpInfo.tsx index d2d1caeec33..7f1fc0600bd 100644 --- a/public/app/features/alerting/unified/components/rule-editor/NeedHelpInfo.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/NeedHelpInfo.tsx @@ -9,8 +9,9 @@ interface NeedHelpInfoProps { contentText: string; externalLink: string; linkText: string; + title: string; } -export function NeedHelpInfo({ contentText, externalLink, linkText }: NeedHelpInfoProps) { +export function NeedHelpInfo({ contentText, externalLink, linkText, title }: NeedHelpInfoProps) { const styles = useStyles2(getStyles); return ( - Define query and alert condition + {title} } footer={ @@ -53,6 +54,7 @@ const getStyles = (theme: GrafanaTheme2) => ({ margin-left: ${theme.spacing(1)}; font-size: ${theme.typography.size.sm}; cursor: pointer; + color: ${theme.colors.text.primary}; `, helpInfoText: css` margin-left: ${theme.spacing(0.5)}; 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 4e755f31439..f0e2d508593 100644 --- a/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx @@ -9,6 +9,7 @@ import { RuleFormType, RuleFormValues } from '../../types/rule-form'; import { GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource'; import LabelsField from './LabelsField'; +import { NeedHelpInfo } from './NeedHelpInfo'; import { RuleEditorSection } from './RuleEditorSection'; import { NotificationPreview } from './notificaton-preview/NotificationPreview'; @@ -33,14 +34,34 @@ export const NotificationsStep = ({ alertUid }: NotificationsStepProps) => { const shouldRenderPreview = Boolean(condition) && Boolean(folder) && type === RuleFormType.grafana; + const NotificationsStepDescription = () => { + return ( +
+
+ Grafana handles the notifications for alerts by assigning labels to alerts. These labels connect alerts to + contact points and silence alert instances that have matching labels. +
+ + +
+ ); + }; + return ( + ) } >
@@ -87,6 +108,7 @@ const getStyles = (theme: GrafanaTheme2) => ({ contentWrapper: css` display: flex; align-items: center; + margin-top: ${theme.spacing(2)}; `, hideButton: css` color: ${theme.colors.text.secondary}; @@ -99,4 +121,13 @@ const getStyles = (theme: GrafanaTheme2) => ({ flowChart: css` margin-right: ${theme.spacing(3)}; `, + title: css` + margin-bottom: ${theme.spacing(2)}; + `, + stepDescription: css` + margin-bottom: ${theme.spacing(2)}; + display: flex; + gap: ${theme.spacing(1)}; +)}; + `, }); diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx index f94c35ec9bc..6d83fa64b36 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx @@ -291,6 +291,7 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P For more information on queries and expressions, see Query and transform data.`} externalLink={`https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/`} linkText={`Read about query and condition`} + title="Define query and alert condition" />