refactor: update data source handling and replace icon implementation

pull/21398/head
twwu 11 months ago
parent 6bd28cadc4
commit 049a6de4b3

@ -1,11 +1,6 @@
import { useCallback, useEffect } from 'react' import { useCallback, useEffect } from 'react'
import { useDatasourceOptions } from '../hooks' import { useDatasourceOptions } from '../hooks'
import OptionCard from './option-card' import OptionCard from './option-card'
import { File, Watercrawl } from '@/app/components/base/icons/src/public/knowledge'
import { Notion } from '@/app/components/base/icons/src/public/common'
import { Jina } from '@/app/components/base/icons/src/public/llm'
import { DataSourceType } from '@/models/datasets'
import { DataSourceProvider } from '@/models/common'
import type { Datasource } from '../types' import type { Datasource } from '../types'
type DataSourceOptionsProps = { type DataSourceOptionsProps = {
@ -13,17 +8,6 @@ type DataSourceOptionsProps = {
onSelect: (option: Datasource) => void onSelect: (option: Datasource) => void
} }
// TODO: replace all icons with tool icon_url
const DATA_SOURCE_ICONS = {
[DataSourceType.FILE]: File as React.FC<React.SVGProps<SVGSVGElement>>,
[DataSourceType.NOTION]: Notion as React.FC<React.SVGProps<SVGSVGElement>>,
[DataSourceProvider.fireCrawl]: '🔥',
[DataSourceProvider.jinaReader]: Jina as React.FC<React.SVGProps<SVGSVGElement>>,
[DataSourceProvider.waterCrawl]: Watercrawl as React.FC<React.SVGProps<SVGSVGElement>>,
}
type KeyType = keyof typeof DATA_SOURCE_ICONS
const DataSourceOptions = ({ const DataSourceOptions = ({
datasourceNodeId, datasourceNodeId,
onSelect, onSelect,
@ -49,8 +33,8 @@ const DataSourceOptions = ({
<OptionCard <OptionCard
key={option.value} key={option.value}
label={option.label} label={option.label}
nodeData={option.data}
selected={datasourceNodeId === option.value} selected={datasourceNodeId === option.value}
Icon={DATA_SOURCE_ICONS[option.type as KeyType]}
onClick={handelSelect.bind(null, option.value)} onClick={handelSelect.bind(null, option.value)}
/> />
))} ))}

@ -1,19 +1,25 @@
import React from 'react' import React from 'react'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import BlockIcon from '@/app/components/workflow/block-icon'
import { BlockEnum } from '@/app/components/workflow/types'
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import { useToolIcon } from '@/app/components/workflow/hooks'
type OptionCardProps = { type OptionCardProps = {
label: string label: string
Icon: React.FC<React.SVGProps<SVGSVGElement>> | string
selected: boolean selected: boolean
nodeData: DataSourceNodeType
onClick?: () => void onClick?: () => void
} }
const OptionCard = ({ const OptionCard = ({
label, label,
Icon,
selected, selected,
nodeData,
onClick, onClick,
}: OptionCardProps) => { }: OptionCardProps) => {
const toolIcon = useToolIcon(nodeData)
return ( return (
<div <div
className={cn( className={cn(
@ -25,11 +31,10 @@ const OptionCard = ({
onClick={onClick} onClick={onClick}
> >
<div className='flex size-7 items-center justify-center rounded-lg border-[0.5px] border-components-panel-border bg-background-default-dodge p-1'> <div className='flex size-7 items-center justify-center rounded-lg border-[0.5px] border-components-panel-border bg-background-default-dodge p-1'>
{ <BlockIcon
typeof Icon === 'string' type={BlockEnum.DataSource}
? <div className='text-[18px] leading-[18px]'>{Icon}</div> toolIcon={toolIcon}
: <Icon className='size-5' /> />
}
</div> </div>
<div className={cn('system-sm-medium text-text-secondary', selected && 'text-primary')}> <div className={cn('system-sm-medium text-text-secondary', selected && 'text-primary')}>
{label} {label}

@ -32,7 +32,7 @@ export const useDatasourceOptions = () => {
type: node.data.provider_type as DatasourceType, type: node.data.provider_type as DatasourceType,
variables: node.data.variables || [], variables: node.data.variables || [],
description: node.data.desc || '', description: node.data.desc || '',
docTitle: '', // todo: Add docTitle and docLink if needed, or remove these properties if not used docTitle: '', // todo: Add docTitle and docLink
docLink: '', docLink: '',
} }
}) })
@ -41,12 +41,11 @@ export const useDatasourceOptions = () => {
const options = useMemo(() => { const options = useMemo(() => {
const options: DataSourceOption[] = [] const options: DataSourceOption[] = []
datasourceNodes.forEach((node) => { datasourceNodes.forEach((node) => {
const type = node.data.provider_type as DatasourceType
const label = node.data.title const label = node.data.title
options.push({ options.push({
label, label,
value: node.id, value: node.id,
type, data: node.data,
}) })
}) })
return options return options

@ -1,3 +1,4 @@
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import type { DatasourceType, RAGPipelineVariables } from '@/models/pipeline' import type { DatasourceType, RAGPipelineVariables } from '@/models/pipeline'
export enum TestRunStep { export enum TestRunStep {
@ -8,7 +9,7 @@ export enum TestRunStep {
export type DataSourceOption = { export type DataSourceOption = {
label: string label: string
value: string value: string
type: DatasourceType data: DataSourceNodeType
} }
export type Datasource = { export type Datasource = {

@ -7,9 +7,9 @@ import type { Viewport } from 'reactflow'
import type { TransferMethod } from '@/types/app' import type { TransferMethod } from '@/types/app'
export enum DatasourceType { export enum DatasourceType {
localFile = 'local-file', localFile = 'local_file',
onlineDocument = 'online-document', onlineDocument = 'online_document',
websiteCrawl = 'website-crawl', websiteCrawl = 'website_crawl',
} }
export type PipelineTemplateListParams = { export type PipelineTemplateListParams = {

Loading…
Cancel
Save