node.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import type { EndNodeType } from './types'
  4. import type { NodeProps, Variable } from '@/app/components/workflow/types'
  5. import { getVarType, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils'
  6. import {
  7. useIsChatMode,
  8. useWorkflow,
  9. } from '@/app/components/workflow/hooks'
  10. import { VarBlockIcon } from '@/app/components/workflow/block-icon'
  11. import { Line3 } from '@/app/components/base/icons/src/public/common'
  12. import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
  13. import { BlockEnum } from '@/app/components/workflow/types'
  14. const Node: FC<NodeProps<EndNodeType>> = ({
  15. id,
  16. data,
  17. }) => {
  18. const { getBeforeNodesInSameBranch } = useWorkflow()
  19. const availableNodes = getBeforeNodesInSameBranch(id)
  20. const isChatMode = useIsChatMode()
  21. const startNode = availableNodes.find((node: any) => {
  22. return node.data.type === BlockEnum.Start
  23. })
  24. const getNode = (id: string) => {
  25. return availableNodes.find(node => node.id === id) || startNode
  26. }
  27. const { outputs } = data
  28. const filteredOutputs = (outputs as Variable[]).filter(({ value_selector }) => value_selector.length > 0)
  29. if (!filteredOutputs.length)
  30. return null
  31. return (
  32. <div className='mb-1 px-3 py-1 space-y-0.5'>
  33. {filteredOutputs.map(({ value_selector }, index) => {
  34. const node = getNode(value_selector[0])
  35. const isSystem = isSystemVar(value_selector)
  36. const varName = isSystem ? `sys.${value_selector[value_selector.length - 1]}` : value_selector[value_selector.length - 1]
  37. const varType = getVarType({
  38. valueSelector: value_selector,
  39. availableNodes,
  40. isChatMode,
  41. })
  42. return (
  43. <div key={index} className='flex items-center h-6 justify-between bg-gray-100 rounded-md px-1 space-x-1 text-xs font-normal text-gray-700'>
  44. <div className='flex items-center text-xs font-medium text-gray-500'>
  45. <div className='p-[1px]'>
  46. <VarBlockIcon
  47. className='!text-gray-900'
  48. type={node?.data.type || BlockEnum.Start}
  49. />
  50. </div>
  51. <div className='max-w-[75px] truncate'>{node?.data.title}</div>
  52. <Line3 className='mr-0.5'></Line3>
  53. <div className='flex items-center text-primary-600'>
  54. <Variable02 className='w-3.5 h-3.5' />
  55. <div className='max-w-[50px] ml-0.5 text-xs font-medium truncate'>{varName}</div>
  56. </div>
  57. </div>
  58. <div className='text-xs font-normal text-gray-700'>
  59. <div className='max-w-[42px] ml-0.5 text-xs font-normal text-gray-500 capitalize truncate' title={varType}>{varType}</div>
  60. </div>
  61. </div>
  62. )
  63. })}
  64. </div>
  65. )
  66. }
  67. export default React.memo(Node)