14
14
* limitations under the License.
15
15
*/
16
16
17
- import { useMemo , useState } from 'react'
17
+ import { useEffect , useMemo , useState } from 'react'
18
18
import Tippy from '@tippyjs/react'
19
19
import { useHistory } from 'react-router-dom'
20
20
import { URLS } from '@Common/Constants'
21
21
import { ReactComponent as InfoIcon } from '../../../Assets/Icon/ic-info-filled.svg'
22
22
import { ReactComponent as Chat } from '../../../Assets/Icon/ic-chat-circle-dots.svg'
23
23
import { AppStatusDetailsChartType , AggregatedNodes , STATUS_SORTING_ORDER , NodeFilters } from './types'
24
24
import { StatusFilterButtonComponent } from './StatusFilterButtonComponent'
25
- import { DEPLOYMENT_STATUS , APP_STATUS_HEADERS , ComponentSizeType } from '../../constants'
25
+ import { DEPLOYMENT_STATUS , APP_STATUS_HEADERS , ComponentSizeType , ALL_RESOURCE_KIND_FILTER } from '../../constants'
26
26
import { IndexStore } from '../../Store'
27
27
import { aggregateNodes } from '../../Helpers'
28
28
import { Button , ButtonStyleType , ButtonVariantType } from '../Button'
@@ -35,7 +35,8 @@ const AppStatusDetailsChart = ({
35
35
} : AppStatusDetailsChartType ) => {
36
36
const history = useHistory ( )
37
37
const _appDetails = IndexStore . getAppDetails ( )
38
- const [ currentFilter , setCurrentFilter ] = useState ( '' )
38
+ const [ currentFilter , setCurrentFilter ] = useState < string > ( ALL_RESOURCE_KIND_FILTER )
39
+ const [ flattenedNodes , setFlattenedNodes ] = useState ( [ ] )
39
40
40
41
const { appId, environmentId : envId } = _appDetails
41
42
@@ -48,30 +49,35 @@ const AppStatusDetailsChart = ({
48
49
( ) => aggregateNodes ( _appDetails . resourceTree ?. nodes || [ ] , _appDetails . resourceTree ?. podMetadata || [ ] ) ,
49
50
[ _appDetails ] ,
50
51
)
51
- const nodesKeyArray = Object . keys ( nodes ?. nodes || { } )
52
- let flattenedNodes = [ ]
53
- if ( nodesKeyArray . length > 0 ) {
54
- for ( let index = 0 ; index < nodesKeyArray . length ; index ++ ) {
55
- const element = nodes . nodes [ nodesKeyArray [ index ] ]
56
- // eslint-disable-next-line no-loop-func
57
- element . forEach ( ( childElement ) => {
58
- if ( childElement . health ) {
59
- flattenedNodes . push ( childElement )
60
- }
61
- } )
62
- }
63
- flattenedNodes . sort (
64
- ( a , b ) =>
65
- STATUS_SORTING_ORDER [ a . health . status ?. toLowerCase ( ) ] -
66
- STATUS_SORTING_ORDER [ b . health . status ?. toLowerCase ( ) ] ,
67
- )
68
52
69
- if ( filterRemoveHealth ) {
70
- flattenedNodes = flattenedNodes . filter (
71
- ( node ) => node . health . status ?. toLowerCase ( ) !== DEPLOYMENT_STATUS . HEALTHY ,
53
+ useEffect ( ( ) => {
54
+ const nodesKeyArray = Object . keys ( nodes ?. nodes || { } )
55
+ let newFlattenedNodes = [ ]
56
+ if ( nodesKeyArray . length > 0 ) {
57
+ for ( let index = 0 ; index < nodesKeyArray . length ; index ++ ) {
58
+ const element = nodes . nodes [ nodesKeyArray [ index ] ]
59
+ // eslint-disable-next-line no-loop-func
60
+ element . forEach ( ( childElement ) => {
61
+ if ( childElement . health ) {
62
+ newFlattenedNodes . push ( childElement )
63
+ }
64
+ } )
65
+ }
66
+ newFlattenedNodes . sort (
67
+ ( a , b ) =>
68
+ STATUS_SORTING_ORDER [ a . health . status ?. toLowerCase ( ) ] -
69
+ STATUS_SORTING_ORDER [ b . health . status ?. toLowerCase ( ) ] ,
72
70
)
71
+
72
+ if ( filterRemoveHealth ) {
73
+ newFlattenedNodes = newFlattenedNodes . filter (
74
+ ( node ) => node . health . status ?. toLowerCase ( ) !== DEPLOYMENT_STATUS . HEALTHY ,
75
+ )
76
+ }
77
+
78
+ setFlattenedNodes ( newFlattenedNodes )
73
79
}
74
- }
80
+ } , [ ` ${ nodes } ` ] )
75
81
76
82
function getNodeMessage ( kind : string , name : string ) {
77
83
if (
@@ -96,7 +102,11 @@ const AppStatusDetailsChart = ({
96
102
< div className = "pt-16 pl-20 pb-8" >
97
103
< div className = "flexbox pr-20 w-100" >
98
104
< div >
99
- < StatusFilterButtonComponent nodes = { flattenedNodes } handleFilterClick = { onFilterClick } />
105
+ < StatusFilterButtonComponent
106
+ nodes = { flattenedNodes }
107
+ selectedTab = { currentFilter }
108
+ handleFilterClick = { onFilterClick }
109
+ />
100
110
</ div >
101
111
</ div >
102
112
</ div >
@@ -115,7 +125,7 @@ const AppStatusDetailsChart = ({
115
125
flattenedNodes
116
126
. filter (
117
127
( nodeDetails ) =>
118
- currentFilter === 'all' ||
128
+ currentFilter === ALL_RESOURCE_KIND_FILTER ||
119
129
( currentFilter === NodeFilters . drifted && nodeDetails . hasDrift ) ||
120
130
nodeDetails . health . status ?. toLowerCase ( ) === currentFilter ,
121
131
)
0 commit comments