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.

node-variable-item.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {
  2. memo,
  3. useMemo,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import cn from '@/utils/classnames'
  7. import { VarBlockIcon } from '@/app/components/workflow/block-icon'
  8. import { Line3 } from '@/app/components/base/icons/src/public/common'
  9. import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
  10. import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others'
  11. import Badge from '@/app/components/base/badge'
  12. import type { Node } from '@/app/components/workflow/types'
  13. type NodeVariableItemProps = {
  14. isEnv: boolean
  15. isChatVar: boolean
  16. node: Node
  17. varName: string
  18. writeMode?: string
  19. showBorder?: boolean
  20. className?: string
  21. isException?: boolean
  22. }
  23. const i18nPrefix = 'workflow.nodes.assigner'
  24. const NodeVariableItem = ({
  25. isEnv,
  26. isChatVar,
  27. node,
  28. varName,
  29. writeMode,
  30. showBorder,
  31. className,
  32. isException,
  33. }: NodeVariableItemProps) => {
  34. const { t } = useTranslation()
  35. const VariableIcon = useMemo(() => {
  36. if (isEnv) {
  37. return (
  38. <Env className='h-3.5 w-3.5 shrink-0 text-util-colors-violet-violet-600' />
  39. )
  40. }
  41. if (isChatVar) {
  42. return (
  43. <BubbleX className='h-3.5 w-3.5 shrink-0 text-util-colors-teal-teal-700' />
  44. )
  45. }
  46. return (
  47. <Variable02
  48. className={cn(
  49. 'h-3.5 w-3.5 shrink-0 text-text-accent',
  50. isException && 'text-text-warning',
  51. )}
  52. />
  53. )
  54. }, [isEnv, isChatVar, isException])
  55. const VariableName = useMemo(() => {
  56. return (
  57. <div
  58. className={cn(
  59. 'system-xs-medium ml-0.5 shrink truncate text-text-accent',
  60. isEnv && 'text-text-primary',
  61. isException && 'text-text-warning',
  62. isChatVar && 'text-util-colors-teal-teal-700',
  63. )}
  64. title={varName}
  65. >
  66. {varName}
  67. </div>
  68. )
  69. }, [isEnv, isChatVar, varName, isException])
  70. return (
  71. <div className={cn(
  72. 'relative flex items-center gap-1 self-stretch rounded-md bg-workflow-block-parma-bg p-[3px] pl-[5px]',
  73. showBorder && '!bg-state-base-hover',
  74. className,
  75. )}>
  76. <div className='flex w-0 grow items-center'>
  77. {
  78. node && (
  79. <>
  80. <div className='shrink-0 p-[1px]'>
  81. <VarBlockIcon
  82. className='!text-text-primary'
  83. type={node.data.type}
  84. />
  85. </div>
  86. <div
  87. className='mx-0.5 shrink-[1000] truncate text-xs font-medium text-text-secondary'
  88. title={node?.data.title}
  89. >
  90. {node?.data.title}
  91. </div>
  92. <Line3 className='mr-0.5 shrink-0'></Line3>
  93. </>
  94. )
  95. }
  96. {VariableIcon}
  97. {VariableName}
  98. </div>
  99. {writeMode && <Badge className='shrink-0' text={t(`${i18nPrefix}.operations.${writeMode}`)} />}
  100. </div>
  101. )
  102. }
  103. export default memo(NodeVariableItem)