16
16
17
17
/* eslint-disable eqeqeq */
18
18
import { useEffect , useState } from 'react'
19
- import { StyledRadioGroup as RadioGroup } from '../../../Common'
19
+ import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
20
+ import { PopupMenu , StyledRadioGroup as RadioGroup } from '../../../Common'
20
21
import { NodeStatus , StatusFilterButtonType } from './types'
21
22
import { IndexStore } from '../../Store'
22
23
23
- interface TabState {
24
- status : string
25
- count : number
26
- isSelected : boolean
27
- }
24
+ import './StatusFilterButtonComponent.scss'
28
25
29
26
export const StatusFilterButtonComponent = ( { nodes, handleFilterClick } : StatusFilterButtonType ) => {
30
27
const [ selectedTab , setSelectedTab ] = useState ( 'all' )
31
28
29
+ const maxInlineFilterCount = 4
32
30
let allNodeCount : number = 0
33
31
let healthyNodeCount : number = 0
34
32
let progressingNodeCount : number = 0
@@ -50,7 +48,7 @@ export const StatusFilterButtonComponent = ({ nodes, handleFilterClick }: Status
50
48
allNodeCount += 1
51
49
} )
52
50
53
- const filters = [
51
+ const filterOptions = [
54
52
{ status : 'all' , count : allNodeCount , isSelected : selectedTab == 'all' } ,
55
53
{ status : NodeStatus . Missing , count : missingNodeCount , isSelected : NodeStatus . Missing == selectedTab } ,
56
54
{ status : NodeStatus . Degraded , count : failedNodeCount , isSelected : NodeStatus . Degraded == selectedTab } ,
@@ -61,6 +59,13 @@ export const StatusFilterButtonComponent = ({ nodes, handleFilterClick }: Status
61
59
} ,
62
60
{ status : NodeStatus . Healthy , count : healthyNodeCount , isSelected : NodeStatus . Healthy == selectedTab } ,
63
61
]
62
+ const validFilterOptions = filterOptions . filter ( ( { count } ) => count > 0 )
63
+ const displayedInlineFilters = validFilterOptions . slice (
64
+ 0 ,
65
+ Math . min ( maxInlineFilterCount , validFilterOptions . length ) ,
66
+ )
67
+ const overflowFilters =
68
+ validFilterOptions . length > maxInlineFilterCount ? validFilterOptions . slice ( maxInlineFilterCount ) : null
64
69
65
70
useEffect ( ( ) => {
66
71
if (
@@ -81,30 +86,70 @@ export const StatusFilterButtonComponent = ({ nodes, handleFilterClick }: Status
81
86
setSelectedTab ( event . target . value )
82
87
}
83
88
89
+ const handleMenuOptionClick = ( status : string ) => ( ) => setSelectedTab ( status )
90
+
91
+ const renderOverflowFilters = ( ) =>
92
+ overflowFilters ? (
93
+ < PopupMenu autoClose >
94
+ < PopupMenu . Button
95
+ isKebab
96
+ rootClassName = "flex p-4 dc__border dc__no-left-radius dc__right-radius-4 bcn-0 dc__hover-n50"
97
+ >
98
+ < ICCaretDown className = "icon-dim-14 scn-6" />
99
+ </ PopupMenu . Button >
100
+ < PopupMenu . Body rootClassName = "w-150 py-4 mt-4" style = { { left : '136px' } } >
101
+ { overflowFilters . map ( ( filter ) => (
102
+ < button
103
+ key = { filter . status }
104
+ type = "button"
105
+ className = { `dc__transparent w-100 py-6 px-8 flex left dc__gap-8 fs-13 lh-20 fw-4 cn-9 ${ filter . isSelected ? 'bcb-1' : 'bcn-0 dc__hover-n50' } ` }
106
+ onClick = { handleMenuOptionClick ( filter . status ) }
107
+ >
108
+ < span
109
+ className = { `dc__app-summary__icon icon-dim-16 ${ filter . status } ${ filter . status } --node` }
110
+ style = { { zIndex : 'unset' } }
111
+ />
112
+ < span className = "dc__first-letter-capitalize flex-grow-1 text-left" > { filter . status } </ span >
113
+ < span > { filter . count } </ span >
114
+ </ button >
115
+ ) ) }
116
+ </ PopupMenu . Body >
117
+ </ PopupMenu >
118
+ ) : null
119
+
84
120
return (
85
- < RadioGroup
86
- className = "gui-yaml-switch"
87
- name = "yaml-mode"
88
- initialTab = { selectedTab }
89
- disabled = { false }
90
- onChange = { handleTabSwitch }
91
- >
92
- { filters . length &&
93
- filters . map (
94
- ( filter : TabState , index : number ) =>
95
- filter . count > 0 && (
96
- < RadioGroup . Radio value = { filter . status } >
97
- { index !== 0 && (
98
- < span
99
- className = { `dc__app-summary__icon icon-dim-16 mr-6 ${ filter . status } ${ filter . status } --node` }
100
- style = { { zIndex : 'unset' } }
101
- />
102
- ) }
103
- < span className = "dc__first-letter-capitalize" > { filter . status } </ span >
104
- < span className = "pl-4" > ({ filter . count } )</ span >
105
- </ RadioGroup . Radio >
106
- ) ,
107
- ) }
108
- </ RadioGroup >
121
+ < >
122
+ < RadioGroup
123
+ className = { `gui-yaml-switch status-filter-button ${ overflowFilters ? 'with-menu-button' : '' } ` }
124
+ name = "status-filter-button"
125
+ initialTab = { selectedTab }
126
+ disabled = { false }
127
+ onChange = { handleTabSwitch }
128
+ >
129
+ { displayedInlineFilters . map ( ( filter , index ) => (
130
+ < RadioGroup . Radio
131
+ key = { filter . status }
132
+ value = { filter . status }
133
+ showTippy = { index !== 0 }
134
+ tippyPlacement = "top"
135
+ tippyContent = { filter . status }
136
+ tippyClass = "w-100 dc__first-letter-capitalize"
137
+ >
138
+ { index !== 0 ? (
139
+ < >
140
+ < span
141
+ className = { `dc__app-summary__icon icon-dim-16 ${ filter . status } ${ filter . status } --node` }
142
+ style = { { zIndex : 'unset' } }
143
+ />
144
+ < span > { filter . count } </ span >
145
+ </ >
146
+ ) : (
147
+ < span className = "dc__first-letter-capitalize" > { `${ filter . status } (${ filter . count } )` } </ span >
148
+ ) }
149
+ </ RadioGroup . Radio >
150
+ ) ) }
151
+ </ RadioGroup >
152
+ { renderOverflowFilters ( ) }
153
+ </ >
109
154
)
110
155
}
0 commit comments