Alerting: Add "no-rules" to redirect to rule viewer (#73111)

This commit is contained in:
Gilles De Mey 2023-08-09 17:17:41 +02:00 committed by GitHub
parent e53e22ef2a
commit d9695eb507
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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]],

View File

@ -98,6 +98,17 @@ export function RedirectToRuleViewer(): JSX.Element | null {
return <Redirect to={to} />;
}
if (rules.length === 0) {
return (
<RuleViewerLayout title={pageTitle}>
<div data-testid="no-rules">
No rules in <span className={styles.param}>{sourceName}</span> matched the name{' '}
<span className={styles.param}>{name}</span>
</div>
</RuleViewerLayout>
);
}
return (
<RuleViewerLayout title={pageTitle}>
<div>