1- import { Button , Text , TextContent , TextVariants , ToolbarGroup , ToolbarItem , Tooltip } from '@patternfly/react-core' ;
2- import { LongArrowAltDownIcon , LongArrowAltUpIcon , TimesCircleIcon , TimesIcon } from '@patternfly/react-icons' ;
1+ import {
2+ Button ,
3+ Dropdown ,
4+ DropdownItem ,
5+ DropdownList ,
6+ MenuToggle ,
7+ MenuToggleElement ,
8+ Text ,
9+ TextContent ,
10+ TextVariants ,
11+ ToolbarGroup ,
12+ ToolbarItem ,
13+ Tooltip
14+ } from '@patternfly/react-core' ;
15+ import {
16+ ArrowsAltVIcon ,
17+ BanIcon ,
18+ CheckIcon ,
19+ LongArrowAltDownIcon ,
20+ LongArrowAltUpIcon ,
21+ TimesCircleIcon ,
22+ TimesIcon
23+ } from '@patternfly/react-icons' ;
324import * as _ from 'lodash' ;
425import * as React from 'react' ;
526import { useTranslation } from 'react-i18next' ;
@@ -13,7 +34,7 @@ import {
1334} from '../../../model/filters' ;
1435import { QuickFilter } from '../../../model/quick-filters' ;
1536import { autoCompleteCache } from '../../../utils/autocomplete-cache' ;
16- import { getFilterFullName , hasSrcDstFilters , swapFilters } from '../../../utils/filters-helper' ;
37+ import { getFilterFullName , hasSrcDstFilters , swapFilters , swapFilterValue } from '../../../utils/filters-helper' ;
1738import { getPathWithParams , netflowTrafficPath } from '../../../utils/url' ;
1839import { navigate } from '../../dynamic-loader/dynamic-loader' ;
1940import { LinksOverflow } from '../links-overflow' ;
@@ -40,6 +61,8 @@ export const FiltersChips: React.FC<FiltersChipsProps> = ({
4061} ) => {
4162 const { t } = useTranslation ( 'plugin__netobserv-plugin' ) ;
4263
64+ const [ openedDropdown , setOpenedDropdown ] = React . useState < string > ( ) ;
65+
4366 const setFiltersList = React . useCallback (
4467 ( list : Filter [ ] ) => {
4568 setFilters ( { ...filters , list : list } ) ;
@@ -101,40 +124,93 @@ export const FiltersChips: React.FC<FiltersChipsProps> = ({
101124 </ Text >
102125 </ Tooltip >
103126 { chipFilter . values . map ( ( chipFilterValue , fvIndex ) => {
127+ if ( isForced || chipFilterValue . disabled ) {
128+ return (
129+ < div key = { fvIndex } className = { `custom-chip ${ chipFilterValue . disabled ? 'disabled-value' : '' } ` } >
130+ < Tooltip
131+ content = { `${ chipFilterValue . disabled ? t ( 'Enable' ) : t ( 'Disable' ) } ${ fullName } '${
132+ chipFilterValue . display || chipFilterValue . v
133+ } ' ${ t ( 'filter' ) } `}
134+ >
135+ < Text
136+ component = { TextVariants . p }
137+ onClick = { ( ) => {
138+ chipFilterValue . disabled = ! chipFilterValue . disabled ;
139+ setFilters ( _ . cloneDeep ( filters ) ) ;
140+ } }
141+ >
142+ { chipFilterValue . display ? chipFilterValue . display : chipFilterValue . v }
143+ </ Text >
144+ </ Tooltip >
145+ </ div >
146+ ) ;
147+ }
148+
149+ const dropdownId = `${ chipFilter . def . id } -${ fvIndex } ` ;
104150 return (
105- < div key = { fvIndex } className = { `custom-chip ${ chipFilterValue . disabled ? 'disabled-value' : '' } ` } >
106- < Tooltip
107- content = { `${ chipFilterValue . disabled ? t ( 'Enable' ) : t ( 'Disable' ) } ${ fullName } '${
108- chipFilterValue . display || chipFilterValue . v
109- } ' ${ t ( 'filter' ) } `}
110- >
111- < Text
112- component = { TextVariants . p }
151+ < Dropdown
152+ key = { fvIndex }
153+ isOpen = { dropdownId === openedDropdown }
154+ onOpenChange = { ( isOpen : boolean ) => setOpenedDropdown ( isOpen ? dropdownId : undefined ) }
155+ toggle = { ( toggleRef : React . Ref < MenuToggleElement > ) => (
156+ < MenuToggle
157+ ref = { toggleRef }
158+ className = { `custom-chip ${ chipFilterValue . disabled ? 'disabled-value' : '' } ` }
159+ isExpanded = { dropdownId === openedDropdown }
160+ onClick = { ( ) => setOpenedDropdown ( openedDropdown === dropdownId ? undefined : dropdownId ) }
161+ >
162+ { chipFilterValue . display ? chipFilterValue . display : chipFilterValue . v }
163+ </ MenuToggle >
164+ ) }
165+ >
166+ < DropdownList >
167+ < DropdownItem
168+ key = "disable"
113169 onClick = { ( ) => {
114- //switch value
115170 chipFilterValue . disabled = ! chipFilterValue . disabled ;
116171 setFilters ( _ . cloneDeep ( filters ) ) ;
172+ setOpenedDropdown ( undefined ) ;
117173 } }
118174 >
119- { chipFilterValue . display ? chipFilterValue . display : chipFilterValue . v }
120- </ Text >
121- </ Tooltip >
122- { ! isForced && (
123- < Button
124- variant = "plain"
175+ { chipFilterValue . disabled && < CheckIcon /> }
176+ { ! chipFilterValue . disabled && < BanIcon /> }
177+ { chipFilterValue . disabled ? t ( 'Enable' ) : t ( 'Disable' ) }
178+ </ DropdownItem >
179+ { ( chipFilter . def . id . startsWith ( 'src_' ) || chipFilter . def . id . startsWith ( 'dst_' ) ) && (
180+ < DropdownItem
181+ key = "swap"
182+ onClick = { ( ) => {
183+ const swapped = swapFilterValue (
184+ filterDefinitions ,
185+ filters ! . list ,
186+ chipFilter . def . id ,
187+ chipFilterValue
188+ ) ;
189+ setFilters ( { ...filters ! , list : swapped } ) ;
190+ setOpenedDropdown ( undefined ) ;
191+ } }
192+ >
193+ < ArrowsAltVIcon style = { { transform : 'rotate(90deg)' } } />
194+ { t ( 'Swap' ) }
195+ </ DropdownItem >
196+ ) }
197+ < DropdownItem
198+ key = "remove"
125199 onClick = { ( ) => {
126200 chipFilter . values = chipFilter . values . filter ( val => val . v !== chipFilterValue . v ) ;
127201 if ( _ . isEmpty ( chipFilter . values ) ) {
128202 setFiltersList ( removeFromFilters ( filters . list , chipFilter ) ) ;
129203 } else {
130204 setFilters ( _ . cloneDeep ( filters ) ) ;
131205 }
206+ setOpenedDropdown ( undefined ) ;
132207 } }
133208 >
134209 < TimesIcon />
135- </ Button >
136- ) }
137- </ div >
210+ { t ( 'Remove' ) }
211+ </ DropdownItem >
212+ </ DropdownList >
213+ </ Dropdown >
138214 ) ;
139215 } ) }
140216 { ! isForced && (
0 commit comments