import { type FC, useEffect, useRef, useState } from 'react' import React from 'react' import type { KnowledgeRetrievalNodeType } from './types' import { Folder } from '@/app/components/base/icons/src/vender/solid/files' import type { NodeProps } from '@/app/components/workflow/types' import { fetchDatasets } from '@/service/datasets' import type { DataSet } from '@/models/datasets' const Node: FC> = ({ data, }) => { const [selectedDatasets, setSelectedDatasets] = useState([]) const updateTime = useRef(0) useEffect(() => { (async () => { updateTime.current = updateTime.current + 1 const currUpdateTime = updateTime.current if (data.dataset_ids?.length > 0) { const { data: dataSetsWithDetail } = await fetchDatasets({ url: '/datasets', params: { page: 1, ids: data.dataset_ids } }) // avoid old data overwrite new data if (currUpdateTime < updateTime.current) return setSelectedDatasets(dataSetsWithDetail) } else { setSelectedDatasets([]) } })() }, [data.dataset_ids]) if (!selectedDatasets.length) return null return (
{selectedDatasets.map(({ id, name }) => (
{name}
))}
) } export default React.memo(Node)