@@ -98,6 +98,28 @@ function QueryEditor(props: QueryEditorProps) {
98
98
99
99
const isResultLoaded = Boolean ( executeQuery . result ) ;
100
100
101
+ const [ inputValue , setInputValue ] = React . useState < string > ( executeQuery . input ) ;
102
+
103
+ const propsChangeUserInput = props . changeUserInput ;
104
+ const changeInputValue = React . useCallback (
105
+ ( input : string ) => {
106
+ setInputValue ( input ) ;
107
+ propsChangeUserInput ( { input} ) ;
108
+ } ,
109
+ [ propsChangeUserInput ] ,
110
+ ) ;
111
+
112
+ React . useEffect ( ( ) => {
113
+ if ( executeQuery . input !== inputValue ) {
114
+ const response = window . confirm ( 'Input value will be lost. Continue?' ) ;
115
+ if ( response ) {
116
+ setInputValue ( executeQuery . input ) ;
117
+ } else {
118
+ changeInputValue ( inputValue ) ;
119
+ }
120
+ }
121
+ } , [ changeInputValue , executeQuery . input , inputValue ] ) ;
122
+
101
123
const [ querySettings ] = useQueryExecutionSettings ( ) ;
102
124
const enableTracingLevel = useTracingLevelOptionAvailable ( ) ;
103
125
const [ lastQueryExecutionSettings , setLastQueryExecutionSettings ] =
@@ -292,10 +314,6 @@ function QueryEditor(props: QueryEditorProps) {
292
314
} ) ;
293
315
} ;
294
316
295
- const onChange = ( newValue : string ) => {
296
- props . changeUserInput ( { input : newValue } ) ;
297
- } ;
298
-
299
317
const onCollapseResultHandler = ( ) => {
300
318
dispatchResultVisibilityState ( PaneVisibilityActionTypes . triggerCollapse ) ;
301
319
} ;
@@ -340,9 +358,9 @@ function QueryEditor(props: QueryEditorProps) {
340
358
< div className = { b ( 'monaco' ) } >
341
359
< MonacoEditor
342
360
language = { YQL_LANGUAGE_ID }
343
- value = { executeQuery . input }
361
+ value = { inputValue }
344
362
options = { editorOptions }
345
- onChange = { onChange }
363
+ onChange = { changeInputValue }
346
364
editorDidMount = { editorDidMount }
347
365
theme = { `vs-${ theme } ` }
348
366
/>
0 commit comments