|
1 | | -import React, {FC, lazy, Suspense, useState, useContext} from 'react' |
2 | | -import { |
3 | | - DraggableResizer, |
4 | | - Orientation, |
5 | | - RemoteDataState, |
6 | | - SpinnerContainer, |
7 | | - TechnoSpinner, |
8 | | - Button, |
9 | | - IconFont, |
10 | | - ComponentStatus, |
11 | | - ComponentSize, |
12 | | - FlexBox, |
13 | | - FlexDirection, |
14 | | - JustifyContent, |
15 | | -} from '@influxdata/clockface' |
16 | | -import TimeRangeDropdown from 'src/shared/components/TimeRangeDropdown' |
17 | | -import Results from 'src/dataExplorer/components/Results' |
18 | | -import {TimeRange} from 'src/types' |
19 | | -import {SubmitQueryButton} from 'src/timeMachine/components/SubmitQueryButton' |
20 | | -import {downloadTextFile} from 'src/shared/utils/download' |
21 | | -import {event} from 'src/cloud/utils/reporting' |
22 | | -import {QueryContext} from 'src/shared/contexts/query' |
23 | | -import {notify} from 'src/shared/actions/notifications' |
| 1 | +import React, {FC, useState} from 'react' |
| 2 | +import {DraggableResizer, Orientation} from '@influxdata/clockface' |
| 3 | +import {QueryProvider} from 'src/shared/contexts/query' |
| 4 | +import {ResultsProvider} from 'src/dataExplorer/components/ResultsContext' |
| 5 | +import ResultsPane from 'src/dataExplorer/components/ResultsPane' |
24 | 6 |
|
25 | | -import {DEFAULT_TIME_RANGE} from 'src/shared/constants/timeRanges' |
26 | 7 | import './NewDataExplorer.scss' |
27 | 8 |
|
28 | | -const FluxMonacoEditor = lazy(() => |
29 | | - import('src/shared/components/FluxMonacoEditor') |
30 | | -) |
31 | | - |
32 | 9 | const INITIAL_VERT_RESIZER_HANDLE = 0.2 |
33 | | -const INITIAL_HORIZ_RESIZER_HANDLE = 0.2 |
34 | | -const fakeNotify = notify |
35 | 10 |
|
36 | 11 | const NewDataExplorer: FC = () => { |
37 | 12 | const [vertDragPosition, setVertDragPosition] = useState([ |
38 | 13 | INITIAL_VERT_RESIZER_HANDLE, |
39 | 14 | ]) |
40 | | - const [horizDragPosition, setHorizDragPosition] = useState([ |
41 | | - INITIAL_HORIZ_RESIZER_HANDLE, |
42 | | - ]) |
43 | | - const {basic} = useContext(QueryContext) |
44 | | - |
45 | | - const [text, setText] = useState('') |
46 | | - const [timeRange, setTimeRange] = useState<TimeRange>(DEFAULT_TIME_RANGE) |
47 | | - |
48 | | - const download = () => { |
49 | | - event('CSV Download Initiated') |
50 | | - basic(text).promise.then(response => { |
51 | | - if (response.type !== 'SUCCESS') { |
52 | | - return |
53 | | - } |
54 | | - |
55 | | - downloadTextFile(response.csv, 'influx.data', '.csv', 'text/csv') |
56 | | - }) |
57 | | - } |
58 | | - |
59 | | - const submit = () => {} |
60 | 15 |
|
61 | 16 | return ( |
62 | | - <DraggableResizer |
63 | | - handleOrientation={Orientation.Vertical} |
64 | | - handlePositions={vertDragPosition} |
65 | | - onChangePositions={setVertDragPosition} |
66 | | - > |
67 | | - <DraggableResizer.Panel> |
68 | | - <h1>[ schema ]</h1> |
69 | | - </DraggableResizer.Panel> |
70 | | - <DraggableResizer.Panel className="new-data-explorer-rightside"> |
71 | | - <DraggableResizer |
72 | | - handleOrientation={Orientation.Horizontal} |
73 | | - handlePositions={horizDragPosition} |
74 | | - onChangePositions={setHorizDragPosition} |
75 | | - > |
76 | | - <DraggableResizer.Panel> |
77 | | - <FlexBox |
78 | | - direction={FlexDirection.Column} |
79 | | - justifyContent={JustifyContent.FlexEnd} |
80 | | - margin={ComponentSize.Small} |
81 | | - style={{height: '100%'}} |
82 | | - > |
83 | | - <div |
84 | | - style={{height: '100%', width: '100%', position: 'relative'}} |
85 | | - > |
86 | | - <Suspense |
87 | | - fallback={ |
88 | | - <SpinnerContainer |
89 | | - loading={RemoteDataState.Loading} |
90 | | - spinnerComponent={<TechnoSpinner />} |
91 | | - /> |
92 | | - } |
93 | | - > |
94 | | - <FluxMonacoEditor script={text} onChangeScript={setText} /> |
95 | | - </Suspense> |
96 | | - </div> |
97 | | - <div style={{width: '100%'}}> |
98 | | - <FlexBox |
99 | | - direction={FlexDirection.Row} |
100 | | - justifyContent={JustifyContent.FlexEnd} |
101 | | - margin={ComponentSize.Small} |
102 | | - > |
103 | | - <Button |
104 | | - titleText="Download query results as a .CSV file" |
105 | | - text="CSV" |
106 | | - icon={IconFont.Download_New} |
107 | | - onClick={download} |
108 | | - status={ |
109 | | - text ? ComponentStatus.Default : ComponentStatus.Disabled |
110 | | - } |
111 | | - /> |
112 | | - <TimeRangeDropdown |
113 | | - timeRange={timeRange} |
114 | | - onSetTimeRange={(range: TimeRange) => setTimeRange(range)} |
115 | | - /> |
116 | | - <SubmitQueryButton |
117 | | - className="submit-btn" |
118 | | - text="Run" |
119 | | - icon={IconFont.Play} |
120 | | - submitButtonDisabled={!text} |
121 | | - queryStatus={RemoteDataState.NotStarted} |
122 | | - onSubmit={submit} |
123 | | - onNotify={fakeNotify} |
124 | | - queryID="" |
125 | | - cancelAllRunningQueries={() => {}} |
126 | | - /> |
127 | | - </FlexBox> |
128 | | - </div> |
129 | | - </FlexBox> |
130 | | - </DraggableResizer.Panel> |
131 | | - <DraggableResizer.Panel> |
132 | | - <Results /> |
133 | | - </DraggableResizer.Panel> |
134 | | - </DraggableResizer> |
135 | | - </DraggableResizer.Panel> |
136 | | - </DraggableResizer> |
| 17 | + <QueryProvider> |
| 18 | + <DraggableResizer |
| 19 | + handleOrientation={Orientation.Vertical} |
| 20 | + handlePositions={vertDragPosition} |
| 21 | + onChangePositions={setVertDragPosition} |
| 22 | + > |
| 23 | + <DraggableResizer.Panel> |
| 24 | + <h1>[ schema ]</h1> |
| 25 | + </DraggableResizer.Panel> |
| 26 | + <DraggableResizer.Panel className="new-data-explorer-rightside"> |
| 27 | + <ResultsProvider> |
| 28 | + <ResultsPane /> |
| 29 | + </ResultsProvider> |
| 30 | + </DraggableResizer.Panel> |
| 31 | + </DraggableResizer> |
| 32 | + </QueryProvider> |
137 | 33 | ) |
138 | 34 | } |
139 | 35 |
|
|
0 commit comments