Skip to content

Commit b0c234f

Browse files
authored
feat: remove example section from flux function's flyover panel (#3434)
* feat: adding feature flag in FluxToolbar * fix: removed example section from flyover panel * fix: removed extra space from new folder * chore: update the file path for components * fix: prettier * feat: removing category from flux functions * fix: prettier * fix: accidently removed example from original folder. added it back * fix: prettier * fix: undoing changes made to notebook's script editor
1 parent b1eca6d commit b0c234f

File tree

9 files changed

+330
-3
lines changed

9 files changed

+330
-3
lines changed

src/timeMachine/components/FluxToolbar.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import React, {FC, useState} from 'react'
33

44
// Components
55
import FluxFunctionsToolbar from 'src/timeMachine/components/fluxFunctionsToolbar/FluxFunctionsToolbar'
6+
import DynamicFluxFunctionsToolbar from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/FluxFunctionsToolbar'
67
import VariableToolbar from 'src/timeMachine/components/variableToolbar/VariableToolbar'
78
import FluxToolbarTab from 'src/timeMachine/components/FluxToolbarTab'
89

910
// Types
1011
import {FluxToolbarFunction} from 'src/types'
1112

13+
// Utils
14+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
15+
1216
interface Props {
1317
activeQueryBuilderTab: string
1418
onInsertFluxFunction: (func: FluxToolbarFunction) => void
@@ -31,9 +35,17 @@ const FluxToolbar: FC<Props> = ({
3135
let activeToolbar
3236

3337
if (activeTab === 'functions') {
34-
activeToolbar = (
35-
<FluxFunctionsToolbar onInsertFluxFunction={onInsertFluxFunction} />
36-
)
38+
if (isFlagEnabled('fluxDynamicDocs')) {
39+
activeToolbar = (
40+
<DynamicFluxFunctionsToolbar
41+
onInsertFluxFunction={onInsertFluxFunction}
42+
/>
43+
)
44+
} else {
45+
activeToolbar = (
46+
<FluxFunctionsToolbar onInsertFluxFunction={onInsertFluxFunction} />
47+
)
48+
}
3749
}
3850

3951
if (activeTab === 'variables') {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@import 'src/style/modules';
2+
3+
.flux-function-docs {
4+
width: 420px;
5+
height: 330px;
6+
}
7+
8+
.flux-function-docs--heading {
9+
font-weight: $cf-font-weight--bold;
10+
margin-top: $cf-space-2xs;
11+
margin-bottom: $cf-space-2xs;
12+
display: inline-block;
13+
width: 100%;
14+
15+
article:first-child & {
16+
margin-top: 0;
17+
}
18+
}
19+
20+
.flux-function-docs--snippet {
21+
background-color: $cf-grey-5;
22+
border-radius: $cf-radius;
23+
margin: $cf-space-3xs 0;
24+
padding: $cf-space-2xs;
25+
font-family: $cf-code-font;
26+
}
27+
28+
.flux-function-docs--arguments {
29+
span:first-child {
30+
font-weight: $cf-font-weight--bold;
31+
color: $c-pool;
32+
margin-right: $cf-space-3xs;
33+
}
34+
35+
span:nth-child(2) {
36+
color: $c-rainforest;
37+
font-style: italic;
38+
margin-right: $cf-border;
39+
}
40+
41+
div {
42+
margin: $cf-space-3xs 0 $cf-space-s 0;
43+
}
44+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Libraries
2+
import React, {FC, useMemo, useState, useCallback} from 'react'
3+
4+
// Components
5+
import TransformToolbarFunctions from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/TransformToolbarFunctions'
6+
import FluxToolbarSearch from 'src/timeMachine/components/FluxToolbarSearch'
7+
import {DapperScrollbars} from '@influxdata/clockface'
8+
import ErrorBoundary from 'src/shared/components/ErrorBoundary'
9+
import ToolbarFunction from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/ToolbarFunction'
10+
11+
// Constants
12+
import {FLUX_FUNCTIONS} from 'src/shared/constants/fluxFunctions'
13+
14+
// Types
15+
import {FluxToolbarFunction} from 'src/types'
16+
17+
interface OwnProps {
18+
onInsertFluxFunction: (func: FluxToolbarFunction) => void
19+
}
20+
21+
const DynamicFluxFunctionsToolbar: FC<OwnProps> = (props: OwnProps) => {
22+
const [searchTerm, setSearchTerm] = useState('')
23+
24+
const handleSearch = (searchTerm: string): void => {
25+
setSearchTerm(searchTerm)
26+
}
27+
28+
const handleClickFunction = useCallback(
29+
(func: FluxToolbarFunction) => {
30+
props.onInsertFluxFunction(func)
31+
},
32+
[props.onInsertFluxFunction]
33+
)
34+
35+
return useMemo(() => {
36+
return (
37+
<ErrorBoundary>
38+
<FluxToolbarSearch onSearch={handleSearch} resourceName="Functions" />
39+
<DapperScrollbars className="flux-toolbar--scroll-area">
40+
<div className="flux-toolbar--list" data-testid="flux-toolbar--list">
41+
<TransformToolbarFunctions
42+
funcs={FLUX_FUNCTIONS}
43+
searchTerm={searchTerm}
44+
>
45+
{sortedFunctions =>
46+
sortedFunctions.map(func => (
47+
<ToolbarFunction
48+
onClickFunction={handleClickFunction}
49+
key={`${func.name}_${func.desc}`}
50+
func={func}
51+
testID={func.name}
52+
/>
53+
))
54+
}
55+
</TransformToolbarFunctions>
56+
</div>
57+
</DapperScrollbars>
58+
</ErrorBoundary>
59+
)
60+
}, [searchTerm, handleClickFunction])
61+
}
62+
63+
export default DynamicFluxFunctionsToolbar
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Libraries
2+
import React, {FunctionComponent} from 'react'
3+
4+
// Components
5+
import {DapperScrollbars} from '@influxdata/clockface'
6+
import TooltipDescription from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/TooltipDescription'
7+
import TooltipArguments from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/TooltipArguments'
8+
import TooltipLink from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/TooltipLink'
9+
10+
// Types
11+
import {FluxToolbarFunction} from 'src/types/shared'
12+
13+
interface Props {
14+
func: FluxToolbarFunction
15+
}
16+
17+
const FunctionTooltipContents: FunctionComponent<Props> = ({
18+
func: {desc, args, link, name},
19+
}) => {
20+
return (
21+
<div className="flux-function-docs" data-testid={`flux-docs--${name}`}>
22+
<DapperScrollbars autoHide={false}>
23+
<div className="flux-toolbar--popover">
24+
<TooltipDescription description={desc} />
25+
<TooltipArguments argsList={args} />
26+
<TooltipLink link={link} />
27+
</div>
28+
</DapperScrollbars>
29+
</div>
30+
)
31+
}
32+
33+
export default FunctionTooltipContents
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Libraries
2+
import React, {FC, createRef} from 'react'
3+
4+
// Component
5+
import FunctionTooltipContents from 'src/timeMachine/components/dynamicFluxFunctionsToolbar/FunctionTooltipContents'
6+
import {
7+
Popover,
8+
PopoverPosition,
9+
PopoverInteraction,
10+
Appearance,
11+
Button,
12+
ComponentSize,
13+
ComponentColor,
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+
const defaultProps = {
26+
testID: 'flux-function',
27+
}
28+
29+
const ToolbarFunction: FC<Props> = ({func, onClickFunction, testID}) => {
30+
const functionRef = createRef<HTMLDListElement>()
31+
const handleClickFunction = () => {
32+
onClickFunction(func)
33+
}
34+
return (
35+
<>
36+
<Popover
37+
appearance={Appearance.Outline}
38+
enableDefaultStyles={false}
39+
position={PopoverPosition.ToTheLeft}
40+
triggerRef={functionRef}
41+
showEvent={PopoverInteraction.Hover}
42+
hideEvent={PopoverInteraction.Hover}
43+
distanceFromTrigger={8}
44+
testID="toolbar-popover"
45+
contents={() => <FunctionTooltipContents func={func} />}
46+
/>
47+
<dd
48+
ref={functionRef}
49+
data-testid={`flux--${testID}`}
50+
className="flux-toolbar--list-item flux-toolbar--function"
51+
>
52+
<code>{func.name}</code>
53+
<Button
54+
testID={`flux--${testID}--inject`}
55+
text="Inject"
56+
onClick={handleClickFunction}
57+
size={ComponentSize.ExtraSmall}
58+
className="flux-toolbar--injector"
59+
color={ComponentColor.Primary}
60+
/>
61+
</dd>
62+
</>
63+
)
64+
}
65+
66+
ToolbarFunction.defaultProps = defaultProps
67+
68+
export default ToolbarFunction
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, {PureComponent} from 'react'
2+
3+
interface Args {
4+
name: string
5+
type: string
6+
desc: string
7+
}
8+
9+
interface Props {
10+
argsList?: Args[]
11+
}
12+
13+
class TooltipArguments extends PureComponent<Props> {
14+
public render() {
15+
return (
16+
<article>
17+
<div className="flux-function-docs--heading">Arguments</div>
18+
<div className="flux-function-docs--snippet">{this.arguments}</div>
19+
</article>
20+
)
21+
}
22+
23+
private get arguments(): JSX.Element | JSX.Element[] {
24+
const {argsList} = this.props
25+
26+
if (argsList.length > 0) {
27+
return argsList.map(a => {
28+
return (
29+
<div className="flux-function-docs--arguments" key={a.name}>
30+
<span>{a.name}:</span>
31+
<span>{a.type}</span>
32+
<div>{a.desc}</div>
33+
</div>
34+
)
35+
})
36+
}
37+
38+
return <div className="flux-function-docs--arguments">None</div>
39+
}
40+
}
41+
42+
export default TooltipArguments
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, {SFC} from 'react'
2+
3+
interface Props {
4+
description: string
5+
}
6+
7+
const TooltipDescription: SFC<Props> = ({description}) => (
8+
<article className="flux-functions-toolbar--description">
9+
<div className="flux-function-docs--heading">Description</div>
10+
<span>{description}</span>
11+
</article>
12+
)
13+
14+
export default TooltipDescription
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, {SFC} from 'react'
2+
3+
interface Props {
4+
link: string
5+
}
6+
7+
const TooltipLink: SFC<Props> = ({link}) => (
8+
<p className="tooltip--link">
9+
Still have questions? Check out the{' '}
10+
<a target="_blank" rel="noreferrer" href={link}>
11+
Flux Docs
12+
</a>
13+
.
14+
</p>
15+
)
16+
17+
export default TooltipLink
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Libraries
2+
import React, {FC, ReactElement} from 'react'
3+
4+
// Components
5+
import {EmptyState, ComponentSize} from '@influxdata/clockface'
6+
7+
// Types
8+
import {FluxToolbarFunction} from 'src/types/shared'
9+
10+
interface Props {
11+
funcs: FluxToolbarFunction[]
12+
searchTerm?: string
13+
children: (funcs: FluxToolbarFunction[]) => JSX.Element | JSX.Element[]
14+
}
15+
16+
const TransformToolbarFunctions: FC<Props> = props => {
17+
const {searchTerm, funcs, children} = props
18+
19+
const filteredFunctions = funcs.filter(func =>
20+
func.name.toLowerCase().includes(searchTerm.toLowerCase())
21+
)
22+
23+
if (filteredFunctions.length === 0) {
24+
return (
25+
<EmptyState size={ComponentSize.ExtraSmall}>
26+
<EmptyState.Text>No functions match your search</EmptyState.Text>
27+
</EmptyState>
28+
)
29+
}
30+
31+
return children(filteredFunctions) as ReactElement<any>
32+
}
33+
34+
export default TransformToolbarFunctions

0 commit comments

Comments
 (0)