diff --git a/.betterer.results b/.betterer.results
index eedd45faab7..b56e99b02a0 100644
--- a/.betterer.results
+++ b/.betterer.results
@@ -1575,9 +1575,6 @@ exports[`better eslint`] = {
[0, 0, 0, "No untranslated strings. Wrap text with ", "6"],
[0, 0, 0, "No untranslated strings. Wrap text with ", "7"]
],
- "public/app/features/alerting/unified/RuleViewer.tsx:5381": [
- [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"]
- ],
"public/app/features/alerting/unified/Settings.tsx:5381": [
[0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"],
[0, 0, 0, "No untranslated strings. Wrap text with ", "1"],
diff --git a/public/app/features/alerting/unified/RuleViewer.test.tsx b/public/app/features/alerting/unified/RuleViewer.test.tsx
new file mode 100644
index 00000000000..c895c32a136
--- /dev/null
+++ b/public/app/features/alerting/unified/RuleViewer.test.tsx
@@ -0,0 +1,16 @@
+import { render, screen } from 'test/test-utils';
+
+import RuleViewer from './RuleViewer';
+import { stringifyErrorLike } from './utils/misc';
+
+describe('Rule Viewer page', () => {
+ it('should throw an error if rule ID cannot be decoded', () => {
+ // check console errors
+ jest.spyOn(console, 'error').mockImplementation((error) => {
+ expect(stringifyErrorLike(error)).toContain('Error: Rule ID is required');
+ });
+
+ render();
+ expect(screen.getByText(/Error: Rule ID is required/i)).toBeInTheDocument();
+ });
+});
diff --git a/public/app/features/alerting/unified/RuleViewer.tsx b/public/app/features/alerting/unified/RuleViewer.tsx
index 9df84a41b18..9beaea7325a 100644
--- a/public/app/features/alerting/unified/RuleViewer.tsx
+++ b/public/app/features/alerting/unified/RuleViewer.tsx
@@ -5,6 +5,7 @@ import { NavModelItem } from '@grafana/data';
import { isFetchError } from '@grafana/runtime';
import { Alert } from '@grafana/ui';
import { EntityNotFound } from 'app/core/components/PageNotFound/EntityNotFound';
+import { t } from 'app/core/internationalization';
import { AlertingPageWrapper } from './components/AlertingPageWrapper';
import { AlertRuleProvider } from './components/rule-viewer/RuleContext';
@@ -63,11 +64,16 @@ const RuleViewer = (): JSX.Element => {
}
// if we get here assume we can't find the rule
- return (
-
-
-
- );
+ if (!rule && !loading) {
+ return (
+
+
+
+ );
+ }
+
+ // we should never get to this state
+ return <>>;
};
export const defaultPageNav: NavModelItem = {
@@ -84,7 +90,11 @@ function ErrorMessage({ error }: ErrorMessageProps) {
return ;
}
- return {stringifyErrorLike(error)};
+ return (
+
+ {stringifyErrorLike(error)}
+
+ );
}
export default withPageErrorBoundary(RuleViewer);
diff --git a/public/app/features/alerting/unified/hooks/useCombinedRule.ts b/public/app/features/alerting/unified/hooks/useCombinedRule.ts
index 0841b794fb5..9d2e37f272e 100644
--- a/public/app/features/alerting/unified/hooks/useCombinedRule.ts
+++ b/public/app/features/alerting/unified/hooks/useCombinedRule.ts
@@ -158,7 +158,7 @@ export function useCombinedRule({ ruleIdentifier, limitAlerts }: Props): Request
}, [ruleIdentifier, ruleSourceName, promRuleNs, rulerRuleGroup, ruleSource, ruleLocation, namespaceName]);
return {
- loading: isLoadingDsFeatures || isLoadingPromRules || isLoadingRulerGroup,
+ loading: isLoadingRuleLocation || isLoadingDsFeatures || isLoadingPromRules || isLoadingRulerGroup,
error: ruleLocationError ?? promRuleNsError ?? rulerRuleGroupError,
result: rule,
};
diff --git a/public/app/features/alerting/unified/rule-editor/ExistingRuleEditor.tsx b/public/app/features/alerting/unified/rule-editor/ExistingRuleEditor.tsx
index 7d1b9d92fcf..fe33ee855ec 100644
--- a/public/app/features/alerting/unified/rule-editor/ExistingRuleEditor.tsx
+++ b/public/app/features/alerting/unified/rule-editor/ExistingRuleEditor.tsx
@@ -37,7 +37,7 @@ export function ExistingRuleEditor({ identifier }: ExistingRuleEditorProps) {
);
}
- if (!ruleWithLocation) {
+ if (!ruleWithLocation && !loading) {
return Sorry! This rule does not exist.;
}
diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json
index c2e79b5c104..6e545aedd6b 100644
--- a/public/locales/en-US/grafana.json
+++ b/public/locales/en-US/grafana.json
@@ -609,6 +609,7 @@
}
},
"rule-viewer": {
+ "error-loading": "Something went wrong loading the rule",
"prometheus-consistency-check": {
"alert-message": "Alert rule has been updated. Changes may take up to a minute to appear on the Alert rules list view.",
"alert-title": "Update in progress"
diff --git a/public/locales/pseudo-LOCALE/grafana.json b/public/locales/pseudo-LOCALE/grafana.json
index 41644d694cb..e8fb5da2873 100644
--- a/public/locales/pseudo-LOCALE/grafana.json
+++ b/public/locales/pseudo-LOCALE/grafana.json
@@ -609,6 +609,7 @@
}
},
"rule-viewer": {
+ "error-loading": "Ŝőmęŧĥįʼnģ ŵęʼnŧ ŵřőʼnģ ľőäđįʼnģ ŧĥę řūľę",
"prometheus-consistency-check": {
"alert-message": "Åľęřŧ řūľę ĥäş þęęʼn ūpđäŧęđ. Cĥäʼnģęş mäy ŧäĸę ūp ŧő ä mįʼnūŧę ŧő äppęäř őʼn ŧĥę Åľęřŧ řūľęş ľįşŧ vįęŵ.",
"alert-title": "Ůpđäŧę įʼn přőģřęşş"