@@ -17,6 +17,15 @@ export function QueryEditor(props: QueryEditorProps<CHDataSource, CHQuery, CHDat
17
17
const isAnnotationView = ! props . app ;
18
18
const initializedQuery = initializeQueryDefaults ( query , isAnnotationView , datasource , onChange ) ;
19
19
const [ formattedData , error ] = useFormattedData ( initializedQuery , datasource , data ?. request ) ;
20
+
21
+ useEffect ( ( ) => {
22
+ if ( formattedData !== initializedQuery . query ) {
23
+ onChange ( { ...initializedQuery , rawQuery : formattedData } )
24
+ }
25
+
26
+ // eslint-disable-next-line
27
+ } , [ formattedData , initializedQuery . query ] ) ;
28
+
20
29
const [ editorMode , setEditorMode ] = useState ( initializedQuery . editorMode || EditorMode . Builder ) ;
21
30
useQueryState ( query , onChange , datasource ) ;
22
31
@@ -89,6 +98,15 @@ export function QueryEditorVariable(props: QueryEditorProps<CHDataSource, CHQuer
89
98
const initializedQuery = initializeQueryDefaultsForVariables ( processedQuery , isAnnotationView , datasource , onChange ) ;
90
99
const [ formattedData , error ] = useFormattedData ( initializedQuery , datasource ) ;
91
100
const [ editorMode , setEditorMode ] = useState ( initializedQuery . editorMode || EditorMode . Builder ) ;
101
+
102
+ useEffect ( ( ) => {
103
+ if ( formattedData !== initializedQuery . query ) {
104
+ onChange ( { ...initializedQuery , rawQuery : formattedData } )
105
+ }
106
+
107
+ // eslint-disable-next-line
108
+ } , [ formattedData , initializedQuery . query ] ) ;
109
+
92
110
useQueryState ( query , onChange , datasource ) ;
93
111
const onSqlChange = ( sql : string ) => onChange ( { ...initializedQuery , query : sql } ) ;
94
112
const onFieldChange = ( field : any ) => onChange ( { ...initializedQuery , [ field . fieldName ] : field . value } ) ;
0 commit comments