1- import { useRef , useState , useEffect } from 'react' ;
21import { Table , Thead , Tr , Th , Tbody , Td } from '@patternfly/react-table' ;
32import {
43 GreenCheckCircleIcon ,
@@ -7,71 +6,24 @@ import {
76 useActiveNamespace ,
87} from '@openshift-console/dynamic-plugin-sdk' ;
98import { BellIcon } from '@patternfly/react-icons' ;
10- import { Bullseye , DropdownItem , Spinner , Tooltip } from '@patternfly/react-core' ;
11- import { Link , useHistory } from 'react-router-dom' ;
12- import { AlertResource } from '../utils' ;
13- import KebabDropdown from '../kebab-dropdown' ;
9+ import { Bullseye , Spinner } from '@patternfly/react-core' ;
10+ import { Link } from 'react-router-dom' ;
11+ import { RuleResource } from '../utils' ;
1412import { useTranslation } from 'react-i18next' ;
15- import {
16- getAlertUrl ,
17- getLegacyObserveState ,
18- getNewSilenceAlertUrl ,
19- getRuleUrl ,
20- usePerspective ,
21- } from '../hooks/usePerspective' ;
22- import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons' ;
13+ import { getRuleUrl , usePerspective } from '../hooks/usePerspective' ;
2314import './incidents-styles.css' ;
2415import { SeverityBadge } from '../alerting/AlertUtils' ;
25- import { useAlertsPoller } from '../hooks/useAlertsPoller' ;
26- import { useSelector } from 'react-redux' ;
27- import isEqual from 'lodash/isEqual' ;
28- import { MonitoringState } from 'src/reducers/observe' ;
29-
30- function useDeepCompareMemoize ( value ) {
31- const ref = useRef ( ) ;
32-
33- if ( ! isEqual ( value , ref . current ) ) {
34- ref . current = value ;
35- }
36-
37- return ref . current ;
38- }
3916
4017const IncidentsDetailsRowTable = ( { alerts } ) => {
41- const history = useHistory ( ) ;
4218 const [ namespace ] = useActiveNamespace ( ) ;
43- useAlertsPoller ( ) ;
44- const { perspective, alertsKey } = usePerspective ( ) ;
45- const [ alertsWithMatchedData , setAlertsWithMatchedData ] = useState ( [ ] ) ;
19+ const { perspective } = usePerspective ( ) ;
4620 const { t } = useTranslation ( process . env . I18N_NAMESPACE ) ;
4721
48- const alertsWithLabels = useSelector ( ( state : MonitoringState ) =>
49- getLegacyObserveState ( perspective , state ) ?. get ( alertsKey ) ,
50- ) ;
51-
52- function findMatchingAlertsWithId ( alertsArray , rulesArray ) {
53- return alertsArray . map ( ( alert ) => {
54- if ( ! Array . isArray ( rulesArray ?. data ) ) {
55- return alert ;
56- }
57- const match = rulesArray . data . find ( ( rule ) => alert . alertname === rule . labels . alertname ) ;
58- if ( match ) {
59- return { ...alert , rule : match } ;
60- }
61- return alert ;
62- } ) ;
63- }
64- const memoizedAlerts = useDeepCompareMemoize ( alerts ) ;
65-
66- useEffect ( ( ) => {
67- setAlertsWithMatchedData ( findMatchingAlertsWithId ( memoizedAlerts , alertsWithLabels ) ) ;
68- } , [ memoizedAlerts , alertsWithLabels ] ) ;
69-
7022 return (
7123 < Table borders = { false } variant = "compact" >
7224 < Thead >
7325 < Tr >
74- < Th width = { 25 } > { t ( 'Alert Name ' ) } </ Th >
26+ < Th width = { 25 } > { t ( 'Alert Rule ' ) } </ Th >
7527 < Th width = { 15 } > { t ( 'Namespace' ) } </ Th >
7628 < Th width = { 10 } > { t ( 'Severity' ) } </ Th >
7729 < Th width = { 10 } > { t ( 'State' ) } </ Th >
@@ -80,40 +32,19 @@ const IncidentsDetailsRowTable = ({ alerts }) => {
8032 </ Tr >
8133 </ Thead >
8234 < Tbody >
83- { ! alertsWithMatchedData ? (
35+ { ! alerts ? (
8436 < Bullseye >
8537 < Spinner aria-label = "incidents-chart-spinner" />
8638 </ Bullseye >
8739 ) : (
88- alertsWithMatchedData ?. map ( ( alertDetails , rowIndex ) => {
40+ alerts ?. map ( ( alertDetails , rowIndex ) => {
8941 return (
9042 < Tr key = { rowIndex } >
9143 < Td dataLabel = "expanded-details-alertname" >
92- < ResourceIcon kind = { AlertResource . kind } />
93- < Link
94- to = {
95- alertDetails ?. rule
96- ? getAlertUrl (
97- perspective ,
98- alertDetails ,
99- alertDetails ?. rule ?. rule . id ,
100- namespace ,
101- )
102- : '#'
103- }
104- style = {
105- ! alertDetails ?. rule || alertDetails . resolved
106- ? { pointerEvents : 'none' , color : 'inherit' , textDecoration : 'inherit' }
107- : { }
108- }
109- >
44+ < ResourceIcon kind = { RuleResource . kind } />
45+ < Link to = { getRuleUrl ( perspective , alertDetails ?. rule , namespace ) } >
11046 { alertDetails . alertname }
11147 </ Link >
112- { ( ! alertDetails ?. rule || alertDetails . resolved ) && (
113- < Tooltip content = { < div > No details can be shown for inactive alerts.</ div > } >
114- < OutlinedQuestionCircleIcon className = "expanded-details-text-margin" />
115- </ Tooltip >
116- ) }
11748 </ Td >
11849 < Td dataLabel = "expanded-details-namespace" > { alertDetails . namespace || '---' } </ Td >
11950 < Td dataLabel = "expanded-details-severity" >
@@ -142,35 +73,6 @@ const IncidentsDetailsRowTable = ({ alerts }) => {
14273 < Timestamp simple = { true } timestamp = { alertDetails . alertsEndFiring } />
14374 ) }
14475 </ Td >
145- < Td >
146- < KebabDropdown
147- dropdownItems = { [
148- < DropdownItem
149- component = "button"
150- key = "silence alert"
151- isDisabled = { ! alertDetails ?. rule }
152- onClick = { ( ) =>
153- history . push (
154- getNewSilenceAlertUrl ( perspective , alertDetails . rule , namespace ) ,
155- )
156- }
157- >
158- { t ( 'Silence alert' ) }
159- </ DropdownItem > ,
160- < DropdownItem
161- key = "view-rule"
162- isDisabled = { alertDetails ?. alertstate === 'resolved' ? true : false }
163- >
164- < Link
165- to = { getRuleUrl ( perspective , alertDetails ?. rule ?. rule ) }
166- style = { { color : 'inherit' , textDecoration : 'inherit' } }
167- >
168- { t ( 'View alerting rule' ) }
169- </ Link >
170- </ DropdownItem > ,
171- ] }
172- />
173- </ Td >
17476 </ Tr >
17577 ) ;
17678 } )
0 commit comments