From f600fa94654401200169d954ccdaf904bea2b968 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Thu, 10 Aug 2023 10:53:58 +0200 Subject: [PATCH] [v10.1.x] Alerting: Add "no-rules" to redirect to rule viewer (#73141) Co-authored-by: Gilles De Mey --- .../alerting/unified/RedirectToRuleViewer.test.tsx | 11 +++++++++++ .../alerting/unified/RedirectToRuleViewer.tsx | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx b/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx index 5b78e5f5ac1..9726a8e7cea 100644 --- a/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx +++ b/public/app/features/alerting/unified/RedirectToRuleViewer.test.tsx @@ -59,6 +59,17 @@ describe('Redirect to Rule viewer', () => { expect(screen.getAllByText('Cloud test alert')).toHaveLength(2); }); + it('should show no rules if empty response', () => { + jest.mocked(combinedRuleHooks.useCloudCombinedRulesMatching).mockReturnValue({ + rules: [], + loading: false, + error: undefined, + }); + mockRuleSourceByName(); + renderRedirectToRuleViewer('/alerting/test prom/prom alert/find'); + expect(screen.getByTestId('no-rules')).toBeInTheDocument(); + }); + it('should redirect to view rule page if only one match', () => { jest.mocked(combinedRuleHooks.useCloudCombinedRulesMatching).mockReturnValue({ rules: [mockedRules[0]], diff --git a/public/app/features/alerting/unified/RedirectToRuleViewer.tsx b/public/app/features/alerting/unified/RedirectToRuleViewer.tsx index 3805cbbbcd0..2bc0fc71f53 100644 --- a/public/app/features/alerting/unified/RedirectToRuleViewer.tsx +++ b/public/app/features/alerting/unified/RedirectToRuleViewer.tsx @@ -98,6 +98,17 @@ export function RedirectToRuleViewer(): JSX.Element | null { return ; } + if (rules.length === 0) { + return ( + +
+ No rules in {sourceName} matched the name{' '} + {name} +
+
+ ); + } + return (