diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts index 85bfbf9df8..aac4a303bc 100644 --- a/web/app/components/workflow/hooks/use-workflow.ts +++ b/web/app/components/workflow/hooks/use-workflow.ts @@ -218,7 +218,6 @@ export const useWorkflow = () => { const effectNodes = findUsedVarNodes(oldValeSelector, afterNodes) // console.log(effectNodes) if (effectNodes.length > 0) { - // debugger const newNodes = getNodes().map((node) => { if (effectNodes.find(n => n.id === node.id)) return updateNodeVars(node, oldValeSelector, newVarSelector) diff --git a/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts b/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts index 74acabb427..918b97a0f6 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-output-var-list.ts @@ -2,8 +2,12 @@ import { useCallback } from 'react' import produce from 'immer' import { type OutputVar } from '../../code/types' import { VarType } from '@/app/components/workflow/types' +import { + useWorkflow, +} from '@/app/components/workflow/hooks' type Params = { + id: string inputs: T setInputs: (newInputs: T) => void varKey?: string @@ -11,12 +15,15 @@ type Params = { onOutputKeyOrdersChange: (newOutputKeyOrders: string[]) => void } function useOutputVarList({ + id, inputs, setInputs, varKey = 'outputs', outputKeyOrders = [], onOutputKeyOrdersChange, }: Params) { + const { handleOutVarRenameChange } = useWorkflow() + const handleVarsChange = useCallback((newVars: OutputVar, changedIndex?: number, newKey?: string) => { const newInputs = produce(inputs, (draft: any) => { draft[varKey] = newVars @@ -29,7 +36,10 @@ function useOutputVarList({ }) onOutputKeyOrdersChange(newOutputKeyOrders) } - }, [inputs, setInputs, varKey, outputKeyOrders, onOutputKeyOrdersChange]) + + if (newKey) + handleOutVarRenameChange(id, [id, outputKeyOrders[changedIndex!]], [id, newKey]) + }, [inputs, setInputs, handleOutVarRenameChange, id, outputKeyOrders, varKey, onOutputKeyOrdersChange]) const handleAddVariable = useCallback(() => { const newKey = `var-${Object.keys((inputs as any)[varKey]).length + 1}` diff --git a/web/app/components/workflow/nodes/code/use-config.ts b/web/app/components/workflow/nodes/code/use-config.ts index 85f0948aff..9d86a4e2a9 100644 --- a/web/app/components/workflow/nodes/code/use-config.ts +++ b/web/app/components/workflow/nodes/code/use-config.ts @@ -86,6 +86,7 @@ const useConfig = (id: string, payload: CodeNodeType) => { }, [allLanguageDefault, inputs, setInputs]) const { handleVarsChange, handleAddVariable: handleAddOutputVariable, handleRemoveVariable } = useOutputVarList({ + id, inputs, setInputs, outputKeyOrders,