11import React , { FC , useCallback , useEffect , useState } from 'react'
22import { useDispatch , useSelector } from 'react-redux'
3+ import { DapperScrollbars } from '@influxdata/clockface'
34
45// Components
6+ import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
57import { FluxFunction } from 'src/types/shared'
68import Fn from 'src/shared/components/FilterList/InjectionOption'
79import FilterList from 'src/shared/components/FilterList/FilterList'
@@ -15,6 +17,7 @@ import {getAllFluxFunctions} from 'src/shared/selectors/app'
1517import { event } from 'src/cloud/utils/reporting'
1618import { getFluxExample } from 'src/shared/utils/fluxExample'
1719import { sortFuncs } from 'src/shared/utils/functions'
20+ import { isFlagEnabled } from '../utils/featureFlag'
1821
1922interface Props {
2023 onSelect : ( fn : FluxFunction ) => void
@@ -27,6 +30,7 @@ const DynamicFunctionsList: FC<Props> = ({onSelect}) => {
2730 const [ termRecorded , setTermRecorded ] = useState ( '' )
2831 const [ tooltipPopup , setTooltipPopup ] = useState ( false )
2932 const [ hoveredFunction , setHoverdFunction ] = useState ( '' )
33+ const [ search , onSearch ] = useState < string > ( '' )
3034
3135 const dispatch = useDispatch ( )
3236 const fluxFunctions = useSelector ( getAllFluxFunctions )
@@ -60,6 +64,74 @@ const DynamicFunctionsList: FC<Props> = ({onSelect}) => {
6064 [ onSelect ]
6165 )
6266
67+ if ( isFlagEnabled ( 'showFnPath' ) ) {
68+ const _search = search . toLocaleLowerCase ( )
69+ const filteredpaths = fluxFunctions
70+ . filter ( fn =>
71+ `${ fn . path } ${ fn . package } ${ fn . name } `
72+ . toLocaleLowerCase ( )
73+ . includes ( _search )
74+ )
75+ . reduce ( ( acc , curr ) => {
76+ if ( ! acc [ curr . path ] ) {
77+ acc [ curr . path ] = [ ]
78+ }
79+
80+ acc [ curr . path ] . push ( curr )
81+ return acc
82+ } , { } )
83+ const filtereditems = Object . keys ( filteredpaths )
84+ . sort ( ( a , b ) =>
85+ a . toLocaleLowerCase ( ) . localeCompare ( b . toLocaleLowerCase ( ) )
86+ )
87+ . reduce ( ( acc , curr ) => {
88+ acc . push (
89+ < div className = "flux-toolbar--path" key = { `fn-head-${ curr } ` } >
90+ { curr }
91+ </ div >
92+ )
93+
94+ return acc . concat (
95+ filteredpaths [ curr ]
96+ . sort ( ( a , b ) =>
97+ `${ a . package } ${ a . name } `
98+ . toLocaleLowerCase ( )
99+ . localeCompare ( `${ b . package } ${ b . name } ` . toLocaleLowerCase ( ) )
100+ )
101+ . map ( fn => (
102+ < Fn
103+ onClick = { handleSelectItem }
104+ extractor = { fn =>
105+ `${ ( fn as FluxFunction ) . package } .${ ( fn as FluxFunction ) . name } `
106+ }
107+ key = { `${ fn . path } -${ fn . package } -${ fn . name } ` }
108+ option = { fn }
109+ testID = { fn . name }
110+ ToolTipContent = { FluxDocsTooltipContent }
111+ setToolTipPopup = { setTooltipPopup }
112+ setHoverdFunction = { setHoverdFunction }
113+ />
114+ ) )
115+ )
116+ } , [ ] )
117+
118+ return (
119+ < div className = "flux-toolbar" >
120+ < div className = "flux-toolbar--search" >
121+ < SearchWidget
122+ placeholderText = "Filter by Package or Function"
123+ onSearch = { onSearch }
124+ searchTerm = { search }
125+ testID = "flux-toolbar-search--input"
126+ />
127+ </ div >
128+ < div className = "flux-toolbar--list" data-testid = "flux-toolbar--list" >
129+ < DapperScrollbars > { filtereditems } </ DapperScrollbars >
130+ </ div >
131+ </ div >
132+ )
133+ }
134+
63135 const render = fn => (
64136 < Fn
65137 onClick = { handleSelectItem }
0 commit comments