Skip to content

Commit bb0b3ce

Browse files
authored
feat: adding function path ui (#5262)
1 parent b4055bb commit bb0b3ce

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/shared/components/DynamicFunctionsList.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, {FC, useCallback, useEffect, useState} from 'react'
22
import {useDispatch, useSelector} from 'react-redux'
3+
import {DapperScrollbars} from '@influxdata/clockface'
34

45
// Components
6+
import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
57
import {FluxFunction} from 'src/types/shared'
68
import Fn from 'src/shared/components/FilterList/InjectionOption'
79
import FilterList from 'src/shared/components/FilterList/FilterList'
@@ -15,6 +17,7 @@ import {getAllFluxFunctions} from 'src/shared/selectors/app'
1517
import {event} from 'src/cloud/utils/reporting'
1618
import {getFluxExample} from 'src/shared/utils/fluxExample'
1719
import {sortFuncs} from 'src/shared/utils/functions'
20+
import {isFlagEnabled} from '../utils/featureFlag'
1821

1922
interface 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}

src/timeMachine/components/FluxToolbar.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ $flux-toolbar--gap: $cf-space-2xs;
1717
width: $cf-form-md-height;
1818
flex: 0 0 $cf-form-md-height;
1919
}
20+
.flux-toolbar--path {
21+
color: $cf-grey-55;
22+
text-transform: uppercase;
23+
letter-spacing: 0.07em;
24+
border-radius: 1px;
25+
border-bottom: 2px solid $cf-grey-15;
26+
white-space: nowrap;
27+
overflow: hidden;
28+
text-overflow: ellipsis;
29+
font-weight: 600;
30+
padding: $cf-space-2xs $cf-space-xs;
31+
}
2032

2133
.flux-toolbar--tab {
2234
border-radius: $cf-radius;

0 commit comments

Comments
 (0)