@@ -117,52 +117,6 @@ type EditorProviderProps = {
117117 resetFormRef ?: React . MutableRefObject < ( ( ) => void ) | null >
118118}
119119
120- /**
121- * Helper function to update the flow in the cache
122- */
123- function updateHandlerFactory ( flowId : string , previousStepId : string ) {
124- return function createStepUpdateHandler ( cache : any , mutationResult : any ) {
125- const { data } = mutationResult
126- const { createStep : createdStep } = data
127- const { getFlow : flow } = cache . readQuery ( {
128- query : GET_FLOW ,
129- variables : { id : flowId } ,
130- } )
131-
132- // getFlow requires certain attributes to be returned
133- const completeCreatedStep = {
134- ...createdStep ,
135- iconUrl : null ,
136- webhookUrl : null ,
137- config : {
138- stepName : null ,
139- templateConfig : {
140- appEventKey : createdStep . config ?. templateConfig ?. appEventKey ?? null ,
141- } ,
142- approval : {
143- branch : createdStep . config ?. approval ?. branch ?? null ,
144- stepId : createdStep . config ?. approval ?. stepId ?? null ,
145- } ,
146- } ,
147- createdAt : new Date ( ) . toISOString ( ) ,
148- }
149-
150- const steps = flow . steps . reduce ( ( steps : any [ ] , currentStep : any ) => {
151- if ( currentStep . id === previousStepId ) {
152- return [ ...steps , currentStep , completeCreatedStep ]
153- }
154-
155- return [ ...steps , currentStep ]
156- } , [ ] )
157-
158- cache . writeQuery ( {
159- query : GET_FLOW ,
160- variables : { id : flowId } ,
161- data : { getFlow : { ...flow , steps } } ,
162- } )
163- }
164- }
165-
166120export const EditorProvider = ( {
167121 readOnly,
168122 flow,
@@ -260,36 +214,17 @@ export const EditorProvider = ({
260214
261215 const createdStep = await createStep ( {
262216 variables : { input : mutationInput } ,
263- update : updateHandlerFactory ( flowId , previousStepId ) ,
264217 } )
265218
266- const newStep = createdStep . data . createStep
219+ let newStep = createdStep . data . createStep
267220 setCurrentStepId ( newStep . id )
268221
269222 // account for the for-each and if-then
270- if ( appKey === TOOLBOX_APP_KEY ) {
271- // Get the complete step data from the cache
272- const { getFlow : updatedFlow } = client . readQuery ( {
273- query : GET_FLOW ,
274- variables : { id : flowId } ,
275- } )
276-
277- const completeStep = updatedFlow . steps . find (
278- ( s : IStep ) => s . id === newStep . id ,
279- )
280-
281- if ( completeStep ) {
282- const completeStepWithFlow = {
283- ...completeStep ,
284- flowId : flowId ,
285- }
286- if ( eventKey === TOOLBOX_ACTIONS . IfThen ) {
287- return ( await initializeIfThen (
288- completeStepWithFlow ,
289- ) ) as unknown as IStep
290- }
291- }
223+ if ( appKey === TOOLBOX_APP_KEY && eventKey === TOOLBOX_ACTIONS . IfThen ) {
224+ newStep = await initializeIfThen ( newStep )
292225 }
226+ // we refetch GET_FLOW after everything is completed
227+ await client . refetchQueries ( { include : [ GET_FLOW ] } )
293228
294229 return newStep as IStep
295230 } ,
0 commit comments