@@ -28,14 +28,19 @@ import {
2828// Contexts
2929import { ResultsContext } from 'src/dataExplorer/components/ResultsContext'
3030import { QueryContext } from 'src/shared/contexts/query'
31- import { PersistanceContext } from 'src/dataExplorer/context/persistance'
31+ import {
32+ PersistanceContext ,
33+ DEFAULT_FLUX_EDITOR_TEXT ,
34+ DEFAULT_SQL_EDITOR_TEXT ,
35+ } from 'src/dataExplorer/context/persistance'
3236
3337// Components
3438import TimeRangeDropdown from 'src/shared/components/TimeRangeDropdown'
3539import Results from 'src/dataExplorer/components/Results'
3640import { SubmitQueryButton } from 'src/timeMachine/components/SubmitQueryButton'
3741import QueryTime from 'src/dataExplorer/components/QueryTime'
3842import NewDatePicker from 'src/shared/components/dateRangePicker/NewDatePicker'
43+ import { SqlEditorMonaco } from 'src/shared/components/SqlMonacoEditor'
3944
4045// Types
4146import { TimeRange } from 'src/types'
@@ -52,7 +57,6 @@ import {getWindowPeriodVariableFromVariables} from 'src/variables/utils/getWindo
5257// Constants
5358import { TIME_RANGE_START , TIME_RANGE_STOP } from 'src/variables/constants'
5459import { isFlagEnabled } from 'src/shared/utils/featureFlag'
55- import { SqlEditorMonaco } from 'src/shared/components/SqlMonacoEditor'
5660
5761const FluxMonacoEditor = lazy (
5862 ( ) => import ( 'src/shared/components/FluxMonacoEditor' )
@@ -100,6 +104,10 @@ const rangeToParam = (timeRange: TimeRange) => {
100104 }
101105}
102106
107+ const isDefaultText = text => {
108+ return text == DEFAULT_FLUX_EDITOR_TEXT || text == DEFAULT_SQL_EDITOR_TEXT
109+ }
110+
103111const ResultsPane : FC = ( ) => {
104112 const { basic, query, cancel} = useContext ( QueryContext )
105113 const { status, result, setStatus, setResult} = useContext ( ResultsContext )
@@ -114,12 +122,25 @@ const ResultsPane: FC = () => {
114122 resource,
115123 } = useContext ( PersistanceContext )
116124 const [ csvDownloadCancelID , setCancelId ] = useState ( null )
125+ const language = resource ?. language ?? LanguageType . FLUX
117126
118- const submitButtonDisabled = ! text && ! selection . measurement
119-
120- const disabledTitleText = submitButtonDisabled
121- ? 'Select measurement before running script'
122- : ''
127+ let submitButtonDisabled = false
128+ let disabledTitleText = ''
129+ if ( ! text || isDefaultText ( text ) ) {
130+ submitButtonDisabled = true
131+ disabledTitleText = 'Write a query before running script'
132+ } else if ( language == LanguageType . SQL && ! selection . bucket ) {
133+ submitButtonDisabled = true
134+ disabledTitleText = 'Select a bucket before running script'
135+ } else if (
136+ language == LanguageType . FLUX &&
137+ selection . composition . synced && // using composition
138+ selection . bucket &&
139+ ! selection . measurement
140+ ) {
141+ submitButtonDisabled = true
142+ disabledTitleText = 'Select a measurement before running script'
143+ }
123144
124145 const download = async ( ) => {
125146 event ( 'CSV Download Initiated' )
@@ -128,7 +149,11 @@ const ResultsPane: FC = () => {
128149 {
129150 vars : rangeToParam ( range ) ,
130151 } ,
131- { rawBlob : true }
152+ {
153+ rawBlob : true ,
154+ language,
155+ bucket : selection . bucket ,
156+ }
132157 )
133158 setCancelId ( promise . id )
134159
@@ -144,9 +169,16 @@ const ResultsPane: FC = () => {
144169
145170 const submit = useCallback ( ( ) => {
146171 setStatus ( RemoteDataState . Loading )
147- query ( text , {
148- vars : rangeToParam ( range ) ,
149- } )
172+ query (
173+ text ,
174+ {
175+ vars : rangeToParam ( range ) ,
176+ } ,
177+ {
178+ language,
179+ bucket : selection . bucket ,
180+ }
181+ )
150182 . then ( r => {
151183 event ( 'resultReceived' , {
152184 status : r . parsed . table . length === 0 ? 'empty' : 'good' ,
@@ -165,7 +197,7 @@ const ResultsPane: FC = () => {
165197 event ( 'resultReceived' , { status : 'error' } )
166198 setStatus ( RemoteDataState . Error )
167199 } )
168- } , [ text , range ] )
200+ } , [ text , range , resource ?. language , selection . bucket ] )
169201
170202 const timeVars = [
171203 getRangeVariable ( TIME_RANGE_START , range ) ,
@@ -176,6 +208,16 @@ const ResultsPane: FC = () => {
176208 getWindowPeriodVariableFromVariables ( text , timeVars ) || [ ]
177209 )
178210
211+ const TimeRangePicker = ( ) =>
212+ isFlagEnabled ( 'newTimeRangeComponent' ) ? (
213+ < NewDatePicker />
214+ ) : (
215+ < TimeRangeDropdown
216+ timeRange = { range }
217+ onSetTimeRange = { ( range : TimeRange ) => setRange ( range ) }
218+ />
219+ )
220+
179221 return (
180222 < DraggableResizer
181223 handleOrientation = { Orientation . Horizontal }
@@ -237,7 +279,9 @@ const ResultsPane: FC = () => {
237279 icon = { IconFont . Download_New }
238280 onClick = { download }
239281 status = {
240- text ? ComponentStatus . Default : ComponentStatus . Disabled
282+ ! submitButtonDisabled
283+ ? ComponentStatus . Default
284+ : ComponentStatus . Disabled
241285 }
242286 testID = "data-explorer--csv-download"
243287 />
@@ -251,13 +295,9 @@ const ResultsPane: FC = () => {
251295 color = { ComponentColor . Danger }
252296 />
253297 ) }
254- { isFlagEnabled ( 'newTimeRangeComponent' ) ? (
255- < NewDatePicker />
256- ) : (
257- < TimeRangeDropdown
258- timeRange = { range }
259- onSetTimeRange = { ( range : TimeRange ) => setRange ( range ) }
260- />
298+ { isFlagEnabled ( 'uiSqlSupport' ) &&
299+ resource ?. language === LanguageType . SQL ? null : (
300+ < TimeRangePicker />
261301 ) }
262302 < SubmitQueryButton
263303 className = "submit-btn"
0 commit comments