From d4113eaec130a368703d843758bc52278bf6e2fb Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 29 Apr 2025 11:36:59 +0800 Subject: [PATCH] feat: code output inspect vars change --- .../nodes/_base/hooks/use-output-var-list.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 839cd14026..a479bffbe0 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 @@ -17,6 +17,7 @@ import { } from '@/app/components/workflow/hooks' import { ErrorHandleTypeEnum } from '@/app/components/workflow/nodes/_base/components/error-handle/types' import { getDefaultValue } from '@/app/components/workflow/nodes/_base/components/error-handle/utils' +import useInspectVarsCrud from '../../../hooks/use-inspect-vars-crud' type Params = { id: string @@ -34,6 +35,11 @@ function useOutputVarList({ outputKeyOrders = [], onOutputKeyOrdersChange, }: Params) { + const { + deleteNodeInspectorVars, + renameInspectVarName, + } = useInspectVarsCrud() + const { handleOutVarRenameChange, isVarUsedInNodes, removeUsedVarInNodes } = useWorkflow() const handleVarsChange = useCallback((newVars: OutputVar, changedIndex?: number, newKey?: string) => { @@ -52,9 +58,14 @@ function useOutputVarList({ onOutputKeyOrdersChange(newOutputKeyOrders) } - if (newKey) + if (newKey) { handleOutVarRenameChange(id, [id, outputKeyOrders[changedIndex!]], [id, newKey]) - }, [inputs, setInputs, handleOutVarRenameChange, id, outputKeyOrders, varKey, onOutputKeyOrdersChange]) + renameInspectVarName(id, outputKeyOrders[changedIndex!], newKey) + } + else if (changedIndex === undefined) { + deleteNodeInspectorVars(id) + } + }, [inputs, setInputs, varKey, outputKeyOrders, onOutputKeyOrdersChange, handleOutVarRenameChange, id, renameInspectVarName, deleteNodeInspectorVars]) const generateNewKey = useCallback(() => { let keyIndex = Object.keys((inputs as any)[varKey]).length + 1 @@ -78,7 +89,8 @@ function useOutputVarList({ }) setInputs(newInputs) onOutputKeyOrdersChange([...outputKeyOrders, newKey]) - }, [generateNewKey, inputs, setInputs, onOutputKeyOrdersChange, outputKeyOrders, varKey]) + deleteNodeInspectorVars(id!) + }, [generateNewKey, inputs, setInputs, onOutputKeyOrdersChange, outputKeyOrders, deleteNodeInspectorVars, id, varKey]) const [isShowRemoveVarConfirm, { setTrue: showRemoveVarConfirm,