From 77a2b34b02a89f75cf70649fdf52d73f1a72120e Mon Sep 17 00:00:00 2001 From: Tom Ratcliffe Date: Wed, 30 Apr 2025 13:51:38 +0100 Subject: [PATCH] Alerting: Make receiver optional in routing preview and handle fallback case (#104639) --- .../NotificationPreviewByAlertManager.tsx | 7 ++-- .../notificaton-preview/NotificationRoute.tsx | 40 ++++++++++++------- .../NotificationRouteDetailsModal.tsx | 19 ++++++--- .../UnknownContactPointDetails.tsx | 23 +++++++++++ public/locales/en-US/grafana.json | 4 ++ 5 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 public/app/features/alerting/unified/components/rule-editor/notificaton-preview/UnknownContactPointDetails.tsx diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreviewByAlertManager.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreviewByAlertManager.tsx index 1b5c9b29bdc..c4fdda45976 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreviewByAlertManager.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreviewByAlertManager.tsx @@ -73,14 +73,13 @@ function NotificationPreviewByAlertManager({ if (!route) { return null; } - if (!receiver) { - throw new Error('Receiver not found'); - } return ( ; instancesCount: number; alertManagerSourceName: string; expandRoute: boolean; onExpandRouteClick: (expand: boolean) => void; -}) { +} + +function NotificationRouteHeader({ + route, + receiver, + receiverNameFromRoute, + routesByIdMap, + instancesCount, + alertManagerSourceName, + expandRoute, + onExpandRouteClick, +}: NotificationRouteHeaderProps) { const styles = useStyles2(getStyles); const [showDetails, setShowDetails] = useState(false); @@ -76,7 +85,7 @@ function NotificationRouteHeader({ @ Delivered to {' '} - {receiver.name} + {receiver ? receiver.name : }
@@ -92,6 +101,7 @@ function NotificationRouteHeader({ onClose={() => setShowDetails(false)} route={route} receiver={receiver} + receiverNameFromRoute={receiverNameFromRoute} routesByIdMap={routesByIdMap} alertManagerSourceName={alertManagerSourceName} /> @@ -100,9 +110,9 @@ function NotificationRouteHeader({ ); } -interface NotificationRouteProps { +interface NotificationRouteProps extends ReceiverNameProps { route: RouteWithPath; - receiver: Receiver; + receiver?: Receiver; instanceMatches: AlertInstanceMatch[]; routesByIdMap: Map; alertManagerSourceName: string; @@ -112,6 +122,7 @@ export function NotificationRoute({ route, instanceMatches, receiver, + receiverNameFromRoute, routesByIdMap, alertManagerSourceName, }: NotificationRouteProps) { @@ -126,6 +137,7 @@ export function NotificationRoute({ void; route: RouteWithPath; - receiver: Receiver; + receiver?: Receiver; routesByIdMap: Map; alertManagerSourceName: string; } @@ -63,6 +65,7 @@ export function NotificationRouteDetailsModal({ onClose, route, receiver, + receiverNameFromRoute, routesByIdMap, alertManagerSourceName, }: NotificationRouteDetailsModalProps) { @@ -107,13 +110,17 @@ export function NotificationRouteDetailsModal({ Contact point - {receiver.name} + + {receiver ? receiver.name : } + - - See details - + {receiver ? ( + + See details + + ) : null}
diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/UnknownContactPointDetails.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/UnknownContactPointDetails.tsx new file mode 100644 index 00000000000..cae79f06f26 --- /dev/null +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/UnknownContactPointDetails.tsx @@ -0,0 +1,23 @@ +import { Tooltip } from '@grafana/ui'; +import { Trans, t } from 'app/core/internationalization'; + +const UnknownContactPointDetails = ({ receiverName }: { receiverName?: string }) => ( + + + + {receiverName ? ( + receiverName + ) : ( + Unknown contact point + )} + + + +); + +export default UnknownContactPointDetails; diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 8f807d1f473..0d1291a7644 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -2353,6 +2353,10 @@ "type-selector-button": { "add-expression": "Add expression" }, + "unknown-contact-point-details": { + "unknown-contact-point": "Unknown contact point", + "unknown-contact-point-tooltip": "Details could not be found. This may be because you do not have access to the contact point" + }, "unknown-rule-list-item": { "title-unknown-rule-type": "Unknown rule type" },