Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.8 KB
Raw Blame
import type { FC } from 'react'
import type { IterationNodeType } from './types'
import type { NodeProps } from '@/app/components/workflow/types'
import { cn } from '@langgenius/dify-ui/cn'
import { memo, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Background, useNodesInitialized, useViewport } from 'reactflow'
import { toast } from '@/app/notifications'
import { IterationStartNodeDumb } from '../iteration-start'
import AddBlock from './add-block'
import { useNodeIterationInteractions } from './use-interactions'

const i18nPrefix = 'nodes.iteration'

const Node: FC<NodeProps<IterationNodeType>> = ({ id, data }) => {
  const { zoom } = useViewport()
  const nodesInitialized = useNodesInitialized()
  const { handleNodeIterationRerender } = useNodeIterationInteractions()
  const { t } = useTranslation(['workflow', 'workflowLogic'])
  const [showTips, setShowTips] = useState(data._isShowTips)

  useEffect(() => {
    if (nodesInitialized) handleNodeIterationRerender(id)
    if (data.is_parallel && showTips) {
      toast.warning(t(($) => $[`${i18nPrefix}.answerNodeWarningDesc`], { ns: 'workflowLogic' }))
      setShowTips(false)
    }
  }, [nodesInitialized, id, handleNodeIterationRerender, data.is_parallel, showTips, t])

  return (
    <div
      className={cn(
        'relative h-full min-h-22.5 w-full min-w-60 rounded-2xl bg-workflow-canvas-workflow-bg',
      )}
    >
      <Background
        id={`iteration-background-${id}`}
        className="z-0! rounded-2xl"
        gap={[14 / zoom, 14 / zoom]}
        size={2 / zoom}
        color="var(--color-workflow-canvas-workflow-dot-color)"
      />
      {data._isCandidate && <IterationStartNodeDumb />}
      {data._children?.length === 1 && <AddBlock iterationNodeId={id} iterationNodeData={data} />}
    </div>
  )
}

export default memo(Node)