11import { Table , Thead , Tr , Th , Tbody , Td } from '@patternfly/react-table' ;
2- import {
3- GreenCheckCircleIcon ,
4- ResourceIcon ,
5- Timestamp ,
6- useActiveNamespace ,
7- } from '@openshift-console/dynamic-plugin-sdk' ;
8- import { BellIcon } from '@patternfly/react-icons' ;
2+ import { ResourceIcon , Timestamp , useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk' ;
93import { Bullseye , Spinner } from '@patternfly/react-core' ;
104import { Link } from 'react-router-dom' ;
115import { ALL_NAMESPACES_KEY , RuleResource } from '../utils' ;
126import { useTranslation } from 'react-i18next' ;
137import { getRuleUrl , usePerspective } from '../hooks/usePerspective' ;
148import './incidents-styles.css' ;
159import { SeverityBadge } from '../alerting/AlertUtils' ;
10+ import { Alert , IncidentsDetailsAlert } from './model' ;
11+ import { IncidentAlertStateIcon } from './IncidentAlertStateIcon' ;
12+ import { useMemo } from 'react' ;
1613
17- const IncidentsDetailsRowTable = ( { alerts } ) => {
14+ interface IncidentsDetailsRowTableProps {
15+ alerts : Alert [ ] ;
16+ }
17+
18+ const IncidentsDetailsRowTable = ( { alerts } : IncidentsDetailsRowTableProps ) => {
1819 const [ namespace , setNamespace ] = useActiveNamespace ( ) ;
1920 const { perspective } = usePerspective ( ) ;
2021 const { t } = useTranslation ( process . env . I18N_NAMESPACE ) ;
2122
23+ const sortedAndMappedAlerts = useMemo ( ( ) => {
24+ if ( alerts && alerts . length > 0 ) {
25+ return [ ...alerts ]
26+ . sort (
27+ ( a : IncidentsDetailsAlert , b : IncidentsDetailsAlert ) =>
28+ a . alertsStartFiring - b . alertsStartFiring ,
29+ )
30+ . map ( ( alertDetails : IncidentsDetailsAlert , rowIndex ) => {
31+ return (
32+ < Tr key = { rowIndex } >
33+ < Td dataLabel = "expanded-details-alertname" >
34+ < ResourceIcon kind = { RuleResource . kind } />
35+ < Link
36+ to = { getRuleUrl ( perspective , alertDetails ?. rule , namespace ) }
37+ onClick = { ( ) => setNamespace ( ALL_NAMESPACES_KEY ) }
38+ >
39+ { alertDetails . alertname }
40+ </ Link >
41+ </ Td >
42+ < Td dataLabel = "expanded-details-namespace" > { alertDetails . namespace || '---' } </ Td >
43+ < Td dataLabel = "expanded-details-severity" >
44+ < SeverityBadge severity = { alertDetails . severity } />
45+ </ Td >
46+ < Td dataLabel = "expanded-details-firingstart" >
47+ < Timestamp timestamp = { alertDetails . alertsStartFiring } />
48+ </ Td >
49+ < Td dataLabel = "expanded-details-firingend" >
50+ { ! alertDetails . resolved ? (
51+ '---'
52+ ) : (
53+ < Timestamp timestamp = { alertDetails . alertsEndFiring } />
54+ ) }
55+ </ Td >
56+ < Td dataLabel = "expanded-details-alertstate" >
57+ < IncidentAlertStateIcon alertDetails = { alertDetails } />
58+ </ Td >
59+ </ Tr >
60+ ) ;
61+ } ) ;
62+ }
63+
64+ return null ;
65+ } , [ alerts , perspective , namespace , setNamespace ] ) ;
66+
2267 return (
2368 < Table borders = { false } variant = "compact" >
2469 < Thead >
2570 < Tr >
26- < Th width = { 25 } > { t ( 'Alert Rule ' ) } </ Th >
27- < Th width = { 15 } > { t ( 'Namespace' ) } </ Th >
28- < Th width = { 10 } > { t ( 'Severity' ) } </ Th >
29- < Th width = { 10 } > { t ( 'State ' ) } </ Th >
30- < Th width = { 20 } > { t ( 'Start ' ) } </ Th >
31- < Th width = { 20 } > { t ( 'End ' ) } </ Th >
71+ < Th width = { 25 } > { t ( 'Alert' ) } </ Th >
72+ < Th > { t ( 'Namespace' ) } </ Th >
73+ < Th > { t ( 'Severity' ) } </ Th >
74+ < Th > { t ( 'Start ' ) } </ Th >
75+ < Th > { t ( 'End ' ) } </ Th >
76+ < Th > { t ( 'State ' ) } </ Th >
3277 </ Tr >
3378 </ Thead >
3479 < Tbody >
@@ -37,49 +82,7 @@ const IncidentsDetailsRowTable = ({ alerts }) => {
3782 < Spinner aria-label = "incidents-chart-spinner" />
3883 </ Bullseye >
3984 ) : (
40- alerts ?. map ( ( alertDetails , rowIndex ) => {
41- return (
42- < Tr key = { rowIndex } >
43- < Td dataLabel = "expanded-details-alertname" >
44- < ResourceIcon kind = { RuleResource . kind } />
45- < Link
46- to = { getRuleUrl ( perspective , alertDetails ?. rule , namespace ) }
47- // Set to ALL_NAMESPACES to ensure that the alert rule is found
48- onClick = { ( ) => setNamespace ( ALL_NAMESPACES_KEY ) }
49- >
50- { alertDetails . alertname }
51- </ Link >
52- </ Td >
53- < Td dataLabel = "expanded-details-namespace" > { alertDetails . namespace || '---' } </ Td >
54- < Td dataLabel = "expanded-details-severity" >
55- < SeverityBadge severity = { alertDetails . severity } />
56- </ Td >
57- < Td dataLabel = "expanded-details-alertstate" >
58- { ! alertDetails . resolved ? (
59- < >
60- < BellIcon />
61- < span className = "expanded-details-text-margin" > Firing</ span >
62- </ >
63- ) : (
64- < >
65- < GreenCheckCircleIcon />
66- < span className = "expanded-details-text-margin" > Resolved</ span >
67- </ >
68- ) }
69- </ Td >
70- < Td dataLabel = "expanded-details-firingstart" >
71- < Timestamp simple = { true } timestamp = { alertDetails . alertsStartFiring } />
72- </ Td >
73- < Td dataLabel = "expanded-details-firingend" >
74- { ! alertDetails . resolved ? (
75- '---'
76- ) : (
77- < Timestamp simple = { true } timestamp = { alertDetails . alertsEndFiring } />
78- ) }
79- </ Td >
80- </ Tr >
81- ) ;
82- } )
85+ sortedAndMappedAlerts
8386 ) }
8487 </ Tbody >
8588 </ Table >
0 commit comments