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.

index.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import type {
  2. FC,
  3. } from 'react'
  4. import {
  5. memo,
  6. useMemo,
  7. } from 'react'
  8. import {
  9. RiAlertFill,
  10. RiCheckboxCircleFill,
  11. RiErrorWarningFill,
  12. RiLoader2Line,
  13. } from '@remixicon/react'
  14. import {
  15. NodeTargetHandle,
  16. } from '@/app/components/workflow/nodes/_base/components/node-handle'
  17. import NodeControl from '@/app/components/workflow/nodes/_base/components/node-control'
  18. import cn from '@/utils/classnames'
  19. import BlockIcon from '@/app/components/workflow/block-icon'
  20. import type {
  21. NodeProps,
  22. } from '@/app/components/workflow/types'
  23. import {
  24. NodeRunningStatus,
  25. } from '@/app/components/workflow/types'
  26. import {
  27. useNodesReadOnly,
  28. } from '@/app/components/workflow/hooks'
  29. type SimpleNodeProps = NodeProps
  30. const SimpleNode: FC<SimpleNodeProps> = ({
  31. id,
  32. data,
  33. }) => {
  34. const { nodesReadOnly } = useNodesReadOnly()
  35. const showSelectedBorder = data.selected || data._isBundled || data._isEntering
  36. const {
  37. showRunningBorder,
  38. showSuccessBorder,
  39. showFailedBorder,
  40. showExceptionBorder,
  41. } = useMemo(() => {
  42. return {
  43. showRunningBorder: data._runningStatus === NodeRunningStatus.Running && !showSelectedBorder,
  44. showSuccessBorder: data._runningStatus === NodeRunningStatus.Succeeded && !showSelectedBorder,
  45. showFailedBorder: data._runningStatus === NodeRunningStatus.Failed && !showSelectedBorder,
  46. showExceptionBorder: data._runningStatus === NodeRunningStatus.Exception && !showSelectedBorder,
  47. }
  48. }, [data._runningStatus, showSelectedBorder])
  49. return (
  50. <div
  51. className={cn(
  52. 'flex rounded-2xl border-[2px]',
  53. showSelectedBorder ? 'border-components-option-card-option-selected-border' : 'border-transparent',
  54. data._waitingRun && 'opacity-70',
  55. )}
  56. style={{
  57. width: 'auto',
  58. height: 'auto',
  59. }}
  60. >
  61. <div
  62. className={cn(
  63. 'group relative pb-1 shadow-xs',
  64. 'rounded-[15px] border border-transparent',
  65. 'w-[240px] bg-workflow-block-bg',
  66. !data._runningStatus && 'hover:shadow-lg',
  67. showRunningBorder && '!border-state-accent-solid',
  68. showSuccessBorder && '!border-state-success-solid',
  69. showFailedBorder && '!border-state-destructive-solid',
  70. showExceptionBorder && '!border-state-warning-solid',
  71. data._isBundled && '!shadow-lg',
  72. )}
  73. >
  74. {
  75. !data._isCandidate && (
  76. <NodeTargetHandle
  77. id={id}
  78. data={data}
  79. handleClassName='!top-4 !-left-[9px] !translate-y-0'
  80. handleId='target'
  81. />
  82. )
  83. }
  84. {
  85. !data._runningStatus && !nodesReadOnly && !data._isCandidate && (
  86. <NodeControl
  87. id={id}
  88. data={data}
  89. />
  90. )
  91. }
  92. <div className={cn(
  93. 'flex items-center rounded-t-2xl px-3 pb-2 pt-3',
  94. )}>
  95. <BlockIcon
  96. className='mr-2 shrink-0'
  97. type={data.type}
  98. size='md'
  99. />
  100. <div
  101. title={data.title}
  102. className='system-sm-semibold-uppercase mr-1 flex grow items-center truncate text-text-primary'
  103. >
  104. <div>
  105. {data.title}
  106. </div>
  107. </div>
  108. {
  109. (data._runningStatus === NodeRunningStatus.Running || data._singleRunningStatus === NodeRunningStatus.Running) && (
  110. <RiLoader2Line className='h-3.5 w-3.5 animate-spin text-text-accent' />
  111. )
  112. }
  113. {
  114. data._runningStatus === NodeRunningStatus.Succeeded && (
  115. <RiCheckboxCircleFill className='h-3.5 w-3.5 text-text-success' />
  116. )
  117. }
  118. {
  119. data._runningStatus === NodeRunningStatus.Failed && (
  120. <RiErrorWarningFill className='h-3.5 w-3.5 text-text-destructive' />
  121. )
  122. }
  123. {
  124. data._runningStatus === NodeRunningStatus.Exception && (
  125. <RiAlertFill className='h-3.5 w-3.5 text-text-warning-secondary' />
  126. )
  127. }
  128. </div>
  129. </div>
  130. </div>
  131. )
  132. }
  133. export default memo(SimpleNode)