mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 10:28:10 +08:00
feat: support scroll into letter
This commit is contained in:
@ -6,31 +6,53 @@ import type { BlockEnum } from '../../../types'
|
||||
import type { ToolDefaultValue } from '../../types'
|
||||
import Tool from '../tool'
|
||||
import { ViewType } from '../../view-type-select'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
type Props = {
|
||||
payload: ToolWithProvider[]
|
||||
isShowLetterIndex: boolean
|
||||
hasSearchText: boolean
|
||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||
letters: string[]
|
||||
toolRefs: any
|
||||
}
|
||||
|
||||
const ToolViewFlatView: FC<Props> = ({
|
||||
letters,
|
||||
payload,
|
||||
isShowLetterIndex,
|
||||
hasSearchText,
|
||||
onSelect,
|
||||
toolRefs,
|
||||
}) => {
|
||||
const firstLetterToolIds = useMemo(() => {
|
||||
const res: Record<string, string> = {}
|
||||
letters.forEach((letter) => {
|
||||
const firstToolId = payload.find(tool => tool.letter === letter)?.id
|
||||
if (firstToolId)
|
||||
res[firstToolId] = letter
|
||||
})
|
||||
return res
|
||||
}, [payload, letters])
|
||||
return (
|
||||
<div>
|
||||
{payload.map(tool => (
|
||||
<Tool
|
||||
<div
|
||||
key={tool.id}
|
||||
payload={tool}
|
||||
viewType={ViewType.flat}
|
||||
isShowLetterIndex={isShowLetterIndex}
|
||||
hasSearchText={hasSearchText}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
ref={(el) => {
|
||||
const letter = firstLetterToolIds[tool.id]
|
||||
if (letter)
|
||||
toolRefs.current[letter] = el
|
||||
}}
|
||||
>
|
||||
<Tool
|
||||
payload={tool}
|
||||
viewType={ViewType.flat}
|
||||
isShowLetterIndex={isShowLetterIndex}
|
||||
hasSearchText={hasSearchText}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user