diff --git a/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx b/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx index ac26971359..58f21c14a4 100644 --- a/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx +++ b/web/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list.tsx @@ -2,7 +2,7 @@ import { useModelList } from '@/app/components/header/account-setting/model-prov import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { useProviderContext } from '@/context/provider-context' import { useInvalidateInstalledPluginList } from '@/service/use-plugins' -import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders } from '@/service/use-tools' +import { useInvalidateAllBuiltInTools, useInvalidateAllToolProviders, useInvalidateApoNodes } from '@/service/use-tools' import { useInvalidateStrategyProviders } from '@/service/use-strategy' import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types' import { PluginType } from '../../types' @@ -16,6 +16,7 @@ const useRefreshPluginList = () => { const invalidateAllToolProviders = useInvalidateAllToolProviders() const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools() + const invalidateApoNodes = useInvalidateApoNodes() const invalidateStrategyProviders = useInvalidateStrategyProviders() return { @@ -27,6 +28,7 @@ const useRefreshPluginList = () => { if ((manifest && PluginType.tool.includes(manifest.category)) || refreshAllType) { invalidateAllToolProviders() invalidateAllBuiltInTools() + invalidateApoNodes() // TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins } diff --git a/web/app/components/workflow/apo/tool-preview/apo-tools-preview.tsx b/web/app/components/workflow/apo/tool-preview/apo-tools-preview.tsx index a4506cb02d..e977085327 100644 --- a/web/app/components/workflow/apo/tool-preview/apo-tools-preview.tsx +++ b/web/app/components/workflow/apo/tool-preview/apo-tools-preview.tsx @@ -26,7 +26,7 @@ const ApoToolsPreview = ({ onSelect, apoToolType, hidePopover }: ApoToolsPreview const [provider, setProvider] = useState() const [searchText, setSearchText] = useState() const getAllTools = async () => { - const tools = await fetchApoTools(apoToolType, searchText) + const tools = await fetchApoTools(apoToolType, searchText, language) // setSearchText('') setProvider(tools[0]) setTools(tools[0]?.tools) diff --git a/web/app/components/workflow/block-selector/apoTools.tsx b/web/app/components/workflow/block-selector/apoTools.tsx index 1ab1c37152..d69e9220d7 100644 --- a/web/app/components/workflow/block-selector/apoTools.tsx +++ b/web/app/components/workflow/block-selector/apoTools.tsx @@ -1,87 +1,58 @@ +import type { ToolWithProvider } from '../types' import { BlockEnum } from '../types' import cn from '@/utils/classnames' -import { useEffect, useState } from 'react' +import { useMemo, useState } from 'react' import type { ToolDefaultValue } from './types' import { Popover } from 'antd' import ApoToolsPreview from '../apo/tool-preview/apo-tools-preview' import type { ApoToolTypeInfo } from '../apo/types' -import { fetchApoNode } from '@/service/tools' import { useGetLanguage } from '@/context/i18n' import BlockIcon from '../block-icon' + type APOToolsProps = { searchText: string; - onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void + onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void; + apoNodes?: ToolWithProvider[] } -const APOTools = ({ searchText, onSelect }: APOToolsProps) => { + +const APOTools = ({ searchText, onSelect, apoNodes = [] }: APOToolsProps) => { const language = useGetLanguage() - const [openKey, setOpenKey] = useState({ - apo_select: false, - apo_analysis: false, - apo_rule: false, - }) - const [apoNodes, setApoNodes] = useState([]) - const hide = (key: ApoToolTypeInfo) => { - setOpenKey(prev => ({ - ...prev, - [key]: false, - })) - } + const [openKey, setOpenKey] = useState>({}) + + const filteredApoNodes = useMemo(() => { + const lowerCaseSearch = searchText.toLowerCase() + return apoNodes.filter(node => node.label[language]?.toLowerCase().includes(lowerCaseSearch)) + }, [searchText, apoNodes, language]) const handleOpenChange = (key: ApoToolTypeInfo, newOpen: boolean) => { - setOpenKey(prev => ({ - ...prev, - [key]: newOpen, - })) + setOpenKey(prev => ({ ...prev, [key]: newOpen })) } - const getApoNodes = async () => { - const data = await fetchApoNode() - setApoNodes(data) + const hide = (key: ApoToolTypeInfo) => { + setOpenKey(prev => ({ ...prev, [key]: false })) } - useEffect(() => { - getApoNodes() - }, []) + return ( - <> -
- {apoNodes?.map(node => ( - handleOpenChange(node.id, newOpen)} - content={ - hide(node.name)}/> - } - > -
- -
- {node?.label[language]} -
-
-
- ))} -
- {/* { - setApoToolType(null) - setShowRecommendModal(false) - }} - /> */} - +
+ {filteredApoNodes.map(node => ( + handleOpenChange(node.id, newOpen)} + content={ + hide(node.name)} /> + } + > +
+ +
{node.label[language]}
+
+
+ ))} +
) } + export default APOTools diff --git a/web/app/components/workflow/block-selector/tabs.tsx b/web/app/components/workflow/block-selector/tabs.tsx index 921e702268..6d270f4db3 100644 --- a/web/app/components/workflow/block-selector/tabs.tsx +++ b/web/app/components/workflow/block-selector/tabs.tsx @@ -1,6 +1,6 @@ import type { FC } from 'react' import { memo } from 'react' -import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools } from '@/service/use-tools' +import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools, useApoNodes } from '@/service/use-tools' import type { BlockEnum } from '../types' import { useTabs } from './hooks' import type { ToolDefaultValue } from './types' @@ -32,7 +32,7 @@ const Tabs: FC = ({ const { data: buildInTools } = useAllBuiltInTools() const { data: customTools } = useAllCustomTools() const { data: workflowTools } = useAllWorkflowTools() - + const { data: apoNodes } = useApoNodes() return (
e.stopPropagation()} className='h-full flex flex-col min-h-[80vh]'> { @@ -59,7 +59,7 @@ const Tabs: FC = ({ } { activeTab === TabsEnum.Blocks && !noBlocks && ( -
+
{ }) } -export const fetchApoTools = (apoToolType: string, queryText: string) => { +export const fetchApoTools = (apoToolType: string, queryText: string, language: string) => { return get('/workspaces/current/tools/apo', { params: { tool_type: apoToolType, query: queryText, + language, }, }) } diff --git a/web/service/use-tools.ts b/web/service/use-tools.ts index ceaa4b14b3..7691dfa821 100644 --- a/web/service/use-tools.ts +++ b/web/service/use-tools.ts @@ -119,3 +119,14 @@ export const useRemoveProviderCredentials = ({ onSuccess, }) } + +const useApoNodesKey = [NAME_SPACE, 'apoNodes'] +export const useApoNodes = () => { + return useQuery({ + queryKey: useApoNodesKey, + queryFn: () => get('/workspaces/current/tools/apo/list'), + }) +} +export const useInvalidateApoNodes = () => { + return useInvalid(useApoNodesKey) +}