Skip to content

Commit c57d72d

Browse files
committed
MK8S-197 - Add banner in case of failed to retrieve alerts
1 parent 0dc64c6 commit c57d72d

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

ui/src/components/DashboardAlerts.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ describe('the dashboard alerts sub-panel', () => {
9999
expect(queryByTestId('critical-alert-badge')).not.toBeInTheDocument();
100100
expect(queryByTestId('view-all-link')).not.toBeInTheDocument();
101101
});
102+
test('should display a warning banner when alerts fail to fetch', () => {
103+
(useAlertLibrary as any).mockImplementation(() => ({
104+
getPlatformAlertSelectors: () => ({
105+
alertname: ['ClusterAtRisk', 'ClusterDegraded'],
106+
}),
107+
}));
108+
(useAlerts as any).mockImplementation(() => ({
109+
alerts: [],
110+
error: new Error('Alert manager responded with 401'),
111+
}));
112+
const { getByText } = render(<DashboardAlerts />);
113+
expect(
114+
getByText('Monitoring information unavailable'),
115+
).toBeInTheDocument();
116+
expect(
117+
getByText('Some data can not be well retrieved'),
118+
).toBeInTheDocument();
119+
});
102120
test('should redirect to alert page with View All link', () => {
103121
(useAlerts as any).mockImplementation(() => ({
104122
alerts: alerts,

ui/src/components/DashboardAlerts.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spacing, Text, TextBadge } from '@scality/core-ui';
1+
import { Banner, Icon, spacing, Text, TextBadge } from '@scality/core-ui';
22
import { Box } from '@scality/core-ui/dist/next';
33
import { useMemo } from 'react';
44
import { useIntl } from 'react-intl';
@@ -61,25 +61,45 @@ const DashboardAlerts = () => {
6161
const totalAlerts = criticalAlerts.length + warningAlerts.length;
6262
return (
6363
<AlertsContainer>
64-
<div>
65-
<Text isEmphazed>
66-
{intl.formatMessage({
67-
id: 'platform_active_alerts',
68-
})}
69-
</Text>
70-
<TextBadge
71-
variant="infoPrimary"
72-
data-testid="all-alert-badge"
73-
text={totalAlerts}
74-
/>
64+
<div style={{ display: 'flex', alignItems: 'center', gap: spacing.r8 }}>
65+
<div>
66+
<Text isEmphazed>
67+
{intl.formatMessage({
68+
id: 'platform_active_alerts',
69+
})}
70+
</Text>
71+
<TextBadge
72+
variant="infoPrimary"
73+
data-testid="all-alert-badge"
74+
text={totalAlerts}
75+
/>
76+
{totalAlerts === 0 && (
77+
<div>
78+
<Text variant="Smaller" color="textSecondary">
79+
{intl.formatMessage({
80+
id: 'no_active_alerts',
81+
})}
82+
</Text>
83+
</div>
84+
)}
85+
</div>
86+
{alerts.error && (
87+
<div style={{ flex: 1 }}>
88+
<Banner
89+
variant="warning"
90+
icon={<Icon name="Exclamation-circle" />}
91+
title={intl.formatMessage({
92+
id: 'monitoring_information_unavailable',
93+
})}
94+
>
95+
{intl.formatMessage({
96+
id: 'some_data_not_retrieved',
97+
})}
98+
</Banner>
99+
</div>
100+
)}
75101
</div>
76-
{totalAlerts === 0 ? (
77-
<Text variant="Smaller" color="textSecondary">
78-
{intl.formatMessage({
79-
id: 'no_active_alerts',
80-
})}
81-
</Text>
82-
) : (
102+
{totalAlerts === 0 ? null : (
83103
<Box pr={24}>
84104
<BadgesContainer>
85105
<div>

0 commit comments

Comments
 (0)