@@ -7,15 +7,17 @@ import React, {
77 useState ,
88} from 'react'
99import {
10+ Button ,
11+ ComponentColor ,
12+ ComponentStatus ,
1013 FlexBox ,
1114 FlexDirection ,
12- SelectGroup ,
13- Button ,
1415 IconFont ,
15- ComponentStatus ,
16- ComponentColor ,
16+ Overlay ,
17+ SelectGroup ,
1718 SpinnerContainer ,
1819 TechnoSpinner ,
20+ TextArea ,
1921} from '@influxdata/clockface'
2022
2123// Components
@@ -44,6 +46,7 @@ import {RemoteDataState, SimpleTableViewProperties} from 'src/types'
4446
4547// Utils
4648import { bytesFormatter } from 'src/shared/copy/notifications'
49+ import { sqlAsFlux } from 'src/shared/contexts/query/preprocessing'
4750
4851import './Results.scss'
4952import { LanguageType } from './resources'
@@ -165,6 +168,22 @@ const TableResults: FC<{search: string}> = ({search}) => {
165168 )
166169}
167170
171+ const GraphSubQueryOverlay : FC < { text : string ; onClose : ( ) => void } > = ( {
172+ text,
173+ onClose,
174+ } ) => (
175+ < Overlay . Container maxWidth = { 600 } >
176+ < Overlay . Header title = "Subquery for graph data:" onDismiss = { onClose } />
177+ < Overlay . Body >
178+ < TextArea
179+ testID = "data-explorer-results--graph-subquery"
180+ value = { text }
181+ readOnly
182+ />
183+ </ Overlay . Body >
184+ </ Overlay . Container >
185+ )
186+
168187const GraphResults : FC = ( ) => {
169188 const { view} = useContext ( ResultsViewContext )
170189 const { result, status} = useContext ( ChildResultsContext )
@@ -186,14 +205,22 @@ const GraphResults: FC = () => {
186205}
187206
188207const WrappedOptions : FC = ( ) => {
208+ const [ showOverlay , setShowOverlay ] = useState ( false )
209+
189210 // use parent `results` so all metadata is present for the viz options
190211 const { result} = useContext ( ResultsContext )
191- const { setResult, setStatus} = useContext ( ChildResultsContext )
212+ const { queryModifers , setResult, setStatus} = useContext ( ChildResultsContext )
192213 const { view, setView, selectViewOptions, viewOptions, selectedViewOptions} =
193214 useContext ( ResultsViewContext )
194- const { resource} = useContext ( PersistanceContext )
215+ const { resource, query : text , selection } = useContext ( PersistanceContext )
195216 const dataExists = ! ! result ?. parsed
196217
218+ const subquery = useMemo (
219+ ( ) => sqlAsFlux ( text , selection ?. bucket , queryModifers ) ,
220+ [ text , selection ?. bucket , queryModifers ]
221+ )
222+ const seeGraphSubquery = ( ) => setShowOverlay ( true )
223+
197224 const updateChildResults = useCallback (
198225 update => {
199226 setView ( {
@@ -218,11 +245,18 @@ const WrappedOptions: FC = () => {
218245 selectViewOptions = { selectViewOptions }
219246 allViewOptions = { viewOptions }
220247 selectedViewOptions = { selectedViewOptions }
248+ seeSubquery = { selection ?. bucket ? seeGraphSubquery : null }
221249 />
222250 ) : null
223251
224252 return (
225253 < >
254+ < Overlay visible = { showOverlay } >
255+ < GraphSubQueryOverlay
256+ text = { subquery }
257+ onClose = { ( ) => setShowOverlay ( false ) }
258+ />
259+ </ Overlay >
226260 { subQueryOptions }
227261 < ViewOptions
228262 properties = { view . properties }
0 commit comments