diff --git a/public/app/features/alerting/unified/components/rule-viewer/v2/StateBadges.tsx b/public/app/features/alerting/unified/components/rule-viewer/v2/StateBadges.tsx index 94ac7edb466..abda0ee41e8 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/v2/StateBadges.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/v2/StateBadges.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { ReactNode } from 'react'; import { Stack, Text } from '@grafana/ui'; import { RuleHealth } from 'app/types/unified-alerting'; @@ -18,14 +18,7 @@ export const RecordingBadge = ({ health }: RecordingBadgeProps) => { const color = hasError ? 'error' : 'success'; const text = hasError ? 'Recording error' : 'Recording'; - return ( - - - - {text} - - - ); + return ; }; // we're making a distinction here between the "state" of the rule and its "health". @@ -36,7 +29,7 @@ interface StateBadgeProps { export const StateBadge = ({ state, health }: StateBadgeProps) => { let stateLabel: string; - let color: 'success' | 'error' | 'warning'; + let color: BadgeColor; switch (state) { case PromAlertingRuleState.Inactive: @@ -64,12 +57,24 @@ export const StateBadge = ({ state, health }: StateBadgeProps) => { stateLabel = 'No data'; } + return ; +}; + +// the generic badge component +type BadgeColor = 'success' | 'error' | 'warning'; + +interface BadgeProps { + color: BadgeColor; + text: NonNullable; +} + +function Badge({ color, text }: BadgeProps) { return ( - + - {stateLabel} + {text} ); -}; +}