diff --git a/frontend/src/lib/components/SchemaForm.svelte b/frontend/src/lib/components/SchemaForm.svelte index e806b87280..de691715db 100644 --- a/frontend/src/lib/components/SchemaForm.svelte +++ b/frontend/src/lib/components/SchemaForm.svelte @@ -6,6 +6,7 @@ import Editor from './Editor.svelte' import FieldHeader from './FieldHeader.svelte' import DynamicInputHelpBox from './flows/DynamicInputHelpBox.svelte' + import { codeToStaticTemplate } from './flows/flowStore' import { getCodeInjectionExpr, getDefaultExpr, isCodeInjection } from './flows/utils' import OverlayPropertyPicker from './propertyPicker/OverlayPropertyPicker.svelte' import Toggle from './Toggle.svelte' @@ -41,23 +42,6 @@ let inputCats: { [id: string]: InputCat } = {} - function codeToStaticTemplate(code?: string): string | undefined { - if (!code) return undefined - - const lines = code - .split('\n') - .slice(1) - .filter((x) => x != '') - - if (lines.length == 1) { - const line = lines[0].trim() - if (line[0] == '`' && line.charAt(line.length - 1) == '`') { - return line.slice(1, line.length - 1) - } - } - return undefined - } - function setPropertyType(id: string, rawValue: string, isRaw: boolean) { const arg = args[id] if (!arg) { diff --git a/frontend/src/lib/components/flows/flowStore.ts b/frontend/src/lib/components/flows/flowStore.ts index 8eaa0f65cf..ce525fcebb 100644 --- a/frontend/src/lib/components/flows/flowStore.ts +++ b/frontend/src/lib/components/flows/flowStore.ts @@ -1,5 +1,5 @@ import type { Schema } from '$lib/common' -import { FlowModuleValue, ScriptService, type Flow, type FlowModule } from '$lib/gen' +import { FlowModuleValue, InputTransform, ScriptService, type Flow, type FlowModule } from '$lib/gen' import { initialCode } from '$lib/script_helpers' import { userStore, workspaceStore } from '$lib/stores' import { derived, get, writable } from 'svelte/store' @@ -15,6 +15,13 @@ export function initFlow(flow: Flow) { const newMode = flow.value.modules[1]?.value.type === FlowModuleValue.type.FORLOOPFLOW ? 'pull' : 'push' mode.set(newMode) flow = flattenForloopFlows(flow, newMode) + flow.value.modules.forEach((mod) => { + Object.values(mod.input_transform).forEach((inp) => { + if (inp.type == InputTransform.type.JAVASCRIPT) { + inp.value = codeToStaticTemplate(inp.expr) + } + }) + }) schemasStore.set([]) flowStore.set(flow) // For each module in flow, we should load the corresponding schema @@ -23,6 +30,22 @@ export function initFlow(flow: Flow) { }) } +export function codeToStaticTemplate(code?: string): string | undefined { + if (!code) return undefined + + const lines = code + .split('\n') + .slice(1) + .filter((x) => x != '') + + if (lines.length == 1) { + const line = lines[0].trim() + if (line[0] == '`' && line.charAt(line.length - 1) == '`') { + return line.slice(1, line.length - 1) + } + } + return undefined +} export function flattenForloopFlows(flow: Flow, mode: FlowMode): Flow { let newFlow: Flow = JSON.parse(JSON.stringify(flow)) if (mode == 'pull') {