node.tsx 3.4 KB

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