mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 14:51:39 +08:00
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import type { DatasetDetailWithPartialMembersResponse } from '@dify/contracts/api/console/datasets/types.gen'
|
|
import type { FC } from 'react'
|
|
import type { KnowledgeRetrievalNodeType } from './types'
|
|
import type { NodeProps } from '@/app/components/workflow/types'
|
|
import * as React from 'react'
|
|
import { useEffect, useState } from 'react'
|
|
import AppIcon from '@/app/components/base/app-icon'
|
|
import { useDatasetsDetailStore } from '../../datasets-detail-store/store'
|
|
|
|
const Node: FC<NodeProps<KnowledgeRetrievalNodeType>> = ({ data }) => {
|
|
const [selectedDatasets, setSelectedDatasets] = useState<
|
|
DatasetDetailWithPartialMembersResponse[]
|
|
>([])
|
|
const datasetsDetail = useDatasetsDetailStore((s) => s.datasetsDetail)
|
|
|
|
useEffect(() => {
|
|
if (data.dataset_ids?.length > 0) {
|
|
const dataSetsWithDetail = data.dataset_ids.reduce<DatasetDetailWithPartialMembersResponse[]>(
|
|
(acc, id) => {
|
|
if (datasetsDetail[id]) acc.push(datasetsDetail[id])
|
|
return acc
|
|
},
|
|
[],
|
|
)
|
|
setSelectedDatasets(dataSetsWithDetail)
|
|
} else {
|
|
setSelectedDatasets([])
|
|
}
|
|
}, [data.dataset_ids, datasetsDetail])
|
|
|
|
if (!selectedDatasets.length) return null
|
|
|
|
return (
|
|
<div className="mb-1 px-3 py-1">
|
|
<div className="space-y-0.5">
|
|
{selectedDatasets.map(({ id, name, icon_info }) => {
|
|
const iconInfo = icon_info || {
|
|
icon: '📙',
|
|
icon_type: 'emoji' as const,
|
|
icon_background: '#FFF4ED',
|
|
icon_url: '',
|
|
}
|
|
return (
|
|
<div
|
|
key={id}
|
|
className="flex h-6.5 items-center gap-x-1 rounded-md bg-workflow-block-parma-bg px-1"
|
|
>
|
|
<AppIcon size="xs" className="shrink-0" icon={iconInfo} />
|
|
<div className="w-0 grow truncate system-xs-regular text-text-secondary">{name}</div>
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(Node)
|