1+ // Libraries
12import React , { FC , lazy , Suspense , useState , useContext } from 'react'
23import {
34 DraggableResizer ,
@@ -15,20 +16,28 @@ import {
1516} from '@influxdata/clockface'
1617import { createLocalStorageStateHook } from 'use-local-storage-state'
1718
19+ // Contexts
20+ import { ResultsContext } from 'src/dataExplorer/components/ResultsContext'
21+ import { QueryContext } from 'src/shared/contexts/query'
22+
23+ // Components
1824import TimeRangeDropdown from 'src/shared/components/TimeRangeDropdown'
1925import Results from 'src/dataExplorer/components/Results'
20- import { ResultsContext } from 'src/dataExplorer/components/ResultsContext'
21- import { TimeRange } from 'src/types'
2226import { SubmitQueryButton } from 'src/timeMachine/components/SubmitQueryButton'
27+ import QueryTime from 'src/dataExplorer/components/QueryTime'
28+
29+ // Types
30+ import { TimeRange } from 'src/types'
31+
32+ // Utils
33+ import { getRangeVariable } from 'src/variables/utils/getTimeRangeVars'
2334import { downloadTextFile } from 'src/shared/utils/download'
2435import { event } from 'src/cloud/utils/reporting'
25- import { QueryContext } from 'src/shared/contexts/query'
2636import { notify } from 'src/shared/actions/notifications'
27- import { TIME_RANGE_START , TIME_RANGE_STOP } from 'src/variables/constants'
28- import { getRangeVariable } from 'src/variables/utils/getTimeRangeVars'
2937import { getWindowPeriodVariableFromVariables } from 'src/variables/utils/getWindowVars'
30- import QueryTime from 'src/dataExplorer/components/QueryTime'
3138
39+ // Constants
40+ import { TIME_RANGE_START , TIME_RANGE_STOP } from 'src/variables/constants'
3241import { DEFAULT_TIME_RANGE } from 'src/shared/constants/timeRanges'
3342
3443const FluxMonacoEditor = lazy ( ( ) =>
@@ -42,6 +51,37 @@ const useLocalStorageState = createLocalStorageStateHook(
4251const INITIAL_HORIZ_RESIZER_HANDLE = 0.2
4352const fakeNotify = notify
4453
54+ const rangeToParam = ( timeRange : TimeRange ) => {
55+ let timeRangeStart , timeRangeStop
56+
57+ if ( ! timeRange ) {
58+ timeRangeStart = timeRangeStop = null
59+ } else {
60+ if ( timeRange . type === 'selectable-duration' ) {
61+ timeRangeStart = '-' + timeRange . duration
62+ } else if ( timeRange . type === 'duration' ) {
63+ timeRangeStart = '-' + timeRange . lower
64+ } else if ( isNaN ( Date . parse ( timeRange . lower ) ) ) {
65+ timeRangeStart = null
66+ } else {
67+ timeRangeStart = new Date ( timeRange . lower ) . toISOString ( )
68+ }
69+
70+ if ( ! timeRange . upper ) {
71+ timeRangeStop = 'now()'
72+ } else if ( isNaN ( Date . parse ( timeRange . upper ) ) ) {
73+ timeRangeStop = null
74+ } else {
75+ timeRangeStop = new Date ( timeRange . upper ) . toISOString ( )
76+ }
77+ }
78+
79+ return {
80+ timeRangeStart,
81+ timeRangeStop,
82+ }
83+ }
84+
4585const ResultsPane : FC = ( ) => {
4686 const [ horizDragPosition , setHorizDragPosition ] = useState ( [
4787 INITIAL_HORIZ_RESIZER_HANDLE ,
@@ -54,7 +94,9 @@ const ResultsPane: FC = () => {
5494
5595 const download = ( ) => {
5696 event ( 'CSV Download Initiated' )
57- basic ( text ) . promise . then ( response => {
97+ basic ( text , {
98+ vars : rangeToParam ( timeRange ) ,
99+ } ) . promise . then ( response => {
58100 if ( response . type !== 'SUCCESS' ) {
59101 return
60102 }
@@ -64,36 +106,9 @@ const ResultsPane: FC = () => {
64106 }
65107
66108 const submit = ( ) => {
67- let timeRangeStart , timeRangeStop
68-
69- if ( ! timeRange ) {
70- timeRangeStart = timeRangeStop = null
71- } else {
72- if ( timeRange . type === 'selectable-duration' ) {
73- timeRangeStart = '-' + timeRange . duration
74- } else if ( timeRange . type === 'duration' ) {
75- timeRangeStart = '-' + timeRange . lower
76- } else if ( isNaN ( Date . parse ( timeRange . lower ) ) ) {
77- timeRangeStart = null
78- } else {
79- timeRangeStart = new Date ( timeRange . lower ) . toISOString ( )
80- }
81-
82- if ( ! timeRange . upper ) {
83- timeRangeStop = 'now()'
84- } else if ( isNaN ( Date . parse ( timeRange . upper ) ) ) {
85- timeRangeStop = null
86- } else {
87- timeRangeStop = new Date ( timeRange . upper ) . toISOString ( )
88- }
89- }
90-
91109 setStatus ( RemoteDataState . Loading )
92110 query ( text , {
93- vars : {
94- timeRangeStart,
95- timeRangeStop,
96- } ,
111+ vars : rangeToParam ( timeRange ) ,
97112 } )
98113 . then ( r => {
99114 event ( 'resultReceived' , {
0 commit comments