1- import React , { FC , useState , useContext , useMemo , useCallback } from 'react'
1+ import React , {
2+ FC ,
3+ useCallback ,
4+ useContext ,
5+ useEffect ,
6+ useMemo ,
7+ useState ,
8+ } from 'react'
29import {
310 FlexBox ,
411 FlexDirection ,
@@ -7,9 +14,21 @@ import {
714 IconFont ,
815 ComponentStatus ,
916 ComponentColor ,
17+ SpinnerContainer ,
18+ TechnoSpinner ,
1019} from '@influxdata/clockface'
1120
12- import { RemoteDataState , SimpleTableViewProperties } from 'src/types'
21+ // Components
22+ import { SearchWidget } from 'src/shared/components/search_widget/SearchWidget'
23+ import {
24+ View ,
25+ ViewTypeDropdown ,
26+ ViewOptions ,
27+ SUPPORTED_VISUALIZATIONS ,
28+ } from 'src/visualization'
29+ import { SqlViewOptions } from 'src/dataExplorer/components/SqlViewOptions'
30+
31+ // Contexts
1332import { ResultsContext } from 'src/dataExplorer/context/results'
1433import {
1534 ResultsViewContext ,
@@ -18,18 +37,17 @@ import {
1837import { ChildResultsContext } from 'src/dataExplorer/context/results/childResults'
1938import { SidebarContext } from 'src/dataExplorer/context/sidebar'
2039import { PersistanceContext } from 'src/dataExplorer/context/persistance'
21- import { SearchWidget } from 'src/shared/components/search_widget/SearchWidget'
22- import {
23- View ,
24- ViewTypeDropdown ,
25- ViewOptions ,
26- SUPPORTED_VISUALIZATIONS ,
27- } from 'src/visualization'
40+
41+ // Types
2842import { FluxResult } from 'src/types/flows'
43+ import { RemoteDataState , SimpleTableViewProperties } from 'src/types'
2944
30- import './Results.scss'
45+ // Utils
3146import { bytesFormatter } from 'src/shared/copy/notifications'
3247
48+ import './Results.scss'
49+ import { LanguageType } from './resources'
50+
3351const QueryStat : FC = ( ) => {
3452 const { result} = useContext ( ResultsContext )
3553
@@ -154,13 +172,15 @@ const GraphResults: FC = () => {
154172
155173 return (
156174 < div className = "data-explorer-results--view" >
157- < View
158- loading = { status }
159- properties = { view . properties }
160- result = { result ?. parsed }
161- timeRange = { range }
162- hideTimer
163- />
175+ < SpinnerContainer loading = { status } spinnerComponent = { < TechnoSpinner /> } >
176+ < View
177+ loading = { status }
178+ properties = { view . properties }
179+ result = { result ?. parsed }
180+ timeRange = { range }
181+ hideTimer
182+ />
183+ </ SpinnerContainer >
164184 </ div >
165185 )
166186}
@@ -169,7 +189,10 @@ const WrappedOptions: FC = () => {
169189 // use parent `results` so all metadata is present for the viz options
170190 const { result} = useContext ( ResultsContext )
171191 const { setResult, setStatus} = useContext ( ChildResultsContext )
172- const { view, setView /* setViewOptions*/ } = useContext ( ResultsViewContext )
192+ const { view, setView, selectViewOptions, viewOptions, selectedViewOptions} =
193+ useContext ( ResultsViewContext )
194+ const { resource} = useContext ( PersistanceContext )
195+ const dataExists = ! ! result ?. parsed
173196
174197 const updateChildResults = useCallback (
175198 update => {
@@ -184,8 +207,19 @@ const WrappedOptions: FC = () => {
184207 [ setStatus , setResult ]
185208 )
186209
187- // TODO: make component with `update={setViewOptions}`, for QxBuilder-specific graph subquery options
188- const subQueryOptions = null
210+ if ( ! dataExists ) {
211+ return null
212+ }
213+
214+ const subQueryOptions =
215+ resource ?. language === LanguageType . SQL &&
216+ view . state == ViewStateType . Graph ? (
217+ < SqlViewOptions
218+ selectViewOptions = { selectViewOptions }
219+ allViewOptions = { viewOptions }
220+ selectedViewOptions = { selectedViewOptions }
221+ />
222+ ) : null
189223
190224 return (
191225 < >
@@ -200,14 +234,26 @@ const WrappedOptions: FC = () => {
200234}
201235
202236const GraphHeader : FC = ( ) => {
203- const { view, setView} = useContext ( ResultsViewContext )
237+ const { view, setView, viewOptions } = useContext ( ResultsViewContext )
204238 const { result} = useContext ( ResultsContext )
205239 const { result : subQueryResult } = useContext ( ChildResultsContext )
206- const { launch} = useContext ( SidebarContext )
240+ const { launch, clear : closeSidebar } = useContext ( SidebarContext )
241+
242+ const dataExists = ! ! result ?. parsed
207243
208244 const launcher = ( ) => {
209245 launch ( < WrappedOptions /> )
210246 }
247+ useEffect ( ( ) => {
248+ if ( dataExists ) {
249+ launcher ( )
250+ }
251+ } , [ viewOptions ] )
252+ useEffect ( ( ) => {
253+ if ( ! dataExists ) {
254+ closeSidebar ( )
255+ }
256+ } , [ dataExists ] )
211257
212258 const updateType = viewType => {
213259 setView ( {
@@ -216,7 +262,6 @@ const GraphHeader: FC = () => {
216262 } )
217263 }
218264
219- const dataExists = ! ! result ?. parsed
220265 const subqueryReturnsData = ! ! subQueryResult ?. parsed
221266 let titleText = 'Configure Visualization'
222267 if ( ! dataExists ) {
0 commit comments