Skip to content

Commit 1711fd1

Browse files
authored
feat: remove example and category from notebook's flux functions (#3439)
* feat: created new files for feature flag * feat: remove example from notebook's flux func * feat: removed categories from notebook's flux functions * fix: prettier
1 parent b0c234f commit 1711fd1

File tree

3 files changed

+186
-1
lines changed

3 files changed

+186
-1
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Libraries
2+
import React, {FC, createRef} from 'react'
3+
4+
// Component
5+
import {
6+
Popover,
7+
PopoverPosition,
8+
PopoverInteraction,
9+
Appearance,
10+
Button,
11+
ComponentSize,
12+
ComponentColor,
13+
DapperScrollbars,
14+
} from '@influxdata/clockface'
15+
16+
// Types
17+
import {FluxToolbarFunction} from 'src/types/shared'
18+
19+
interface Props {
20+
func: FluxToolbarFunction
21+
onClickFunction: (func: FluxToolbarFunction) => void
22+
testID: string
23+
}
24+
25+
interface TooltipProps {
26+
func: FluxToolbarFunction
27+
}
28+
29+
const defaultProps = {
30+
testID: 'flux-function',
31+
}
32+
33+
const FunctionTooltipContents: FC<TooltipProps> = ({func}) => {
34+
let argComponent = <div className="flux-function-docs--arguments">None</div>
35+
36+
if (func.args.length > 0) {
37+
argComponent = (
38+
<>
39+
{func.args.map(a => (
40+
<div className="flux-function-docs--arguments" key={a.name}>
41+
<span>{a.name}:</span>
42+
<span>{a.type}</span>
43+
<div>{a.desc}</div>
44+
</div>
45+
))}
46+
</>
47+
)
48+
}
49+
50+
return (
51+
<div className="flux-function-docs" data-testid={`flux-docs--${func.name}`}>
52+
<DapperScrollbars autoHide={false}>
53+
<div className="flux-toolbar--popover">
54+
<article className="flux-functions-toolbar--description">
55+
<div className="flux-function-docs--heading">Description</div>
56+
<span>{func.desc}</span>
57+
</article>
58+
<article>
59+
<div className="flux-function-docs--heading">Arguments</div>
60+
<div className="flux-function-docs--snippet">{argComponent}</div>
61+
</article>
62+
<p className="tooltip--link">
63+
Still have questions? Check out the{' '}
64+
<a target="_blank" rel="noreferrer" href={func.link}>
65+
Flux Docs
66+
</a>
67+
.
68+
</p>
69+
</div>
70+
</DapperScrollbars>
71+
</div>
72+
)
73+
}
74+
75+
const ToolbarFunction: FC<Props> = ({func, onClickFunction, testID}) => {
76+
const functionRef = createRef<HTMLDListElement>()
77+
const handleClickFunction = () => {
78+
onClickFunction(func)
79+
}
80+
81+
return (
82+
<>
83+
<Popover
84+
appearance={Appearance.Outline}
85+
enableDefaultStyles={false}
86+
position={PopoverPosition.ToTheLeft}
87+
triggerRef={functionRef}
88+
showEvent={PopoverInteraction.Hover}
89+
hideEvent={PopoverInteraction.Hover}
90+
distanceFromTrigger={8}
91+
testID="toolbar-popover"
92+
contents={() => <FunctionTooltipContents func={func} />}
93+
/>
94+
<dd
95+
ref={functionRef}
96+
data-testid={`flux--${testID}`}
97+
className="flux-toolbar--list-item flux-toolbar--function"
98+
>
99+
<code>{func.name}</code>
100+
<Button
101+
testID={`flux--${testID}--inject`}
102+
text="Inject"
103+
onClick={handleClickFunction}
104+
size={ComponentSize.ExtraSmall}
105+
className="flux-toolbar--injector"
106+
color={ComponentColor.Primary}
107+
/>
108+
</dd>
109+
</>
110+
)
111+
}
112+
113+
ToolbarFunction.defaultProps = defaultProps
114+
115+
export default ToolbarFunction
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React, {FC, useState, useMemo, useCallback} from 'react'
2+
3+
import {EmptyState, ComponentSize} from '@influxdata/clockface'
4+
import {FLUX_FUNCTIONS} from 'src/shared/constants/fluxFunctions'
5+
import {FluxToolbarFunction} from 'src/types/shared'
6+
import Fn from 'src/flows/pipes/RawFluxEditor/dynamicFunction'
7+
import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
8+
9+
interface Props {
10+
onSelect: (fn: FluxToolbarFunction) => void
11+
}
12+
13+
const DynamicFunctions: FC<Props> = ({onSelect}) => {
14+
const [search, setSearch] = useState('')
15+
const updateSearch = useCallback(
16+
text => {
17+
setSearch(text)
18+
},
19+
[search, setSearch]
20+
)
21+
22+
const filteredFunctions = FLUX_FUNCTIONS.filter(func =>
23+
func.name.toLowerCase().includes(search.toLowerCase())
24+
)
25+
26+
return useMemo(() => {
27+
let fnComponent
28+
29+
if (!filteredFunctions.length) {
30+
fnComponent = (
31+
<EmptyState size={ComponentSize.ExtraSmall}>
32+
<EmptyState.Text>No functions match your search</EmptyState.Text>
33+
</EmptyState>
34+
)
35+
} else {
36+
fnComponent = filteredFunctions.map(fn => (
37+
<Fn
38+
onClickFunction={onSelect}
39+
key={`${fn.name}_${fn.desc}`}
40+
func={fn}
41+
testID={fn.name}
42+
/>
43+
))
44+
}
45+
46+
return (
47+
<div className="flux-toolbar">
48+
<div className="flux-toolbar--search">
49+
<SearchWidget
50+
placeholderText="Filter Functions..."
51+
onSearch={updateSearch}
52+
searchTerm={search}
53+
testID="flux-toolbar-search--input"
54+
/>
55+
</div>
56+
<div className="flux-toolbar--list" data-testid="flux-toolbar--list">
57+
{fnComponent}
58+
</div>
59+
</div>
60+
)
61+
}, [search, onSelect])
62+
}
63+
64+
export default DynamicFunctions

src/flows/pipes/RawFluxEditor/view.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import {PipeProp} from 'src/types/flows'
2525
import {PipeContext} from 'src/flows/context/pipe'
2626
import {SidebarContext} from 'src/flows/context/sidebar'
2727
import Functions from 'src/flows/pipes/RawFluxEditor/functions'
28+
import DynamicFunctions from 'src/flows/pipes/RawFluxEditor/dynamicFunctions'
2829

2930
// Styles
3031
import 'src/flows/pipes/RawFluxEditor/style.scss'
3132

3233
// Utils
3334
import {event} from 'src/cloud/utils/reporting'
35+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
3436

3537
const FluxMonacoEditor = lazy(() =>
3638
import('src/shared/components/FluxMonacoEditor')
@@ -126,7 +128,11 @@ const Query: FC<PipeProp> = ({Context}) => {
126128
} else {
127129
event('Flux Panel (Notebooks) - Toggle Functions - On')
128130
show(id)
129-
showSub(<Functions onSelect={inject} />)
131+
if (isFlagEnabled('fluxDynamicDocs')) {
132+
showSub(<DynamicFunctions onSelect={inject} />)
133+
} else {
134+
showSub(<Functions onSelect={inject} />)
135+
}
130136
}
131137
}
132138

0 commit comments

Comments
 (0)