84 lines
2.6 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-07-22 16:48:24 +08:00
import Link from 'next/link'
import { useTranslation } from 'react-i18next'
import { RiArrowRightUpLine } from '@remixicon/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'
2025-07-22 16:48:24 +08:00
import { getMarketplaceUrl } from '@/utils/var'
import { useGlobalPublicStore } from '@/context/global-public-context'
2025-05-13 16:01:58 +08:00
type AllToolsProps = {
className?: string
toolContentClassName?: string
searchText: string
onSelect: OnSelectBlock
dataSources: ToolWithProvider[]
}
const DataSources = ({
className,
toolContentClassName,
searchText,
onSelect,
dataSources,
}: AllToolsProps) => {
2025-07-22 16:48:24 +08:00
const { t } = useTranslation()
2025-05-13 16:01:58 +08:00
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-07-22 16:48:24 +08:00
const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures)
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}
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}
canNotSelectMultiple
2025-05-13 16:01:58 +08:00
/>
2025-07-22 16:48:24 +08:00
{
enable_marketplace && (
<Link
className='system-sm-medium sticky bottom-0 z-10 flex h-8 cursor-pointer items-center rounded-b-lg border-[0.5px] border-t border-components-panel-border bg-components-panel-bg-blur px-4 py-1 text-text-accent-light-mode-only shadow-lg'
href={getMarketplaceUrl('')}
target='_blank'
>
<span>{t('plugin.findMoreInMarketplace')}</span>
<RiArrowRightUpLine className='ml-0.5 h-3 w-3' />
</Link>
)
}
2025-05-13 16:01:58 +08:00
</div>
</div>
)
}
export default DataSources