1414 * limitations under the License.
1515 */
1616
17- import { useMemo , useState } from 'react'
17+ import { useEffect , useMemo , useState } from 'react'
1818import Tippy from '@tippyjs/react'
1919import { useHistory } from 'react-router-dom'
2020import { URLS } from '@Common/Constants'
2121import { ReactComponent as InfoIcon } from '../../../Assets/Icon/ic-info-filled.svg'
2222import { ReactComponent as Chat } from '../../../Assets/Icon/ic-chat-circle-dots.svg'
2323import { AppStatusDetailsChartType , AggregatedNodes , STATUS_SORTING_ORDER , NodeFilters } from './types'
2424import { 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'
2626import { IndexStore } from '../../Store'
2727import { aggregateNodes } from '../../Helpers'
2828import { Button , ButtonStyleType , ButtonVariantType } from '../Button'
@@ -35,7 +35,8 @@ const AppStatusDetailsChart = ({
3535} : AppStatusDetailsChartType ) => {
3636 const history = useHistory ( )
3737 const _appDetails = IndexStore . getAppDetails ( )
38- const [ currentFilter , setCurrentFilter ] = useState ( '' )
38+ const [ currentFilter , setCurrentFilter ] = useState < string > ( ALL_RESOURCE_KIND_FILTER )
39+ const [ flattenedNodes , setFlattenedNodes ] = useState ( [ ] )
3940
4041 const { appId, environmentId : envId } = _appDetails
4142
@@ -48,30 +49,35 @@ const AppStatusDetailsChart = ({
4849 ( ) => aggregateNodes ( _appDetails . resourceTree ?. nodes || [ ] , _appDetails . resourceTree ?. podMetadata || [ ] ) ,
4950 [ _appDetails ] ,
5051 )
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- )
6852
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 ( ) ] ,
7270 )
71+
72+ if ( filterRemoveHealth ) {
73+ newFlattenedNodes = newFlattenedNodes . filter (
74+ ( node ) => node . health . status ?. toLowerCase ( ) !== DEPLOYMENT_STATUS . HEALTHY ,
75+ )
76+ }
77+
78+ setFlattenedNodes ( newFlattenedNodes )
7379 }
74- }
80+ } , [ ` ${ nodes } ` ] )
7581
7682 function getNodeMessage ( kind : string , name : string ) {
7783 if (
@@ -96,7 +102,11 @@ const AppStatusDetailsChart = ({
96102 < div className = "pt-16 pl-20 pb-8" >
97103 < div className = "flexbox pr-20 w-100" >
98104 < div >
99- < StatusFilterButtonComponent nodes = { flattenedNodes } handleFilterClick = { onFilterClick } />
105+ < StatusFilterButtonComponent
106+ nodes = { flattenedNodes }
107+ selectedTab = { currentFilter }
108+ handleFilterClick = { onFilterClick }
109+ />
100110 </ div >
101111 </ div >
102112 </ div >
@@ -115,7 +125,7 @@ const AppStatusDetailsChart = ({
115125 flattenedNodes
116126 . filter (
117127 ( nodeDetails ) =>
118- currentFilter === 'all' ||
128+ currentFilter === ALL_RESOURCE_KIND_FILTER ||
119129 ( currentFilter === NodeFilters . drifted && nodeDetails . hasDrift ) ||
120130 nodeDetails . health . status ?. toLowerCase ( ) === currentFilter ,
121131 )
0 commit comments