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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useEffect,
  5. useState,
  6. } from 'react'
  7. import {
  8. Background,
  9. useNodesInitialized,
  10. useViewport,
  11. } from 'reactflow'
  12. import { useTranslation } from 'react-i18next'
  13. import { IterationStartNodeDumb } from '../iteration-start'
  14. import { useNodeIterationInteractions } from './use-interactions'
  15. import type { IterationNodeType } from './types'
  16. import AddBlock from './add-block'
  17. import cn from '@/utils/classnames'
  18. import type { NodeProps } from '@/app/components/workflow/types'
  19. import Toast from '@/app/components/base/toast'
  20. const i18nPrefix = 'workflow.nodes.iteration'
  21. const Node: FC<NodeProps<IterationNodeType>> = ({
  22. id,
  23. data,
  24. }) => {
  25. const { zoom } = useViewport()
  26. const nodesInitialized = useNodesInitialized()
  27. const { handleNodeIterationRerender } = useNodeIterationInteractions()
  28. const { t } = useTranslation()
  29. const [showTips, setShowTips] = useState(data._isShowTips)
  30. useEffect(() => {
  31. if (nodesInitialized)
  32. handleNodeIterationRerender(id)
  33. if (data.is_parallel && showTips) {
  34. Toast.notify({
  35. type: 'warning',
  36. message: t(`${i18nPrefix}.answerNodeWarningDesc`),
  37. duration: 5000,
  38. })
  39. setShowTips(false)
  40. }
  41. }, [nodesInitialized, id, handleNodeIterationRerender, data.is_parallel, showTips, t])
  42. return (
  43. <div className={cn(
  44. 'relative h-full min-h-[90px] w-full min-w-[240px] rounded-2xl bg-workflow-canvas-workflow-bg',
  45. )}>
  46. <Background
  47. id={`iteration-background-${id}`}
  48. className='!z-0 rounded-2xl'
  49. gap={[14 / zoom, 14 / zoom]}
  50. size={2 / zoom}
  51. color='var(--color-workflow-canvas-workflow-dot-color)'
  52. />
  53. {
  54. data._isCandidate && (
  55. <IterationStartNodeDumb />
  56. )
  57. }
  58. {
  59. data._children!.length === 1 && (
  60. <AddBlock
  61. iterationNodeId={id}
  62. iterationNodeData={data}
  63. />
  64. )
  65. }
  66. </div>
  67. )
  68. }
  69. export default memo(Node)