Skip to content

Commit bbe23b7

Browse files
authored
feat: view options in flux builder (#4831)
1 parent 3ee6207 commit bbe23b7

File tree

7 files changed

+205
-61
lines changed

7 files changed

+205
-61
lines changed

src/dataExplorer/components/FluxQueryBuilder.tsx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {DraggableResizer, Orientation} from '@influxdata/clockface'
55
import {QueryProvider} from 'src/shared/contexts/query'
66
import {EditorProvider} from 'src/shared/contexts/editor'
77
import {ResultsProvider} from 'src/dataExplorer/components/ResultsContext'
8+
import {SidebarProvider} from 'src/dataExplorer/context/sidebar'
89
import ResultsPane from 'src/dataExplorer/components/ResultsPane'
9-
import SidePane from 'src/dataExplorer/components/SidePane'
10+
import Sidebar from 'src/dataExplorer/components/Sidebar'
1011
import Schema from 'src/dataExplorer/components/Schema'
1112

1213
// Styles
1314
import './FluxQueryBuilder.scss'
1415

15-
const INITIAL_LEFT_VERT_RESIZER_HANDLE = 0.2
16+
const INITIAL_LEFT_VERT_RESIZER_HANDLE = 0.25
1617
const INITIAL_RIGHT_VERT_RESIZER_HANDLE = 0.8
1718

1819
const FluxQueryBuilder: FC = () => {
@@ -23,28 +24,30 @@ const FluxQueryBuilder: FC = () => {
2324

2425
return (
2526
<QueryProvider>
26-
<EditorProvider>
27-
<DraggableResizer
28-
handleOrientation={Orientation.Vertical}
29-
handlePositions={vertDragPosition}
30-
onChangePositions={setVertDragPosition}
31-
>
32-
<DraggableResizer.Panel>
33-
<Schema />
34-
</DraggableResizer.Panel>
35-
<DraggableResizer.Panel
36-
testID="flux-query-builder-middle-panel"
37-
className="new-data-explorer-rightside"
38-
>
39-
<ResultsProvider>
40-
<ResultsPane />
41-
</ResultsProvider>
42-
</DraggableResizer.Panel>
43-
<DraggableResizer.Panel>
44-
<SidePane />
45-
</DraggableResizer.Panel>
46-
</DraggableResizer>
47-
</EditorProvider>
27+
<ResultsProvider>
28+
<EditorProvider>
29+
<SidebarProvider>
30+
<DraggableResizer
31+
handleOrientation={Orientation.Vertical}
32+
handlePositions={vertDragPosition}
33+
onChangePositions={setVertDragPosition}
34+
>
35+
<DraggableResizer.Panel>
36+
<Schema />
37+
</DraggableResizer.Panel>
38+
<DraggableResizer.Panel
39+
testID="flux-query-builder-middle-panel"
40+
className="new-data-explorer-rightside"
41+
>
42+
<ResultsPane />
43+
</DraggableResizer.Panel>
44+
<DraggableResizer.Panel>
45+
<Sidebar />
46+
</DraggableResizer.Panel>
47+
</DraggableResizer>
48+
</SidebarProvider>
49+
</EditorProvider>
50+
</ResultsProvider>
4851
</QueryProvider>
4952
)
5053
}

src/dataExplorer/components/Results.tsx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import {
1111

1212
import {RemoteDataState, SimpleTableViewProperties} from 'src/types'
1313
import {ResultsContext} from 'src/dataExplorer/components/ResultsContext'
14+
import {SidebarContext} from 'src/dataExplorer/context/sidebar'
1415

1516
import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
1617
import TimeZoneDropdown from 'src/shared/components/TimeZoneDropdown'
1718
import {
1819
View,
1920
ViewTypeDropdown,
21+
ViewOptions,
2022
SUPPORTED_VISUALIZATIONS,
2123
} from 'src/visualization'
2224

@@ -60,20 +62,33 @@ const EmptyResults: FC = () => {
6062
)
6163
}
6264

65+
const WrappedOptions: FC = () => {
66+
const {result, view, setView} = useContext(ResultsContext)
67+
68+
return (
69+
<ViewOptions
70+
properties={view.properties}
71+
results={result.parsed}
72+
update={update => {
73+
Object.keys(update).forEach(k => (view.properties[k] = update[k]))
74+
75+
setView({...view})
76+
}}
77+
/>
78+
)
79+
}
80+
6381
const Results: FC = () => {
6482
const [search, setSearch] = useState('')
65-
const {result, status} = useContext(ResultsContext)
66-
const [vizState, setVizState] = useState('table')
67-
const [viewProperties, setViewProperties] = useState(
68-
SUPPORTED_VISUALIZATIONS['xy'].initial
69-
)
83+
const {result, status, view, setView} = useContext(ResultsContext)
84+
const {launch} = useContext(SidebarContext)
7085

7186
let resultView
7287

7388
if (status === RemoteDataState.NotStarted) {
7489
resultView = <EmptyResults />
7590
} else {
76-
if (vizState === 'table') {
91+
if (view.state === 'table') {
7792
resultView = (
7893
<View
7994
loading={status}
@@ -91,7 +106,7 @@ const Results: FC = () => {
91106
<div style={{height: '100%', width: '100%', padding: 12}}>
92107
<View
93108
loading={status}
94-
properties={viewProperties}
109+
properties={view.properties}
95110
result={result.parsed}
96111
/>
97112
</div>
@@ -101,12 +116,18 @@ const Results: FC = () => {
101116

102117
const dataExists = result.parsed && Object.entries(result.parsed).length
103118
const updateType = viewType => {
104-
setViewProperties(SUPPORTED_VISUALIZATIONS[viewType].initial)
119+
setView({
120+
state: 'graph',
121+
properties: SUPPORTED_VISUALIZATIONS[viewType].initial,
122+
})
123+
}
124+
125+
const launcher = () => {
126+
launch(<WrappedOptions />)
105127
}
106-
const launcher = () => {}
107128

108129
const tableHeader =
109-
vizState === 'table' ? (
130+
view.state === 'table' ? (
110131
<>
111132
<div style={{width: '300px'}}>
112133
<SearchWidget
@@ -125,10 +146,10 @@ const Results: FC = () => {
125146
) : null
126147

127148
const vizHeader =
128-
vizState === 'graph' ? (
149+
view.state === 'graph' ? (
129150
<>
130151
<ViewTypeDropdown
131-
viewType={viewProperties.type}
152+
viewType={view.properties.type}
132153
onUpdateType={updateType}
133154
/>
134155
<Button
@@ -161,17 +182,17 @@ const Results: FC = () => {
161182
id="table"
162183
name="viz-setting"
163184
value="table"
164-
active={vizState === 'table'}
165-
onClick={setVizState}
185+
active={view.state === 'table'}
186+
onClick={state => setView({...view, state})}
166187
>
167188
Table
168189
</SelectGroup.Option>
169190
<SelectGroup.Option
170191
id="graph"
171192
name="viz-setting"
172193
value="graph"
173-
active={vizState === 'graph'}
174-
onClick={setVizState}
194+
active={view.state === 'graph'}
195+
onClick={state => setView({...view, state})}
175196
>
176197
Graph
177198
</SelectGroup.Option>

src/dataExplorer/components/ResultsContext.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
import React, {FC, createContext, useState, useRef, useEffect} from 'react'
22
import {FluxResult} from 'src/types/flows'
3-
import {RemoteDataState} from 'src/types'
3+
import {RemoteDataState, ViewProperties} from 'src/types'
4+
import {SUPPORTED_VISUALIZATIONS} from 'src/visualization'
5+
6+
interface View {
7+
state: 'table' | 'graph'
8+
properties: ViewProperties
9+
}
410

511
interface ResultsContextType {
612
status: RemoteDataState
713
result: FluxResult
814
time: number
15+
view: View
916

1017
setStatus: (status: RemoteDataState) => void
1118
setResult: (result: FluxResult) => void
19+
setView: (view: View) => void
1220
}
1321

14-
export const ResultsContext = createContext<ResultsContextType>({
22+
const DEFAULT_STATE: ResultsContextType = {
1523
status: RemoteDataState.NotStarted,
1624
result: {} as FluxResult,
1725
time: null,
26+
view: {
27+
state: 'table',
28+
properties: SUPPORTED_VISUALIZATIONS['xy'].initial,
29+
},
1830

1931
setStatus: _ => {},
2032
setResult: _ => {},
21-
})
33+
setView: _ => {},
34+
}
35+
36+
export const ResultsContext = createContext<ResultsContextType>(DEFAULT_STATE)
2237

2338
export const ResultsProvider: FC = ({children}) => {
2439
const [result, setResult] = useState<FluxResult>({} as FluxResult)
@@ -28,6 +43,11 @@ export const ResultsProvider: FC = ({children}) => {
2843
RemoteDataState.NotStarted
2944
)
3045

46+
// for display, should be moved
47+
const [view, setView] = useState<View>(
48+
JSON.parse(JSON.stringify(DEFAULT_STATE.view))
49+
)
50+
3151
useEffect(() => {
3252
let running = false
3353
const check = () => {
@@ -66,9 +86,11 @@ export const ResultsProvider: FC = ({children}) => {
6686
status,
6787
result,
6888
time,
89+
view,
6990

7091
setStatus,
7192
setResult,
93+
setView,
7294
}}
7395
>
7496
{children}

src/dataExplorer/components/SidePane.scss

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import '@influxdata/clockface/dist/variables.scss';
2+
3+
.container-right-side-bar {
4+
margin-left: $cf-space-s;
5+
width: inherit;
6+
overflow-x: hidden;
7+
height: 100%;
8+
display: flex;
9+
flex-direction: column;
10+
11+
.flux-toolbar {
12+
flex-direction: column;
13+
}
14+
}
15+
16+
.flux-builder-sidebar--buttons {
17+
text-align: right;
18+
}
19+
20+
.flux-builder-sidebar--menu {
21+
padding-top: $cf-space-2xs;
22+
height: calc(
23+
100% - 30px
24+
); // this is due to a scrollbar issue where the height of the button above it makes the 100% height unreachable: https://github.com/influxdata/ui/issues/2474
25+
}
26+
27+
.flux-builder-sidebar--menu-wrapper {
28+
width: calc(100% - 16px);
29+
padding-bottom: 20px;
30+
}

src/dataExplorer/components/SidePane.tsx renamed to src/dataExplorer/components/Sidebar.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
import React, {FC, useContext, useCallback} from 'react'
2+
import {DapperScrollbars} from '@influxdata/clockface'
23

34
// Components
45
import SelectorTitle from 'src/dataExplorer/components/SelectorTitle'
5-
import {EditorContext} from 'src/shared/contexts/editor'
66
import Functions from 'src/shared/components/GroupedFunctionsList'
77
import DynamicFunctions from 'src/shared/components/DynamicFunctionsList'
88

9+
// Contexts
10+
import {SidebarContext} from 'src/dataExplorer/context/sidebar'
11+
import {EditorContext} from 'src/shared/contexts/editor'
12+
13+
// Types
914
import {FluxFunction, FluxToolbarFunction} from 'src/types'
1015

1116
// Utils
1217
import {event} from 'src/cloud/utils/reporting'
1318
import {CLOUD} from 'src/shared/constants'
1419
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
1520

16-
import './SidePane.scss'
21+
import './Sidebar.scss'
1722

1823
const TOOLTIP = `The flux standard library contains several packages, \
1924
functions, and variables which may be useful when constructing your flux query.`
2025

21-
const SidePane: FC = () => {
26+
const Sidebar: FC = () => {
2227
const {injectFunction} = useContext(EditorContext)
28+
const {visible, menu, clear} = useContext(SidebarContext)
2329

2430
const inject = useCallback(
2531
(fn: FluxFunction | FluxToolbarFunction) => {
@@ -39,6 +45,35 @@ const SidePane: FC = () => {
3945
browser = <DynamicFunctions onSelect={inject} />
4046
}
4147

48+
if (!visible && !menu) {
49+
return null
50+
}
51+
52+
if (menu) {
53+
return (
54+
<div className="container-right-side-bar">
55+
<div className="flux-builder-sidebar--buttons">
56+
<button
57+
className="cf-overlay--dismiss"
58+
type="button"
59+
onClick={() => {
60+
clear()
61+
}}
62+
/>
63+
</div>
64+
<div className="flux-builder-sidebar--menu">
65+
<DapperScrollbars
66+
noScrollX={true}
67+
thumbStopColor="gray"
68+
thumbStartColor="gray"
69+
>
70+
<div className="flux-builder-sidebar--menu-wrapper">{menu}</div>
71+
</DapperScrollbars>
72+
</div>
73+
</div>
74+
)
75+
}
76+
4277
return (
4378
<div className="container-right-side-bar">
4479
<SelectorTitle title="Flux library" info={TOOLTIP} />
@@ -47,4 +82,4 @@ const SidePane: FC = () => {
4782
)
4883
}
4984

50-
export default SidePane
85+
export default Sidebar

0 commit comments

Comments
 (0)