65 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-05-13 16:01:58 +08:00
import {
2025-05-23 10:46:28 +08:00
useCallback,
2025-05-13 16:01:58 +08:00
useRef,
} from 'react'
2025-05-23 10:46:28 +08:00
import { BlockEnum } from '../types'
2025-05-13 16:01:58 +08:00
import type {
OnSelectBlock,
ToolWithProvider,
} from '../types'
2025-05-23 16:27:19 +08:00
import type { ToolDefaultValue } from './types'
2025-05-13 16:01:58 +08:00
import Tools from './tools'
import { ViewType } from './view-type-select'
import cn from '@/utils/classnames'
import type { ListRef } from '@/app/components/workflow/block-selector/market-place-plugin/list'
type AllToolsProps = {
className?: string
toolContentClassName?: string
searchText: string
onSelect: OnSelectBlock
dataSources: ToolWithProvider[]
}
const DataSources = ({
className,
toolContentClassName,
searchText,
onSelect,
dataSources,
}: AllToolsProps) => {
const pluginRef = useRef<ListRef>(null)
const wrapElemRef = useRef<HTMLDivElement>(null)
2025-05-23 16:27:19 +08:00
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
onSelect(BlockEnum.DataSource, toolDefaultValue && {
2025-06-05 16:51:01 +08:00
plugin_id: toolDefaultValue?.provider_id,
2025-05-23 16:27:19 +08:00
provider_type: toolDefaultValue?.provider_type,
provider_name: toolDefaultValue?.provider_name,
datasource_name: toolDefaultValue?.tool_name,
datasource_label: toolDefaultValue?.tool_label,
2025-05-23 18:19:01 +08:00
title: toolDefaultValue?.title,
2025-05-23 16:27:19 +08:00
})
2025-05-23 10:46:28 +08:00
}, [onSelect])
2025-05-13 16:01:58 +08:00
return (
<div className={cn(className)}>
<div
ref={wrapElemRef}
className='max-h-[464px] overflow-y-auto'
onScroll={pluginRef.current?.handleScroll}
>
<Tools
className={toolContentClassName}
showWorkflowEmpty={false}
2025-05-26 14:13:28 +08:00
tools={dataSources}
2025-05-23 16:27:19 +08:00
onSelect={handleSelect as OnSelectBlock}
2025-05-13 16:01:58 +08:00
viewType={ViewType.flat}
hasSearchText={!!searchText}
/>
</div>
</div>
)
}
export default DataSources