From a799493bf7c677df884fe1f390caca47602e22d2 Mon Sep 17 00:00:00 2001 From: twwu Date: Thu, 23 Oct 2025 17:18:02 +0800 Subject: [PATCH] refactor: streamline workflow variable hooks by replacing useStore with useAll*Tools for improved data handling --- .../workflow/hooks/use-workflow-search.tsx | 4 ++-- .../workflow/hooks/use-workflow-variables.ts | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/web/app/components/workflow/hooks/use-workflow-search.tsx b/web/app/components/workflow/hooks/use-workflow-search.tsx index 8332c7afbc..68ad9873f9 100644 --- a/web/app/components/workflow/hooks/use-workflow-search.tsx +++ b/web/app/components/workflow/hooks/use-workflow-search.tsx @@ -8,7 +8,6 @@ import { workflowNodesAction } from '@/app/components/goto-anything/actions/work import BlockIcon from '@/app/components/workflow/block-icon' import { setupNodeSelectionListener } from '../utils/node-navigation' import { BlockEnum } from '../types' -import { useStore } from '../store' import type { Emoji } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types' import { canFindTool } from '@/utils' @@ -16,6 +15,7 @@ import type { LLMNodeType } from '../nodes/llm/types' import { useAllBuiltInTools, useAllCustomTools, + useAllMCPTools, useAllWorkflowTools, } from '@/service/use-tools' @@ -30,7 +30,7 @@ export const useWorkflowSearch = () => { const { data: buildInTools } = useAllBuiltInTools() const { data: customTools } = useAllCustomTools() const { data: workflowTools } = useAllWorkflowTools() - const mcpTools = useStore(s => s.mcpTools) + const { data: mcpTools } = useAllMCPTools() // Extract tool icon logic - clean separation of concerns const getToolIcon = useCallback((nodeData: CommonNodeType): string | Emoji | undefined => { diff --git a/web/app/components/workflow/hooks/use-workflow-variables.ts b/web/app/components/workflow/hooks/use-workflow-variables.ts index 962f5ce227..871937365a 100644 --- a/web/app/components/workflow/hooks/use-workflow-variables.ts +++ b/web/app/components/workflow/hooks/use-workflow-variables.ts @@ -93,10 +93,6 @@ export const useWorkflowVariables = () => { conversationVariables, environmentVariables, ragPipelineVariables, - buildInTools, - customTools, - workflowTools, - mcpTools, dataSourceList, } = workflowStore.getState() return getVarType({ @@ -111,16 +107,16 @@ export const useWorkflowVariables = () => { conversationVariables, ragVariables: ragPipelineVariables, allPluginInfoList: { - buildInTools, - customTools, - workflowTools, - mcpTools, + buildInTools: buildInTools || [], + customTools: customTools || [], + workflowTools: workflowTools || [], + mcpTools: mcpTools || [], dataSourceList: dataSourceList ?? [], }, schemaTypeDefinitions, preferSchemaType, }) - }, [workflowStore, getVarType, schemaTypeDefinitions]) + }, [workflowStore, getVarType, schemaTypeDefinitions, buildInTools, customTools, workflowTools, mcpTools]) return { getNodeAvailableVars,