@@ -4,41 +4,36 @@ import {connect} from 'react-redux';
4
4
import cn from 'bem-cn-lite' ;
5
5
import _ from 'lodash' ;
6
6
import MonacoEditor from 'react-monaco-editor' ;
7
- import { Button , DropdownMenu } from '@gravity-ui/uikit' ;
8
7
9
8
import SplitPane from '../../../components/SplitPane' ;
10
9
import { QueryResultTable } from '../../../components/QueryResultTable' ;
11
10
12
- import SaveQuery from './SaveQuery/SaveQuery' ;
13
11
import SavedQueries from './SavedQueries/SavedQueries' ;
14
- import { Icon } from '../../../components/Icon' ;
15
12
import QueryResult from './QueryResult/QueryResult' ;
16
13
import QueryExplain from './QueryExplain/QueryExplain' ;
14
+ import { QueryEditorControls } from './QueryEditorControls/QueryEditorControls' ;
15
+ import { OldQueryEditorControls } from './QueryEditorControls/OldQueryEditorControls' ;
17
16
18
17
import {
19
- sendQuery ,
18
+ sendExecuteQuery ,
20
19
changeUserInput ,
21
20
saveQueryToHistory ,
22
21
goToPreviousQuery ,
23
22
goToNextQuery ,
24
- selectRunAction ,
25
- RUN_ACTIONS_VALUES ,
26
23
MONACO_HOT_KEY_ACTIONS ,
27
24
setMonacoHotKey ,
28
25
} from '../../../store/reducers/executeQuery' ;
29
26
import { getExplainQuery , getExplainQueryAst } from '../../../store/reducers/explainQuery' ;
30
- import { getSettingValue , setSettingValue } from '../../../store/reducers/settings' ;
27
+ import { getParsedSettingValue , setSettingValue } from '../../../store/reducers/settings' ;
31
28
import {
32
29
DEFAULT_IS_QUERY_RESULT_COLLAPSED ,
33
30
DEFAULT_SIZE_RESULT_PANE_KEY ,
34
31
SAVED_QUERIES_KEY ,
35
- QUERY_INITIAL_RUN_ACTION_KEY ,
32
+ QUERY_INITIAL_MODE_KEY ,
33
+ ENABLE_QUERY_MODES_FOR_EXPLAIN ,
36
34
} from '../../../utils/constants' ;
37
35
38
- import { parseJson } from '../../../utils/utils' ;
39
-
40
36
import './QueryEditor.scss' ;
41
- import Divider from '../../../components/Divider/Divider' ;
42
37
import QueriesHistory from './QueriesHistory/QueriesHistory' ;
43
38
import {
44
39
PaneVisibilityActionTypes ,
@@ -47,11 +42,6 @@ import {
47
42
import Preview from '../Preview/Preview' ;
48
43
import { setShowPreview } from '../../../store/reducers/schema' ;
49
44
50
- export const RUN_ACTIONS = [
51
- { value : RUN_ACTIONS_VALUES . script , content : 'Run Script' } ,
52
- { value : RUN_ACTIONS_VALUES . scan , content : 'Run Scan' } ,
53
- ] ;
54
-
55
45
const TABLE_SETTINGS = {
56
46
sortable : false ,
57
47
} ;
@@ -73,14 +63,15 @@ const RESULT_TYPES = {
73
63
const b = cn ( 'query-editor' ) ;
74
64
75
65
const propTypes = {
76
- sendQuery : PropTypes . func ,
66
+ sendExecuteQuery : PropTypes . func ,
77
67
path : PropTypes . string ,
78
68
response : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . array ] ) ,
79
69
executeQuery : PropTypes . object ,
80
70
explainQuery : PropTypes . object ,
81
71
setMonacoHotKey : PropTypes . func ,
82
72
theme : PropTypes . string ,
83
73
type : PropTypes . string ,
74
+ initialQueryMode : PropTypes . string ,
84
75
} ;
85
76
86
77
const initialTenantCommonInfoState = {
@@ -92,6 +83,7 @@ function QueryEditor(props) {
92
83
const [ resultType , setResultType ] = useState ( RESULT_TYPES . EXECUTE ) ;
93
84
94
85
const [ isResultLoaded , setIsResultLoaded ] = useState ( false ) ;
86
+ const [ queryMode , setQueryMode ] = useState ( props . initialQueryMode ) ;
95
87
96
88
const [ resultVisibilityState , dispatchResultVisibilityState ] = useReducer (
97
89
paneVisibilityToggleReducerCreator ( DEFAULT_IS_QUERY_RESULT_COLLAPSED ) ,
@@ -155,7 +147,7 @@ function QueryEditor(props) {
155
147
setMonacoHotKey ( null ) ;
156
148
switch ( monacoHotKey ) {
157
149
case MONACO_HOT_KEY_ACTIONS . sendQuery : {
158
- return handleSendClick ( ) ;
150
+ return handleSendExecuteClick ( queryMode ) ;
159
151
}
160
152
case MONACO_HOT_KEY_ACTIONS . goPrev : {
161
153
return handlePreviousHistoryClick ( ) ;
@@ -246,17 +238,17 @@ function QueryEditor(props) {
246
238
props . changeUserInput ( { input : newValue } ) ;
247
239
} ;
248
240
249
- const handleSendClick = ( ) => {
241
+ const handleSendExecuteClick = ( mode ) => {
250
242
const {
251
243
path,
252
- executeQuery : { input, history, runAction } ,
253
- sendQuery ,
244
+ executeQuery : { input, history} ,
245
+ sendExecuteQuery ,
254
246
saveQueryToHistory,
255
247
setShowPreview,
256
248
} = props ;
257
249
258
250
setResultType ( RESULT_TYPES . EXECUTE ) ;
259
- sendQuery ( { query : input , database : path , action : runAction } ) ;
251
+ sendExecuteQuery ( { query : input , database : path , mode } ) ;
260
252
setIsResultLoaded ( true ) ;
261
253
setShowPreview ( false ) ;
262
254
@@ -267,15 +259,20 @@ function QueryEditor(props) {
267
259
dispatchResultVisibilityState ( PaneVisibilityActionTypes . triggerExpand ) ;
268
260
} ;
269
261
270
- const handleGetExplainQueryClick = ( ) => {
262
+ const handleGetExplainQueryClick = ( mode ) => {
271
263
const {
272
264
path,
273
265
executeQuery : { input} ,
274
266
getExplainQuery,
275
267
setShowPreview,
276
268
} = props ;
269
+
277
270
setResultType ( RESULT_TYPES . EXPLAIN ) ;
278
- getExplainQuery ( { query : input , database : path } ) ;
271
+ getExplainQuery ( {
272
+ query : input ,
273
+ database : path ,
274
+ mode : mode ,
275
+ } ) ;
279
276
setIsResultLoaded ( true ) ;
280
277
setShowPreview ( false ) ;
281
278
dispatchResultVisibilityState ( PaneVisibilityActionTypes . triggerExpand ) ;
@@ -513,65 +510,42 @@ function QueryEditor(props) {
513
510
setSettingValue ( SAVED_QUERIES_KEY , JSON . stringify ( newSavedQueries ) ) ;
514
511
} ;
515
512
516
- const renderControls = ( ) => {
517
- const { executeQuery, explainQuery, savedQueries, selectRunAction, setSettingValue} = props ;
518
- const { runAction} = executeQuery ;
519
- const runIsDisabled = ! executeQuery . input || executeQuery . loading ;
520
- const runText = _ . find ( RUN_ACTIONS , { value : runAction } ) . content ;
521
-
522
- const menuItems = RUN_ACTIONS . map ( ( action ) => {
523
- return {
524
- text : action . content ,
525
- action : ( ) => {
526
- selectRunAction ( action . value ) ;
527
- setSettingValue ( QUERY_INITIAL_RUN_ACTION_KEY , action . value ) ;
528
- } ,
529
- } ;
530
- } ) ;
513
+ const onUpdateQueryMode = ( mode ) => {
514
+ setQueryMode ( mode ) ;
515
+ props . setSettingValue ( QUERY_INITIAL_MODE_KEY , mode ) ;
516
+ } ;
531
517
532
- return (
533
- < div className = { b ( 'controls' ) } >
534
- < div className = { b ( 'control-run' ) } >
535
- < Button
536
- onClick = { handleSendClick }
537
- view = "action"
538
- pin = "round-brick"
539
- disabled = { runIsDisabled }
540
- loading = { executeQuery . loading }
541
- >
542
- < Icon name = "startPlay" viewBox = "0 0 16 16" width = { 16 } height = { 16 } />
543
- { runText }
544
- </ Button >
545
- < DropdownMenu
546
- items = { menuItems }
547
- popupClassName = { b ( 'select-query-action-popup' ) }
548
- switcher = {
549
- < Button
550
- view = "action"
551
- pin = "brick-round"
552
- disabled = { runIsDisabled }
553
- loading = { executeQuery . loading }
554
- className = { b ( 'select-query-action' ) }
555
- >
556
- < Icon name = "chevron-down" width = { 16 } height = { 16 } />
557
- </ Button >
558
- }
559
- />
560
- </ div >
561
- < Button
562
- onClick = { handleGetExplainQueryClick }
563
- disabled = { ! executeQuery . input }
564
- loading = { explainQuery . loading }
565
- >
566
- Explain
567
- </ Button >
568
- < Divider />
569
- < SaveQuery
518
+ const renderControls = ( ) => {
519
+ const { executeQuery, explainQuery, savedQueries, enableQueryModesForExplain} = props ;
520
+
521
+ if ( enableQueryModesForExplain ) {
522
+ return (
523
+ < QueryEditorControls
524
+ onRunButtonClick = { handleSendExecuteClick }
525
+ runIsLoading = { executeQuery . loading }
526
+ onExplainButtonClick = { handleGetExplainQueryClick }
527
+ explainIsLoading = { explainQuery . loading }
528
+ onSaveQueryClick = { onSaveQueryHandler }
570
529
savedQueries = { savedQueries }
571
- onSaveQuery = { onSaveQueryHandler }
572
- saveButtonDisabled = { runIsDisabled }
530
+ disabled = { ! executeQuery . input }
531
+ onUpdateQueryMode = { onUpdateQueryMode }
532
+ queryMode = { queryMode }
573
533
/>
574
- </ div >
534
+ ) ;
535
+ }
536
+
537
+ return (
538
+ < OldQueryEditorControls
539
+ onRunButtonClick = { handleSendExecuteClick }
540
+ runIsLoading = { executeQuery . loading }
541
+ onExplainButtonClick = { handleGetExplainQueryClick }
542
+ explainIsLoading = { explainQuery . loading }
543
+ onSaveQueryClick = { onSaveQueryHandler }
544
+ savedQueries = { savedQueries }
545
+ disabled = { ! executeQuery . input }
546
+ onUpdateQueryMode = { onUpdateQueryMode }
547
+ queryMode = { queryMode }
548
+ />
575
549
) ;
576
550
} ;
577
551
@@ -632,23 +606,24 @@ const mapStateToProps = (state) => {
632
606
return {
633
607
executeQuery : state . executeQuery ,
634
608
explainQuery : state . explainQuery ,
635
- savedQueries : parseJson ( getSettingValue ( state , SAVED_QUERIES_KEY ) ) ,
609
+ savedQueries : getParsedSettingValue ( state , SAVED_QUERIES_KEY ) ,
610
+ initialQueryMode : getParsedSettingValue ( state , QUERY_INITIAL_MODE_KEY ) ,
611
+ enableQueryModesForExplain : getParsedSettingValue ( state , ENABLE_QUERY_MODES_FOR_EXPLAIN ) ,
636
612
showPreview : state . schema . showPreview ,
637
613
currentSchema : state . schema . currentSchema ,
638
614
monacoHotKey : state . executeQuery ?. monacoHotKey ,
639
615
} ;
640
616
} ;
641
617
642
618
const mapDispatchToProps = {
643
- sendQuery ,
619
+ sendExecuteQuery ,
644
620
changeUserInput,
645
621
saveQueryToHistory,
646
622
goToPreviousQuery,
647
623
goToNextQuery,
648
624
getExplainQuery,
649
625
getExplainQueryAst,
650
626
setSettingValue,
651
- selectRunAction,
652
627
setShowPreview,
653
628
setMonacoHotKey,
654
629
} ;
0 commit comments