import { memo, useCallback, useRef, } from 'react' import { useTranslation } from 'react-i18next' import type { BlockEnum, ToolWithProvider } from '../types' import IndexBar, { groupItems } from './index-bar' import type { ToolDefaultValue } from './types' import ToolItem from './tool-item' import Empty from '@/app/components/tools/add-tool-modal/empty' import { useGetLanguage } from '@/context/i18n' type ToolsProps = { showWorkflowEmpty: boolean onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void tools: ToolWithProvider[] } const Blocks = ({ showWorkflowEmpty, onSelect, tools, }: ToolsProps) => { const { t } = useTranslation() const language = useGetLanguage() const { letters, groups: groupedTools } = groupItems(tools, tool => tool.label[language][0]) const toolRefs = useRef({}) const renderGroup = useCallback((toolWithProvider: ToolWithProvider) => { const list = toolWithProvider.tools return (
{toolWithProvider.label[language]}
{ list.map(tool => ( )) }
) }, [onSelect, language]) const renderLetterGroup = (letter) => { const tools = groupedTools[letter] return (
(toolRefs.current[letter] = el)} > {tools.map(renderGroup)}
) } return (
{ !tools.length && !showWorkflowEmpty && (
{t('workflow.tabs.noResult')}
) } {!tools.length && showWorkflowEmpty && (
)} {!!tools.length && letters.map(renderLetterGroup)} {tools.length > 10 && }
) } export default memo(Blocks)