|
| 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' |
| 24 | + |
| 25 | +import {DEFAULT_TIME_RANGE} from 'src/shared/constants/timeRanges' |
| 26 | +import './NewDataExplorer.scss' |
| 27 | + |
| 28 | +const FluxMonacoEditor = lazy(() => |
| 29 | + import('src/shared/components/FluxMonacoEditor') |
| 30 | +) |
| 31 | + |
| 32 | +const INITIAL_VERT_RESIZER_HANDLE = 0.2 |
| 33 | +const INITIAL_HORIZ_RESIZER_HANDLE = 0.2 |
| 34 | +const fakeNotify = notify |
| 35 | + |
| 36 | +const NewDataExplorer: FC = () => { |
| 37 | + const [vertDragPosition, setVertDragPosition] = useState([ |
| 38 | + INITIAL_VERT_RESIZER_HANDLE, |
| 39 | + ]) |
| 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 | + |
| 61 | + 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> |
| 137 | + ) |
| 138 | +} |
| 139 | + |
| 140 | +export default NewDataExplorer |
0 commit comments