refactor: streamline workflow variable hooks by replacing useStore with useAll*Tools for improved data handling

This commit is contained in:
twwu 2025-10-23 17:18:02 +08:00
parent dc21ab5f59
commit a799493bf7
2 changed files with 7 additions and 11 deletions

View File

@ -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 => {

View File

@ -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,