node-variable-item.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { memo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import cn from '@/utils/classnames'
  4. import { VarBlockIcon } from '@/app/components/workflow/block-icon'
  5. import { Line3 } from '@/app/components/base/icons/src/public/common'
  6. import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
  7. import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others'
  8. import Badge from '@/app/components/base/badge'
  9. import type { Node } from '@/app/components/workflow/types'
  10. import { BlockEnum } from '@/app/components/workflow/types'
  11. type NodeVariableItemProps = {
  12. isEnv: boolean
  13. isChatVar: boolean
  14. node: Node
  15. varName: string
  16. writeMode?: string
  17. showBorder?: boolean
  18. className?: string
  19. isException?: boolean
  20. }
  21. const i18nPrefix = 'workflow.nodes.assigner'
  22. const NodeVariableItem = ({
  23. isEnv,
  24. isChatVar,
  25. node,
  26. varName,
  27. writeMode,
  28. showBorder,
  29. className,
  30. isException,
  31. }: NodeVariableItemProps) => {
  32. const { t } = useTranslation()
  33. return (
  34. <div className={cn(
  35. 'relative flex items-center p-[3px] pl-[5px] gap-1 self-stretch rounded-md bg-workflow-block-parma-bg',
  36. showBorder && '!bg-black/[0.02]',
  37. className,
  38. )}>
  39. {!isEnv && !isChatVar && (
  40. <div className='flex items-center'>
  41. <div className='p-[1px]'>
  42. <VarBlockIcon
  43. className='!text-gray-900'
  44. type={node?.data.type || BlockEnum.Start}
  45. />
  46. </div>
  47. <div className='max-w-[85px] truncate mx-0.5 text-xs font-medium text-gray-700' title={node?.data.title}>{node?.data.title}</div>
  48. <Line3 className='mr-0.5'></Line3>
  49. </div>
  50. )}
  51. <div className='flex items-center text-primary-600 w-full'>
  52. {!isEnv && !isChatVar && <Variable02 className={cn('shrink-0 w-3.5 h-3.5 text-primary-500', isException && 'text-text-warning')} />}
  53. {isEnv && <Env className='shrink-0 w-3.5 h-3.5 text-util-colors-violet-violet-600' />}
  54. {!isChatVar && <div className={cn('max-w-[75px] truncate ml-0.5 system-xs-medium overflow-hidden text-ellipsis', isEnv && 'text-gray-900', isException && 'text-text-warning')} title={varName}>{varName}</div>}
  55. {isChatVar
  56. && <div className='flex items-center w-full gap-1'>
  57. <div className='flex h-[18px] min-w-[18px] items-center gap-0.5 flex-1'>
  58. <BubbleX className='w-3.5 h-3.5 text-util-colors-teal-teal-700' />
  59. <div className={cn('max-w-[75px] truncate ml-0.5 system-xs-medium overflow-hidden text-ellipsis text-util-colors-teal-teal-700')}>{varName}</div>
  60. </div>
  61. {writeMode && <Badge className='shrink-0' text={t(`${i18nPrefix}.operations.${writeMode}`)} />}
  62. </div>
  63. }
  64. </div>
  65. </div>
  66. )
  67. }
  68. export default memo(NodeVariableItem)