From 6015c0644aeca36bcb04629cfe0a9bf40d11c392 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 15 May 2025 18:02:08 +0800 Subject: [PATCH] chore: var aggrect rename throtte --- .../nodes/variable-assigner/use-config.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/web/app/components/workflow/nodes/variable-assigner/use-config.ts b/web/app/components/workflow/nodes/variable-assigner/use-config.ts index baf99d63b4..c65941e32d 100644 --- a/web/app/components/workflow/nodes/variable-assigner/use-config.ts +++ b/web/app/components/workflow/nodes/variable-assigner/use-config.ts @@ -1,6 +1,6 @@ -import { useCallback, useState } from 'react' +import { useCallback, useRef, useState } from 'react' import produce from 'immer' -import { useBoolean } from 'ahooks' +import { useBoolean, useDebounceFn } from 'ahooks' import { v4 as uuid4 } from 'uuid' import type { ValueSelector, Var } from '../../types' import { VarType } from '../../types' @@ -143,6 +143,20 @@ const useConfig = (id: string, payload: VariableAssignerNodeType) => { deleteNodeInspectorVars(id) }, [deleteNodeInspectorVars, id, inputs, setInputs]) + // record the first old name value + const oldNameRecord = useRef>({}) + + const { + run: renameInspectNameWithDebounce, + } = useDebounceFn( + (id: string, newName: string) => { + const oldName = oldNameRecord.current[id] + renameInspectVarName(id, oldName, newName) + delete oldNameRecord.current[id] + }, + { wait: 500 }, + ) + const handleVarGroupNameChange = useCallback((groupId: string) => { return (name: string) => { const index = inputs.advanced_settings.groups.findIndex(item => item.groupId === groupId) @@ -151,9 +165,11 @@ const useConfig = (id: string, payload: VariableAssignerNodeType) => { }) handleOutVarRenameChange(id, [id, inputs.advanced_settings.groups[index].group_name, 'output'], [id, name, 'output']) setInputs(newInputs) - renameInspectVarName(id, inputs.advanced_settings.groups[index].group_name, name) + if(!(id in oldNameRecord.current)) + oldNameRecord.current[id] = inputs.advanced_settings.groups[index].group_name + renameInspectNameWithDebounce(id, name) } - }, [handleOutVarRenameChange, id, inputs, renameInspectVarName, setInputs]) + }, [handleOutVarRenameChange, id, inputs, renameInspectNameWithDebounce, setInputs]) const onRemoveVarConfirm = useCallback(() => { removedVars.forEach((v) => {