From 8413090c49dad4c1466a190d08231185336763fa Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 21 May 2025 15:34:20 +0800 Subject: [PATCH] chore: enchance set inspect var value and remove node vars --- .../workflow/debug/inspect-vars-slice.ts | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts index 8140280b61..f3eacf6fec 100644 --- a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts +++ b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts @@ -59,30 +59,31 @@ export const createInspectVarsSlice: StateCreator = (set, }) }, deleteNodeInspectVars: (nodeId) => { - set(produce((state: InspectVarsSliceShape) => { + set((state: InspectVarsSliceShape) => { const nodes = state.nodesWithInspectVars.filter(node => node.nodeId !== nodeId) - state.nodesWithInspectVars = nodes + return { + nodesWithInspectVars: nodes, + } }, - )) + ) }, setInspectVarValue: (nodeId, varId, value) => { - set(produce((state: InspectVarsSliceShape) => { - const nodes = state.nodesWithInspectVars.map((node) => { - if (node.nodeId === nodeId) { - return produce(node, (draft) => { - const needChangeVarIndex = draft.vars.findIndex((varItem) => { - return varItem.id === varId - }) - if (needChangeVarIndex !== -1) { - draft.vars[needChangeVarIndex].value = value - draft.vars[needChangeVarIndex].edited = true - } - }) - } - return node - }) - state.nodesWithInspectVars = nodes - })) + set((state: InspectVarsSliceShape) => { + const nodes = produce(state.nodesWithInspectVars, (draft) => { + const targetNode = draft.find(node => node.nodeId === nodeId) + if (!targetNode) + return + const targetVar = targetNode.vars.find(varItem => varItem.id === varId) + if(!targetVar) + return + targetVar.value = value + targetVar.edited = true + }, + ) + return { + nodesWithInspectVars: nodes, + } + }) }, renameInspectVarName: (nodeId, varId, selector) => { set((state: InspectVarsSliceShape) => {