Files
dify/web/app/components/workflow/block-selector/index-bar.tsx
FFXN 0e320290e1 feat: evaluation (#35353)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: jyong <718720800@qq.com>
Co-authored-by: Yansong Zhang <916125788@qq.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: hj24 <mambahj24@gmail.com>
Co-authored-by: hj24 <huangjian@dify.ai>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: 非法操作 <hjlarry@163.com>
Co-authored-by: Ayush Baluni <73417844+aayushbaluni@users.noreply.github.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: jimcody1995 <jjimcody@gmail.com>
Co-authored-by: James <63717587+jamesrayammons@users.noreply.github.com>
Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai>
Co-authored-by: Stephen Zhou <hi@hyoban.cc>
Co-authored-by: Coding On Star <447357187@qq.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jerryzai <jerryzh8710@protonmail.com>
Co-authored-by: NVIDIAN <speedy.hpc@hotmail.com>
Co-authored-by: ai-hpc <ai-hpc@users.noreply.github.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: Junghwan <70629228+shaun0927@users.noreply.github.com>
Co-authored-by: HeYinKazune <70251095+HeYin-OS@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Jingyi <jingyi.qi@dify.ai>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: sxxtony <166789813+sxxtony@users.noreply.github.com>
2026-04-17 16:37:21 +08:00

101 lines
3.0 KiB
TypeScript

import type { FC, RefObject } from 'react'
import type { ToolWithProvider } from '../types'
import { cn } from '@langgenius/dify-ui/cn'
import { pinyin } from 'pinyin-pro'
import { CollectionType } from '../../tools/types'
export const CUSTOM_GROUP_NAME = '@@@custom@@@'
export const WORKFLOW_GROUP_NAME = '@@@workflow@@@'
export const DATA_SOURCE_GROUP_NAME = '@@@data_source@@@'
export const AGENT_GROUP_NAME = '@@@agent@@@'
/*
{
A: {
'google': [ // plugin organize name
...tools
],
'custom': [ // custom tools
...tools
],
'workflow': [ // workflow as tools
...tools
]
}
}
*/
export const groupItems = (items: ToolWithProvider[], getFirstChar: (item: ToolWithProvider) => string) => {
const groups = items.reduce((acc: Record<string, Record<string, ToolWithProvider[]>>, item) => {
const firstChar = getFirstChar(item)
if (!firstChar || firstChar.length === 0)
return acc
let letter
// transform Chinese to pinyin
if (/[\u4E00-\u9FA5]/.test(firstChar))
letter = pinyin(firstChar, { pattern: 'first', toneType: 'none' })[0]!.toUpperCase()
else
letter = firstChar.toUpperCase()
if (!/[A-Z]/.test(letter))
letter = '#'
if (!acc[letter])
acc[letter] = {}
let groupName: string = ''
if (item.type === CollectionType.builtIn)
groupName = item.author
else if (item.type === CollectionType.custom)
groupName = CUSTOM_GROUP_NAME
else if (item.type === CollectionType.workflow)
groupName = WORKFLOW_GROUP_NAME
else if (item.type === CollectionType.datasource)
groupName = DATA_SOURCE_GROUP_NAME
else
groupName = AGENT_GROUP_NAME
if (!acc[letter]![groupName])
acc[letter]![groupName] = []
acc[letter]![groupName]!.push(item)
return acc
}, {})
const letters = Object.keys(groups).sort()
// move '#' to the end
const hashIndex = letters.indexOf('#')
if (hashIndex !== -1) {
letters.splice(hashIndex, 1)
letters.push('#')
}
return { letters, groups }
}
type IndexBarProps = {
letters: string[]
itemRefs: RefObject<{ [key: string]: HTMLElement | null }>
className?: string
}
const IndexBar: FC<IndexBarProps> = ({ letters, itemRefs, className }) => {
const handleIndexClick = (letter: string) => {
const element = itemRefs.current?.[letter]
if (element)
element.scrollIntoView({ behavior: 'smooth' })
}
return (
<div className={cn('index-bar sticky top-[20px] flex h-full w-6 flex-col items-center justify-center text-xs font-medium text-text-quaternary', className)}>
<div className={cn('absolute top-0 left-0 h-full w-px bg-[linear-gradient(270deg,rgba(255,255,255,0)_0%,rgba(16,24,40,0.08)_30%,rgba(16,24,40,0.08)_50%,rgba(16,24,40,0.08)_70.5%,rgba(255,255,255,0)_100%)]')}></div>
{letters.map(letter => (
<div className="cursor-pointer hover:text-text-secondary" key={letter} onClick={() => handleIndexClick(letter)}>
{letter}
</div>
))}
</div>
)
}
export default IndexBar