From b8ecfd859b374c1d831f5077d57c5ea5ea9bf112 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 18 Mar 2024 11:03:23 +0800 Subject: [PATCH] feat: fill single run form variable with constant value first time --- .../components/workflow/nodes/tool/use-config.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/nodes/tool/use-config.ts b/web/app/components/workflow/nodes/tool/use-config.ts index b0a1e84a1a..e3163172a1 100644 --- a/web/app/components/workflow/nodes/tool/use-config.ts +++ b/web/app/components/workflow/nodes/tool/use-config.ts @@ -153,6 +153,17 @@ const useConfig = (id: string, payload: ToolNodeType) => { setRunInputData(value) } + // fill single run form variable with constant value first time + const inputVarValuesWithConstantValue = () => { + const res = produce(inputVarValues, (draft) => { + inputs.tool_parameters.forEach(({ variable, variable_type, value }: any) => { + if (variable_type === VarType.static && (draft[variable] === undefined || draft[variable] === null)) + draft[variable] = value + }) + }) + return res + } + const singleRunForms = (() => { const formInputs: InputVar[] = [] toolInputVarSchema.forEach((item: any) => { @@ -165,7 +176,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { }) const forms: FormProps[] = [{ inputs: formInputs, - values: inputVarValues, + values: inputVarValuesWithConstantValue(), onChange: setInputVarValues, }] return forms