|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
memo, |
|
|
memo, |
|
|
useCallback, |
|
|
useCallback, |
|
|
|
|
|
useRef, |
|
|
} from 'react' |
|
|
} from 'react' |
|
|
import { useTranslation } from 'react-i18next' |
|
|
import { useTranslation } from 'react-i18next' |
|
|
import BlockIcon from '../block-icon' |
|
|
import BlockIcon from '../block-icon' |
|
|
import { BlockEnum } from '../types' |
|
|
import { BlockEnum } from '../types' |
|
|
import type { ToolWithProvider } from '../types' |
|
|
import type { ToolWithProvider } from '../types' |
|
|
|
|
|
import IndexBar, { groupItems } from './index-bar' |
|
|
import type { ToolDefaultValue } from './types' |
|
|
import type { ToolDefaultValue } from './types' |
|
|
import Tooltip from '@/app/components/base/tooltip' |
|
|
import Tooltip from '@/app/components/base/tooltip' |
|
|
import Empty from '@/app/components/tools/add-tool-modal/empty' |
|
|
import Empty from '@/app/components/tools/add-tool-modal/empty' |
|
|
|
|
|
|
|
|
const { t } = useTranslation() |
|
|
const { t } = useTranslation() |
|
|
const language = useGetLanguage() |
|
|
const language = useGetLanguage() |
|
|
|
|
|
|
|
|
|
|
|
const { letters, groups: groupedTools } = groupItems(tools, tool => tool.label[language][0]) |
|
|
|
|
|
const toolRefs = useRef({}) |
|
|
|
|
|
|
|
|
const renderGroup = useCallback((toolWithProvider: ToolWithProvider) => { |
|
|
const renderGroup = useCallback((toolWithProvider: ToolWithProvider) => { |
|
|
const list = toolWithProvider.tools |
|
|
const list = toolWithProvider.tools |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) |
|
|
) |
|
|
}, [onSelect, language]) |
|
|
}, [onSelect, language]) |
|
|
|
|
|
|
|
|
|
|
|
const renderLetterGroup = (letter) => { |
|
|
|
|
|
const tools = groupedTools[letter] |
|
|
|
|
|
return ( |
|
|
|
|
|
<div |
|
|
|
|
|
key={letter} |
|
|
|
|
|
ref={el => (toolRefs.current[letter] = el)} |
|
|
|
|
|
> |
|
|
|
|
|
{tools.map(renderGroup)} |
|
|
|
|
|
</div> |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div className='p-1 max-w-[320px] max-h-[464px] overflow-y-auto'> |
|
|
<div className='p-1 max-w-[320px] max-h-[464px] overflow-y-auto'> |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
{!tools.length && showWorkflowEmpty && ( |
|
|
{!tools.length && showWorkflowEmpty && ( |
|
|
<div className='py-10'> |
|
|
<div className='py-10'> |
|
|
<Empty/> |
|
|
|
|
|
|
|
|
<Empty /> |
|
|
</div> |
|
|
</div> |
|
|
)} |
|
|
)} |
|
|
{ |
|
|
|
|
|
!!tools.length && tools.map(renderGroup) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
{!!tools.length && letters.map(renderLetterGroup)} |
|
|
|
|
|
{tools.length > 10 && <IndexBar letters={letters} itemRefs={toolRefs} />} |
|
|
</div> |
|
|
</div> |
|
|
) |
|
|
) |
|
|
} |
|
|
} |