@@ -23,11 +23,7 @@ import {PipeProp} from 'src/types/flows'
2323// Context
2424import { PipeContext } from 'src/flows/context/pipe'
2525import { SidebarContext } from 'src/flows/context/sidebar'
26- import {
27- EditorContext ,
28- EditorProvider ,
29- InjectionType ,
30- } from 'src/flows/context/editor'
26+ import { EditorContext , EditorProvider } from 'src/shared/contexts/editor'
3127import { VariablesContext } from 'src/flows/context/variables'
3228
3329// Components
@@ -39,10 +35,6 @@ import DynamicFunctions from 'src/flows/pipes/RawFluxEditor/FunctionsList/Dynami
3935import 'src/flows/pipes/RawFluxEditor/style.scss'
4036
4137// Utils
42- import {
43- isPipeTransformation ,
44- functionRequiresNewLine ,
45- } from 'src/shared/utils/fluxFunctions'
4638import { event } from 'src/cloud/utils/reporting'
4739import { CLOUD } from 'src/shared/constants'
4840import { isFlagEnabled } from 'src/shared/utils/featureFlag'
@@ -52,12 +44,12 @@ const FluxMonacoEditor = lazy(() =>
5244)
5345
5446const Query : FC < PipeProp > = ( { Context} ) => {
55- const { id, data} = useContext ( PipeContext )
47+ const { id, data, update } = useContext ( PipeContext )
5648 const { hideSub, id : showId , show, showSub, register} = useContext (
5749 SidebarContext
5850 )
5951 const editorContext = useContext ( EditorContext )
60- const { setEditor, inject, updateText } = editorContext
52+ const { setEditor, inject, injectFunction } = editorContext
6153 const { queries, activeQuery} = data
6254 const query = queries [ activeQuery ]
6355 const { variables} = useContext ( VariablesContext )
@@ -71,54 +63,35 @@ const Query: FC<PipeProp> = ({Context}) => {
7163 {
7264 title : 'Inject Secret' ,
7365 disable : ( ) => false ,
74- menu : < SecretsList inject = { inject } /> ,
66+ menu : < SecretsList inject = { inject } cbOnInject = { updateText } /> ,
7567 } ,
7668 ] ,
7769 } ,
7870 ] )
7971 }
8072 } , [ id , inject ] )
8173
82- const injectIntoEditor = useCallback (
83- ( fn ) : void => {
84- const text = isPipeTransformation ( fn )
85- ? ` |> ${ fn . example } `
86- : `${ fn . example } `
87-
88- const getHeader = fn => {
89- let importStatement = null
90-
91- // universe packages are loaded by deafult. Don't need import statement
92- if ( fn . package && fn . package !== 'universe' ) {
93- importStatement = `import "${ fn . package } "`
94- if (
95- CLOUD &&
96- isFlagEnabled ( 'fluxDynamicDocs' ) &&
97- fn . path . includes ( '/' )
98- ) {
99- importStatement = `import "${ fn . path } "`
100- }
101- }
102- return importStatement
74+ const updateText = useCallback (
75+ text => {
76+ const _queries = [ ...queries ]
77+ _queries [ activeQuery ] = {
78+ ...queries [ activeQuery ] ,
79+ text,
10380 }
10481
105- const type =
106- isPipeTransformation ( fn ) || functionRequiresNewLine ( fn )
107- ? InjectionType . OnOwnLine
108- : InjectionType . SameLine
82+ update ( { queries : _queries } )
83+ } ,
84+ [ queries , activeQuery ]
85+ )
10986
110- const options = {
111- text,
112- type,
113- header : getHeader ( fn ) ,
114- triggerSuggest : true ,
115- }
116- inject ( options )
87+ const injectIntoEditor = useCallback (
88+ ( fn ) : void => {
89+ injectFunction ( fn , updateText )
11790 } ,
118- [ inject ]
91+ [ injectFunction , updateText ]
11992 )
12093
121- const launcher = ( ) => {
94+ const launcher = useCallback ( ( ) => {
12295 if ( showId === id ) {
12396 event ( 'Flux Panel (Notebooks) - Toggle Functions - Off' )
12497 hideSub ( )
@@ -131,7 +104,7 @@ const Query: FC<PipeProp> = ({Context}) => {
131104 showSub ( < Functions onSelect = { injectIntoEditor } /> )
132105 }
133106 }
134- }
107+ } , [ injectIntoEditor , showId ] )
135108
136109 const controls = (
137110 < Button
@@ -172,6 +145,7 @@ const Query: FC<PipeProp> = ({Context}) => {
172145 updateText ,
173146 editorContext . editor ,
174147 variables ,
148+ launcher ,
175149 ]
176150 )
177151}
0 commit comments