Skip to content

Commit fc0648c

Browse files
authored
fix: csv not respecting time range (#4879)
1 parent 7240c94 commit fc0648c

File tree

1 file changed

+50
-35
lines changed

1 file changed

+50
-35
lines changed

src/dataExplorer/components/ResultsPane.tsx

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Libraries
12
import React, {FC, lazy, Suspense, useState, useContext} from 'react'
23
import {
34
DraggableResizer,
@@ -15,20 +16,28 @@ import {
1516
} from '@influxdata/clockface'
1617
import {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
1824
import TimeRangeDropdown from 'src/shared/components/TimeRangeDropdown'
1925
import Results from 'src/dataExplorer/components/Results'
20-
import {ResultsContext} from 'src/dataExplorer/components/ResultsContext'
21-
import {TimeRange} from 'src/types'
2226
import {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'
2334
import {downloadTextFile} from 'src/shared/utils/download'
2435
import {event} from 'src/cloud/utils/reporting'
25-
import {QueryContext} from 'src/shared/contexts/query'
2636
import {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'
2937
import {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'
3241
import {DEFAULT_TIME_RANGE} from 'src/shared/constants/timeRanges'
3342

3443
const FluxMonacoEditor = lazy(() =>
@@ -42,6 +51,37 @@ const useLocalStorageState = createLocalStorageStateHook(
4251
const INITIAL_HORIZ_RESIZER_HANDLE = 0.2
4352
const 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+
4585
const 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

Comments
 (0)