@@ -20,6 +20,7 @@ import {
2020// Contexts
2121import { ResultsContext } from 'src/dataExplorer/components/ResultsContext'
2222import { QueryContext } from 'src/shared/contexts/query'
23+ import { PersistanceContext } from 'src/dataExplorer/context/persistance'
2324
2425// Components
2526import TimeRangeDropdown from 'src/shared/components/TimeRangeDropdown'
@@ -39,8 +40,6 @@ import {getWindowPeriodVariableFromVariables} from 'src/variables/utils/getWindo
3940
4041// Constants
4142import { TIME_RANGE_START , TIME_RANGE_STOP } from 'src/variables/constants'
42- import { DEFAULT_TIME_RANGE } from 'src/shared/constants/timeRanges'
43- import { useSessionStorage } from '../shared/utils'
4443
4544const FluxMonacoEditor = lazy ( ( ) =>
4645 import ( 'src/shared/components/FluxMonacoEditor' )
@@ -49,7 +48,7 @@ const FluxMonacoEditor = lazy(() =>
4948const fakeNotify = notify
5049
5150const rangeToParam = ( timeRange : TimeRange ) => {
52- let timeRangeStart , timeRangeStop
51+ let timeRangeStart : string , timeRangeStop : string
5352
5453 if ( ! timeRange ) {
5554 timeRangeStart = timeRangeStop = null
@@ -82,21 +81,19 @@ const rangeToParam = (timeRange: TimeRange) => {
8281const ResultsPane : FC = ( ) => {
8382 const { basic, query, cancel} = useContext ( QueryContext )
8483 const { status, result, setStatus, setResult} = useContext ( ResultsContext )
85-
86- const [
87- horizDragPosition ,
88- setHorizDragPosition ,
89- ] = useSessionStorage ( 'dataExplorer.resize.horizontal' , [ 0.2 ] )
90- const [ text , setText ] = useSessionStorage ( 'dataExplorer.query' , '' )
91- const [ timeRange , setTimeRange ] = useSessionStorage (
92- 'dataExplorer.range' ,
93- DEFAULT_TIME_RANGE
94- )
84+ const {
85+ horizontal,
86+ setHorizontal,
87+ query : text ,
88+ setQuery,
89+ range,
90+ setRange,
91+ } = useContext ( PersistanceContext )
9592
9693 const download = ( ) => {
9794 event ( 'CSV Download Initiated' )
9895 basic ( text , {
99- vars : rangeToParam ( timeRange ) ,
96+ vars : rangeToParam ( range ) ,
10097 } ) . promise . then ( response => {
10198 if ( response . type !== 'SUCCESS' ) {
10299 return
@@ -109,7 +106,7 @@ const ResultsPane: FC = () => {
109106 const submit = ( ) => {
110107 setStatus ( RemoteDataState . Loading )
111108 query ( text , {
112- vars : rangeToParam ( timeRange ) ,
109+ vars : rangeToParam ( range ) ,
113110 } )
114111 . then ( r => {
115112 event ( 'resultReceived' , {
@@ -130,8 +127,8 @@ const ResultsPane: FC = () => {
130127 }
131128
132129 const timeVars = [
133- getRangeVariable ( TIME_RANGE_START , timeRange ) ,
134- getRangeVariable ( TIME_RANGE_STOP , timeRange ) ,
130+ getRangeVariable ( TIME_RANGE_START , range ) ,
131+ getRangeVariable ( TIME_RANGE_STOP , range ) ,
135132 ]
136133
137134 const variables = timeVars . concat (
@@ -141,8 +138,8 @@ const ResultsPane: FC = () => {
141138 return (
142139 < DraggableResizer
143140 handleOrientation = { Orientation . Horizontal }
144- handlePositions = { horizDragPosition }
145- onChangePositions = { setHorizDragPosition }
141+ handlePositions = { horizontal }
142+ onChangePositions = { setHorizontal }
146143 >
147144 < DraggableResizer . Panel >
148145 < FlexBox
@@ -164,7 +161,7 @@ const ResultsPane: FC = () => {
164161 < FluxMonacoEditor
165162 variables = { variables }
166163 script = { text }
167- onChangeScript = { setText }
164+ onChangeScript = { setQuery }
168165 />
169166 </ Suspense >
170167 </ div >
@@ -193,8 +190,8 @@ const ResultsPane: FC = () => {
193190 }
194191 />
195192 < TimeRangeDropdown
196- timeRange = { timeRange }
197- onSetTimeRange = { ( range : TimeRange ) => setTimeRange ( range ) }
193+ timeRange = { range }
194+ onSetTimeRange = { ( range : TimeRange ) => setRange ( range ) }
198195 />
199196 < SubmitQueryButton
200197 className = "submit-btn"
0 commit comments