-
Notifications
You must be signed in to change notification settings - Fork 699
Expand file tree
/
Copy pathMonitoringOverviewAlerts.tsx
More file actions
68 lines (64 loc) · 2.35 KB
/
MonitoringOverviewAlerts.tsx
File metadata and controls
68 lines (64 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as React from 'react';
import { Alert } from '@patternfly/react-core';
import * as _ from 'lodash';
import { Link } from 'react-router-dom-v5-compat';
import { Alert as AlertType, useActivePerspective } from '@console/dynamic-plugin-sdk';
import { labelsToParams } from '@console/internal/components/monitoring/utils';
import { fromNow } from '@console/internal/components/utils/datetime';
import { sortMonitoringAlerts } from '@console/shared';
import { getAlertType } from './monitoring-overview-alerts-utils';
import './MonitoringOverviewAlerts.scss';
interface MonitoringOverviewAlertsProps {
alerts: AlertType[];
}
const MonitoringOverviewAlerts: React.FC<MonitoringOverviewAlertsProps> = ({ alerts }) => {
const [activePerspective, setActivePerspective] = useActivePerspective();
const sortedAlerts = sortMonitoringAlerts(alerts);
return (
<div className="odc-monitoring-overview-alerts">
{_.map(sortedAlerts, (alert: AlertType) => {
const {
activeAt,
annotations: { message },
labels: { severity, alertname, namespace },
rule: { name, id },
} = alert;
const alertDetailsPageLink =
activePerspective === 'dev'
? `/dev-monitoring/ns/${namespace}/alerts/${id}?${labelsToParams(alert.labels)}`
: `/monitoring/alerts/${id}?${labelsToParams(alert.labels)}`;
return (
<Alert
variant={getAlertType(severity)}
isInline
title={
<Link
onClick={() => {
if (
alertDetailsPageLink.startsWith('/dev-monitoring') &&
activePerspective !== 'dev'
) {
setActivePerspective('dev');
}
}}
to={alertDetailsPageLink}
>
{name}
</Link>
}
key={`${alertname}-${id}`}
>
{message}
<div className="odc-monitoring-overview-alerts__timestamp">
<span className="pf-v6-u-font-size-xs pf-v6-u-text-color-subtle">
{fromNow(activeAt)}
</span>
</div>
</Alert>
);
})}
</div>
);
};
export const InternalMonitoringOverviewAlerts = MonitoringOverviewAlerts;
export default MonitoringOverviewAlerts;