You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hooks.tsx 1.1KB

1234567891011121314151617181920212223
  1. import { useMemo } from 'react'
  2. import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
  3. import { basePath } from '@/utils/var'
  4. import { useDataSourceList } from '@/service/use-pipeline'
  5. import { transformDataSourceToTool } from '@/app/components/workflow/block-selector/utils'
  6. export const useDatasourceIcon = (data: DataSourceNodeType) => {
  7. const { data: dataSourceListData, isSuccess } = useDataSourceList(true)
  8. const datasourceIcon = useMemo(() => {
  9. if (!isSuccess) return
  10. const dataSourceList = [...(dataSourceListData || [])]
  11. dataSourceList.forEach((item) => {
  12. const icon = item.declaration.identity.icon
  13. if (typeof icon == 'string' && !icon.includes(basePath))
  14. item.declaration.identity.icon = `${basePath}${icon}`
  15. })
  16. const formattedDataSourceList = dataSourceList.map(item => transformDataSourceToTool(item))
  17. return formattedDataSourceList?.find(toolWithProvider => toolWithProvider.plugin_id === data.plugin_id)?.icon
  18. }, [data.plugin_id, dataSourceListData, isSuccess])
  19. return datasourceIcon
  20. }