@@ -38,6 +38,7 @@ import 'src/flows/pipes/RawFluxEditor/style.scss'
3838import { event } from 'src/cloud/utils/reporting'
3939import { CLOUD } from 'src/shared/constants'
4040import { isFlagEnabled } from 'src/shared/utils/featureFlag'
41+ import { buildQuery } from 'src/timeMachine/utils/queryBuilder'
4142
4243const FluxMonacoEditor = lazy ( ( ) =>
4344 import ( 'src/shared/components/FluxMonacoEditor' )
@@ -51,9 +52,28 @@ const Query: FC<PipeProp> = ({Context}) => {
5152 const editorContext = useContext ( EditorContext )
5253 const { inject, injectFunction} = editorContext
5354 const { queries, activeQuery} = data
54- const query = queries [ activeQuery ]
55+ // NOTE: this is to migrate bad data from an EAR, not part of the spec
56+ // the first condition is the correct one
57+ const query = Array . isArray ( queries ) ? queries [ activeQuery ] : queries
5558 const { variables} = useContext ( VariablesContext )
5659
60+ // NOTE: this is to migrate bad data from an EAR, not part of the spec
61+ // the first condition is the correct one, no need to call build query
62+ const queryText = query ?. text ?? buildQuery ( query )
63+
64+ // NOTE: this should apply the migration
65+ useEffect ( ( ) => {
66+ if ( Array . isArray ( queries ) ) {
67+ return
68+ }
69+
70+ if ( ! query . text ) {
71+ query . text = buildQuery ( query )
72+ }
73+
74+ update ( { ...data , queries : [ { ...query } ] } )
75+ } , [ id ] )
76+
5777 useEffect ( ( ) => {
5878 if ( isFlagEnabled ( 'fluxInjectSecrets' ) ) {
5979 register ( id , [
@@ -130,7 +150,7 @@ const Query: FC<PipeProp> = ({Context}) => {
130150 }
131151 >
132152 < FluxMonacoEditor
133- script = { query . text }
153+ script = { queryText }
134154 variables = { variables }
135155 onChangeScript = { updateText }
136156 wrapLines = "on"
@@ -141,7 +161,7 @@ const Query: FC<PipeProp> = ({Context}) => {
141161 ) ,
142162 [
143163 RemoteDataState . Loading ,
144- query . text ,
164+ queryText ,
145165 updateText ,
146166 editorContext . editor ,
147167 variables ,
0 commit comments