@@ -14,6 +14,7 @@ import DataSourceLister from './DataSourceLister';
14
14
import { allSvgs } from '@tooljet/plugins/client' ;
15
15
// import { Confirm } from '../Viewer/Confirm';
16
16
import _ , { isEmpty , isEqual } from 'lodash' ;
17
+ import { Button , ButtonGroup , Dropdown } from 'react-bootstrap' ;
17
18
18
19
const queryNameRegex = new RegExp ( '^[A-Za-z0-9_-]*$' ) ;
19
20
@@ -39,9 +40,11 @@ let QueryManager = class QueryManager extends React.Component {
39
40
showSaveConfirmation : false ,
40
41
restArrayValuesChanged : false ,
41
42
nextProps : null ,
43
+ buttonText : '' ,
42
44
} ;
43
45
44
46
this . previewPanelRef = React . createRef ( ) ;
47
+ this . buttonConfig = JSON . parse ( localStorage . getItem ( 'queryManagerButtonConfig' ) ) ;
45
48
}
46
49
47
50
setStateFromProps = ( props ) => {
@@ -90,6 +93,14 @@ let QueryManager = class QueryManager extends React.Component {
90
93
base0E : '#d381c3' ,
91
94
base0F : '#be643c' ,
92
95
} ,
96
+ buttonText :
97
+ props . mode === 'edit'
98
+ ? this . buttonConfig ?. editMode ?. text ?? 'Save & Run'
99
+ : this . buttonConfig ?. createMode ?. text ?? 'Create & Run' ,
100
+ shouldRunQuery :
101
+ props . mode === 'edit'
102
+ ? this . buttonConfig ?. editMode ?. shouldRunQuery ?? true
103
+ : this . buttonConfig ?. createMode ?. shouldRunQuery ?? true ,
93
104
} ,
94
105
( ) => {
95
106
if ( this . props . mode === 'edit' ) {
@@ -154,7 +165,7 @@ let QueryManager = class QueryManager extends React.Component {
154
165
const prevLoading = this . state . currentState ?. queries [ query . name ]
155
166
? this . state . currentState ?. queries [ query . name ] ?. isLoading
156
167
: false ;
157
- if ( ! isEqual ( this . state . selectedQuery , nextProps . selectedQuery ) ) {
168
+ if ( ! isEmpty ( nextProps . selectedQuery ) && ! isEqual ( this . state . selectedQuery , nextProps . selectedQuery ) ) {
158
169
if ( query && ! isLoading && ! prevLoading ) {
159
170
this . props . runQuery ( query . id , query . name ) ;
160
171
}
@@ -247,7 +258,7 @@ let QueryManager = class QueryManager extends React.Component {
247
258
} ;
248
259
249
260
createOrUpdateDataQuery = ( ) => {
250
- const { appId, options, selectedDataSource, mode, queryName } = this . state ;
261
+ const { appId, options, selectedDataSource, mode, queryName, shouldRunQuery } = this . state ;
251
262
const appVersionId = this . props . editingVersionId ;
252
263
const kind = selectedDataSource . kind ;
253
264
const dataSourceId = selectedDataSource . id === 'null' ? null : selectedDataSource . id ;
@@ -264,10 +275,10 @@ let QueryManager = class QueryManager extends React.Component {
264
275
. update ( this . state . selectedQuery . id , queryName , options )
265
276
. then ( ( data ) => {
266
277
this . setState ( {
267
- isUpdating : selectedDataSource ?. kind !== 'runjs' ? true : false ,
278
+ isUpdating : shouldRunQuery ? true : false ,
268
279
isFieldsChanged : false ,
269
280
restArrayValuesChanged : false ,
270
- updatedQuery : selectedDataSource ?. kind !== 'runjs' ? { ...data , updateQuery : true } : { } ,
281
+ updatedQuery : shouldRunQuery ? { ...data , updateQuery : true } : { } ,
271
282
} ) ;
272
283
this . props . dataQueriesChanged ( ) ;
273
284
this . props . setStateOfUnsavedQueries ( false ) ;
@@ -284,10 +295,10 @@ let QueryManager = class QueryManager extends React.Component {
284
295
. then ( ( data ) => {
285
296
toast . success ( 'Query Added' ) ;
286
297
this . setState ( {
287
- isCreating : selectedDataSource ?. kind !== 'runjs' ? true : false ,
298
+ isCreating : shouldRunQuery ? true : false ,
288
299
isFieldsChanged : false ,
289
300
restArrayValuesChanged : false ,
290
- updatedQuery : selectedDataSource ?. kind !== 'runjs' ? { ...data , updateQuery : false } : { } ,
301
+ updatedQuery : shouldRunQuery ? { ...data , updateQuery : false } : { } ,
291
302
} ) ;
292
303
this . props . dataQueriesChanged ( ) ;
293
304
this . props . setStateOfUnsavedQueries ( false ) ;
@@ -358,6 +369,17 @@ let QueryManager = class QueryManager extends React.Component {
358
369
this . optionchanged ( 'events' , events ) ;
359
370
} ;
360
371
372
+ updateButtonText = ( text , shouldRunQuery ) => {
373
+ if ( this . state . mode === 'edit' ) {
374
+ this . buttonConfig = { ...this . buttonConfig , editMode : { text : text , shouldRunQuery : shouldRunQuery } } ;
375
+ localStorage . setItem ( 'queryManagerButtonConfig' , JSON . stringify ( this . buttonConfig ) ) ;
376
+ } else {
377
+ this . buttonConfig = { ...this . buttonConfig , createMode : { text : text , shouldRunQuery : shouldRunQuery } } ;
378
+ localStorage . setItem ( 'queryManagerButtonConfig' , JSON . stringify ( this . buttonConfig ) ) ;
379
+ }
380
+ this . setState ( { buttonText : text , shouldRunQuery : shouldRunQuery } ) ;
381
+ } ;
382
+
361
383
render ( ) {
362
384
const {
363
385
dataSources,
@@ -384,8 +406,7 @@ let QueryManager = class QueryManager extends React.Component {
384
406
ElementToRender = allSources [ sourcecomponentName ] ;
385
407
}
386
408
387
- let buttonText = mode === 'edit' ? 'Save' : 'Create' ;
388
- buttonText = selectedDataSource ?. kind !== 'runjs' ? buttonText + ' & Run' : buttonText ;
409
+ let dropDownButtonText = mode === 'edit' ? 'Save' : 'Create' ;
389
410
const buttonDisabled = isUpdating || isCreating ;
390
411
const mockDataQueryComponent = this . mockDataQueryAsComponent ( ) ;
391
412
const Icon = allSvgs [ this ?. state ?. selectedDataSource ?. kind ] ;
@@ -468,16 +489,39 @@ let QueryManager = class QueryManager extends React.Component {
468
489
</ button >
469
490
) }
470
491
{ selectedDataSource && ( addingQuery || editingQuery ) && (
471
- < button
472
- onClick = { this . createOrUpdateDataQuery }
473
- disabled = { buttonDisabled }
474
- className = { `btn btn-primary m-1 float-right ${ isUpdating || isCreating ? 'btn-loading' : '' } ${
475
- this . state . selectedDataSource ? '' : 'disabled'
476
- } `}
477
- style = { { width : '102px' , height : '28px' } }
478
- >
479
- { buttonText }
480
- </ button >
492
+ < Dropdown as = { ButtonGroup } className = { 'm-1 float-right' } style = { { display : 'initial' , height : '28px' } } >
493
+ < Button
494
+ className = { `btn btn-primary ${ isUpdating || isCreating ? 'btn-loading' : '' } ${
495
+ this . state . selectedDataSource ? '' : 'disabled'
496
+ } `}
497
+ style = { { width : '100px' , height : '28px' } }
498
+ onClick = { this . createOrUpdateDataQuery }
499
+ disabled = { buttonDisabled }
500
+ >
501
+ { this . state . buttonText }
502
+ </ Button >
503
+ < Dropdown . Toggle
504
+ split
505
+ className = "btn btn-primary d-none d-lg-inline"
506
+ style = { { height : '28px' , paddingTop : '5px' } }
507
+ />
508
+ < Dropdown . Menu className = "import-lg-position" >
509
+ < Dropdown . Item
510
+ onClick = { ( ) => {
511
+ this . updateButtonText ( dropDownButtonText , false ) ;
512
+ } }
513
+ >
514
+ { dropDownButtonText }
515
+ </ Dropdown . Item >
516
+ < Dropdown . Item
517
+ onClick = { ( ) => {
518
+ this . updateButtonText ( `${ dropDownButtonText } & Run` , true ) ;
519
+ } }
520
+ >
521
+ { `${ dropDownButtonText } & Run` }
522
+ </ Dropdown . Item >
523
+ </ Dropdown . Menu >
524
+ </ Dropdown >
481
525
) }
482
526
< span onClick = { this . props . toggleQueryEditor } className = "cursor-pointer m-3" data-tip = "Hide query editor" >
483
527
< svg width = "18" height = "10" viewBox = "0 0 18 10" fill = "none" xmlns = "http://www.w3.org/2000/svg" >
0 commit comments