From fbe43100aa3049df6cdd65c62b5930e6862641c9 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Wed, 27 Mar 2024 16:50:41 +0100 Subject: [PATCH] add paused badge --- .../components/rule-viewer/PausedBadge.tsx | 13 ++++++++++ .../components/rule-viewer/RuleViewer.tsx | 26 +++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 public/app/features/alerting/unified/components/rule-viewer/PausedBadge.tsx diff --git a/public/app/features/alerting/unified/components/rule-viewer/PausedBadge.tsx b/public/app/features/alerting/unified/components/rule-viewer/PausedBadge.tsx new file mode 100644 index 00000000000..1bb27750bc8 --- /dev/null +++ b/public/app/features/alerting/unified/components/rule-viewer/PausedBadge.tsx @@ -0,0 +1,13 @@ +import React from 'react'; + +import { Icon, Stack, Text } from '@grafana/ui'; + +export default function PausedBadge() { + return ( + + + Paused + + + ); +} diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx index c03e043f52b..5b217a5e869 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx @@ -6,7 +6,6 @@ import { NavModelItem, UrlQueryValue } from '@grafana/data'; import { Alert, LinkButton, Stack, TabContent, Text, TextLink, useStyles2 } from '@grafana/ui'; import { PageInfoItem } from 'app/core/components/Page/types'; import { useQueryParams } from 'app/core/hooks/useQueryParams'; -import InfoPausedRule from 'app/features/alerting/unified/components/InfoPausedRule'; import { CombinedRule, RuleHealth, RuleIdentifier } from 'app/types/unified-alerting'; import { PromAlertingRuleState, PromRuleType } from 'app/types/unified-alerting-dto'; @@ -31,6 +30,7 @@ import { RedirectToCloneRule } from '../rules/CloneRule'; import { useAlertRulePageActions } from './Actions'; import { useDeleteModal } from './DeleteModal'; import { FederatedRuleWarning } from './FederatedRuleWarning'; +import PausedBadge from './PausedBadge'; import { useAlertRule } from './RuleContext'; import { RecordingBadge, StateBadge } from './StateBadges'; import { Details } from './tabs/Details'; @@ -71,7 +71,10 @@ const RuleViewer = () => { const isProvisioned = isGrafanaRulerRule(rule.rulerRule) && Boolean(rule.rulerRule.grafana_alert.provenance); const isPaused = isGrafanaRulerRule(rule.rulerRule) && isGrafanaRulerRulePaused(rule.rulerRule); + const showError = hasError && !isPaused; + const summary = annotations[Annotation.summary]; + return ( { renderTitle={(title) => ( @@ -89,7 +93,6 @@ const RuleViewer = () => { info={createMetadata(rule)} subTitle={ <Stack direction="column"> - {isPaused && <InfoPausedRule />} {summary} {/* alerts and notifications and stuff */} {isFederatedRule && <FederatedRuleWarning />} @@ -98,7 +101,7 @@ const RuleViewer = () => { <ProvisioningAlert resource={ProvisionedResource.AlertRule} bottomSpacing={0} topSpacing={2} /> )} {/* error state */} - {hasError && ( + {showError && ( <Alert title="Something went wrong when evaluating this alert rule" bottomSpacing={0} topSpacing={2}> <pre style={{ marginBottom: 0 }}> <code>{rule.promRule?.lastError ?? 'No error message'}</code> @@ -213,13 +216,14 @@ export const createListFilterLink = (values: Array<[string, string]>) => { interface TitleProps { name: string; + paused?: boolean; // recording rules don't have a state state?: PromAlertingRuleState; health?: RuleHealth; ruleType?: PromRuleType; } -export const Title = ({ name, state, health, ruleType }: TitleProps) => { +export const Title = ({ name, paused = false, state, health, ruleType }: TitleProps) => { const styles = useStyles2(getStyles); const isRecordingRule = ruleType === PromRuleType.Recording; @@ -229,9 +233,15 @@ export const Title = ({ name, state, health, ruleType }: TitleProps) => { <Text variant="h1" truncate> {name} </Text> - {/* recording rules won't have a state */} - {state && <StateBadge state={state} health={health} />} - {isRecordingRule && <RecordingBadge health={health} />} + {paused ? ( + <PausedBadge /> + ) : ( + <> + {/* recording rules won't have a state */} + {state && <StateBadge state={state} health={health} />} + {isRecordingRule && <RecordingBadge health={health} />} + </> + )} </div> ); };