import type { FC, ReactElement, } from 'react' import { cloneElement, memo, useMemo, } from 'react' import type { NodeProps } from '../../types' import { BlockEnum, NodeRunningStatus, } from '../../types' import { useNodesReadOnly, useToolIcon, } from '../../hooks' import { NodeSourceHandle, NodeTargetHandle, } from './components/node-handle' import NodeControl from './components/node-control' import BlockIcon from '@/app/components/workflow/block-icon' import { CheckCircle, Loading02, } from '@/app/components/base/icons/src/vender/line/general' import { AlertCircle } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback' type BaseNodeProps = { children: ReactElement } & NodeProps const BaseNode: FC = ({ id, data, children, }) => { const { nodesReadOnly } = useNodesReadOnly() const toolIcon = useToolIcon(data) const { showRunningBorder, showSuccessBorder, showFailedBorder, } = useMemo(() => { return { showRunningBorder: data._runningStatus === NodeRunningStatus.Running && !data.selected, showSuccessBorder: data._runningStatus === NodeRunningStatus.Succeeded && !data.selected, showFailedBorder: data._runningStatus === NodeRunningStatus.Failed && !data.selected, } }, [data._runningStatus, data.selected]) return (
{ data.type !== BlockEnum.VariableAssigner && ( ) } { data.type !== BlockEnum.IfElse && data.type !== BlockEnum.QuestionClassifier && ( ) } { !data._runningStatus && !nodesReadOnly && ( ) }
{data.title}
{ (data._runningStatus === NodeRunningStatus.Running || data._singleRunningStatus === NodeRunningStatus.Running) && ( ) } { data._runningStatus === NodeRunningStatus.Succeeded && ( ) } { data._runningStatus === NodeRunningStatus.Failed && ( ) }
{cloneElement(children, { id, data })} { data.desc && (
{data.desc}
) }
) } export default memo(BaseNode)