From 1c36fcb092fdd2bb8f5f5aabef112a677a4f2bff Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 23 Aug 2022 22:34:16 +0200 Subject: [PATCH] make code injection works with multiline --- frontend/src/lib/components/flows/utils.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/components/flows/utils.ts b/frontend/src/lib/components/flows/utils.ts index b2c702845a..cf34232171 100644 --- a/frontend/src/lib/components/flows/utils.ts +++ b/frontend/src/lib/components/flows/utils.ts @@ -106,16 +106,14 @@ export async function loadSchemaFromModule(module: FlowModule): Promise<{ } } -const returnStatementRegex = new RegExp(/\$\{(.*)\}/) +const dynamicTemplateRegex = new RegExp(/\$\{(.*)\}/) export function isCodeInjection(expr: string | undefined): boolean { if (!expr) { return false } - const lines = expr.split('\n') - const [returnStatement] = lines.reverse() - return returnStatementRegex.test(returnStatement) + return dynamicTemplateRegex.test(expr) } export function getDefaultExpr( @@ -124,9 +122,8 @@ export function getDefaultExpr( previousExpr?: string ) { const expr = previousExpr ?? `previous_result.${key}` - return `import { previous_result, flow_input, step, variable, resource, params } from 'windmill${ - importPath ? `@${importPath}` : '' - }' + return `import { previous_result, flow_input, step, variable, resource, params } from 'windmill${importPath ? `@${importPath}` : '' + }' ${expr}` }