Skip to content

Commit d4155d8

Browse files
authored
feat: persist more things (#4926)
1 parent 292b22e commit d4155d8

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/dataExplorer/components/FluxQueryBuilder.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, {FC, useState} from 'react'
1+
import React, {FC} from 'react'
2+
import {createLocalStorageStateHook} from 'use-local-storage-state'
23

34
// Components
45
import {DraggableResizer, Orientation} from '@influxdata/clockface'
@@ -13,14 +14,12 @@ import Schema from 'src/dataExplorer/components/Schema'
1314
// Styles
1415
import './FluxQueryBuilder.scss'
1516

16-
const INITIAL_LEFT_VERT_RESIZER_HANDLE = 0.25
17-
const INITIAL_RIGHT_VERT_RESIZER_HANDLE = 0.8
18-
17+
const useResizeState = createLocalStorageStateHook(
18+
'dataExplorer.resize.vertical',
19+
[0.25, 0.8]
20+
)
1921
const FluxQueryBuilder: FC = () => {
20-
const [vertDragPosition, setVertDragPosition] = useState([
21-
INITIAL_LEFT_VERT_RESIZER_HANDLE,
22-
INITIAL_RIGHT_VERT_RESIZER_HANDLE,
23-
])
22+
const [vertDragPosition, setVertDragPosition] = useResizeState()
2423

2524
return (
2625
<QueryProvider>

src/dataExplorer/components/ResultsPane.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC, lazy, Suspense, useState, useContext} from 'react'
2+
import React, {FC, lazy, Suspense, useContext} from 'react'
33
import {
44
DraggableResizer,
55
Orientation,
@@ -43,12 +43,19 @@ import {DEFAULT_TIME_RANGE} from 'src/shared/constants/timeRanges'
4343
const FluxMonacoEditor = lazy(() =>
4444
import('src/shared/components/FluxMonacoEditor')
4545
)
46-
const useLocalStorageState = createLocalStorageStateHook(
46+
const useQueryState = createLocalStorageStateHook<string>(
4747
'dataExplorer.query',
4848
''
4949
)
50+
const useRangeState = createLocalStorageStateHook<TimeRange>(
51+
'dataExplorer.range',
52+
DEFAULT_TIME_RANGE
53+
)
54+
const useResizeState = createLocalStorageStateHook(
55+
'dataExplorer.resize.horizontal',
56+
[0.2]
57+
)
5058

51-
const INITIAL_HORIZ_RESIZER_HANDLE = 0.2
5259
const fakeNotify = notify
5360

5461
const rangeToParam = (timeRange: TimeRange) => {
@@ -83,14 +90,12 @@ const rangeToParam = (timeRange: TimeRange) => {
8390
}
8491

8592
const ResultsPane: FC = () => {
86-
const [horizDragPosition, setHorizDragPosition] = useState([
87-
INITIAL_HORIZ_RESIZER_HANDLE,
88-
])
8993
const {basic, query} = useContext(QueryContext)
9094
const {status, setStatus, setResult} = useContext(ResultsContext)
9195

92-
const [text, setText] = useLocalStorageState()
93-
const [timeRange, setTimeRange] = useState<TimeRange>(DEFAULT_TIME_RANGE)
96+
const [horizDragPosition, setHorizDragPosition] = useResizeState()
97+
const [text, setText] = useQueryState()
98+
const [timeRange, setTimeRange] = useRangeState()
9499

95100
const download = () => {
96101
event('CSV Download Initiated')

0 commit comments

Comments
 (0)