mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 09:58:04 +08:00
datasource
This commit is contained in:
@ -7,6 +7,7 @@ import type {
|
||||
OnSelectBlock,
|
||||
ToolWithProvider,
|
||||
} from '../types'
|
||||
import type { ToolDefaultValue } from './types'
|
||||
import Tools from './tools'
|
||||
import { ViewType } from './view-type-select'
|
||||
import cn from '@/utils/classnames'
|
||||
@ -30,8 +31,14 @@ const DataSources = ({
|
||||
const pluginRef = useRef<ListRef>(null)
|
||||
const wrapElemRef = useRef<HTMLDivElement>(null)
|
||||
const formatedDataSources = dataSources.map(item => ({ ...item, tools: item.datasources || [] }))
|
||||
const handleSelect = useCallback<OnSelectBlock>((_, toolDefaultValue) => {
|
||||
onSelect(BlockEnum.DataSource, toolDefaultValue)
|
||||
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
|
||||
onSelect(BlockEnum.DataSource, toolDefaultValue && {
|
||||
provider_id: toolDefaultValue?.provider_id,
|
||||
provider_type: toolDefaultValue?.provider_type,
|
||||
provider_name: toolDefaultValue?.provider_name,
|
||||
datasource_name: toolDefaultValue?.tool_name,
|
||||
datasource_label: toolDefaultValue?.tool_label,
|
||||
})
|
||||
}, [onSelect])
|
||||
|
||||
return (
|
||||
@ -45,7 +52,7 @@ const DataSources = ({
|
||||
className={toolContentClassName}
|
||||
showWorkflowEmpty={false}
|
||||
tools={formatedDataSources}
|
||||
onSelect={handleSelect}
|
||||
onSelect={handleSelect as OnSelectBlock}
|
||||
viewType={ViewType.flat}
|
||||
hasSearchText={!!searchText}
|
||||
/>
|
||||
|
||||
@ -4,9 +4,9 @@ import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools } from '@/se
|
||||
import type {
|
||||
BlockEnum,
|
||||
NodeDefault,
|
||||
OnSelectBlock,
|
||||
ToolWithProvider,
|
||||
} from '../types'
|
||||
import type { ToolDefaultValue } from './types'
|
||||
import { TabsEnum } from './types'
|
||||
import Blocks from './blocks'
|
||||
import AllTools from './all-tools'
|
||||
@ -16,7 +16,7 @@ export type TabsProps = {
|
||||
activeTab: TabsEnum
|
||||
searchText: string
|
||||
tags: string[]
|
||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||
onSelect: OnSelectBlock
|
||||
availableBlocksTypes?: BlockEnum[]
|
||||
blocks: NodeDefault[]
|
||||
dataSources?: ToolWithProvider[]
|
||||
|
||||
@ -33,6 +33,14 @@ export type ToolDefaultValue = {
|
||||
output_schema: Record<string, any>
|
||||
}
|
||||
|
||||
export type DataSourceDefaultValue = {
|
||||
provider_id: string
|
||||
provider_type: string
|
||||
provider_name: string
|
||||
datasource_name: string
|
||||
datasource_label: string
|
||||
}
|
||||
|
||||
export type ToolValue = {
|
||||
provider_name: string
|
||||
tool_name: string
|
||||
|
||||
Reference in New Issue
Block a user