2025-07-02 13:48:11 +08:00
|
|
|
import { useMemo } from 'react'
|
2025-05-27 14:17:55 +08:00
|
|
|
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
|
|
|
|
import { basePath } from '@/utils/var'
|
|
|
|
import { useDataSourceList } from '@/service/use-pipeline'
|
|
|
|
import { transformDataSourceToTool } from '@/app/components/workflow/block-selector/utils'
|
|
|
|
|
|
|
|
export const useDatasourceIcon = (data: DataSourceNodeType) => {
|
2025-07-02 13:48:11 +08:00
|
|
|
const { data: dataSourceListData, isSuccess } = useDataSourceList(true)
|
2025-05-27 14:17:55 +08:00
|
|
|
|
2025-07-02 13:48:11 +08:00
|
|
|
const datasourceIcon = useMemo(() => {
|
|
|
|
if (!isSuccess) return
|
|
|
|
const dataSourceList = [...(dataSourceListData || [])]
|
2025-05-27 14:17:55 +08:00
|
|
|
dataSourceList.forEach((item) => {
|
|
|
|
const icon = item.declaration.identity.icon
|
|
|
|
if (typeof icon == 'string' && !icon.includes(basePath))
|
|
|
|
item.declaration.identity.icon = `${basePath}${icon}`
|
|
|
|
})
|
|
|
|
const formattedDataSourceList = dataSourceList.map(item => transformDataSourceToTool(item))
|
2025-07-02 13:48:11 +08:00
|
|
|
return formattedDataSourceList?.find(toolWithProvider => toolWithProvider.plugin_id === data.plugin_id)?.icon
|
|
|
|
}, [data.plugin_id, dataSourceListData, isSuccess])
|
2025-05-27 14:17:55 +08:00
|
|
|
|
|
|
|
return datasourceIcon
|
|
|
|
}
|