Fix node search (#23795)
This commit is contained in:
@@ -218,7 +218,6 @@ export const useShortcuts = (): void => {
|
|||||||
useKeyPress(
|
useKeyPress(
|
||||||
'shift',
|
'shift',
|
||||||
(e) => {
|
(e) => {
|
||||||
console.log('Shift down', e)
|
|
||||||
if (shouldHandleShortcut(e))
|
if (shouldHandleShortcut(e))
|
||||||
dimOtherNodes()
|
dimOtherNodes()
|
||||||
},
|
},
|
||||||
|
@@ -7,6 +7,11 @@ import type { CommonNodeType } from '../types'
|
|||||||
import { workflowNodesAction } from '@/app/components/goto-anything/actions/workflow-nodes'
|
import { workflowNodesAction } from '@/app/components/goto-anything/actions/workflow-nodes'
|
||||||
import BlockIcon from '@/app/components/workflow/block-icon'
|
import BlockIcon from '@/app/components/workflow/block-icon'
|
||||||
import { setupNodeSelectionListener } from '../utils/node-navigation'
|
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'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to register workflow nodes search functionality
|
* Hook to register workflow nodes search functionality
|
||||||
@@ -16,6 +21,11 @@ export const useWorkflowSearch = () => {
|
|||||||
const { handleNodeSelect } = useNodesInteractions()
|
const { handleNodeSelect } = useNodesInteractions()
|
||||||
|
|
||||||
// Filter and process nodes for search
|
// Filter and process nodes for search
|
||||||
|
const buildInTools = useStore(s => s.buildInTools)
|
||||||
|
const customTools = useStore(s => s.customTools)
|
||||||
|
const workflowTools = useStore(s => s.workflowTools)
|
||||||
|
const mcpTools = useStore(s => s.mcpTools)
|
||||||
|
|
||||||
const searchableNodes = useMemo(() => {
|
const searchableNodes = useMemo(() => {
|
||||||
const filteredNodes = nodes.filter((node) => {
|
const filteredNodes = nodes.filter((node) => {
|
||||||
if (!node.id || !node.data || node.type === 'sticky') return false
|
if (!node.id || !node.data || node.type === 'sticky') return false
|
||||||
@@ -31,6 +41,20 @@ export const useWorkflowSearch = () => {
|
|||||||
.map((node) => {
|
.map((node) => {
|
||||||
const nodeData = node.data as CommonNodeType
|
const nodeData = node.data as CommonNodeType
|
||||||
|
|
||||||
|
// compute tool icon if node is a Tool
|
||||||
|
let toolIcon: string | Emoji | undefined
|
||||||
|
if (nodeData?.type === BlockEnum.Tool) {
|
||||||
|
let targetTools = workflowTools
|
||||||
|
if (nodeData.provider_type === CollectionType.builtIn)
|
||||||
|
targetTools = buildInTools
|
||||||
|
else if (nodeData.provider_type === CollectionType.custom)
|
||||||
|
targetTools = customTools
|
||||||
|
else if (nodeData.provider_type === CollectionType.mcp)
|
||||||
|
targetTools = mcpTools
|
||||||
|
|
||||||
|
toolIcon = targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, nodeData.provider_id))?.icon
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: node.id,
|
id: node.id,
|
||||||
title: nodeData?.title || nodeData?.type || 'Untitled',
|
title: nodeData?.title || nodeData?.type || 'Untitled',
|
||||||
@@ -38,11 +62,12 @@ export const useWorkflowSearch = () => {
|
|||||||
desc: nodeData?.desc || '',
|
desc: nodeData?.desc || '',
|
||||||
blockType: nodeData?.type,
|
blockType: nodeData?.type,
|
||||||
nodeData,
|
nodeData,
|
||||||
|
toolIcon,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}, [nodes])
|
}, [nodes, buildInTools, customTools, workflowTools, mcpTools])
|
||||||
|
|
||||||
// Create search function for workflow nodes
|
// Create search function for workflow nodes
|
||||||
const searchWorkflowNodes = useCallback((query: string) => {
|
const searchWorkflowNodes = useCallback((query: string) => {
|
||||||
@@ -83,6 +108,7 @@ export const useWorkflowSearch = () => {
|
|||||||
type={node.blockType}
|
type={node.blockType}
|
||||||
className="shrink-0"
|
className="shrink-0"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
toolIcon={node.toolIcon}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
metadata: {
|
metadata: {
|
||||||
|
Reference in New Issue
Block a user