mirror of
https://github.com/langgenius/dify.git
synced 2025-11-08 15:31:02 +00:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: quicksand <quicksandzn@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Hanqing Zhao <sherry9277@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <xh001x@hotmail.com>
139 lines
4.1 KiB
TypeScript
139 lines
4.1 KiB
TypeScript
import type {
|
|
FC,
|
|
} from 'react'
|
|
import {
|
|
memo,
|
|
useMemo,
|
|
} from 'react'
|
|
import {
|
|
RiAlertFill,
|
|
RiCheckboxCircleFill,
|
|
RiErrorWarningFill,
|
|
RiLoader2Line,
|
|
} from '@remixicon/react'
|
|
import {
|
|
NodeTargetHandle,
|
|
} from '@/app/components/workflow/nodes/_base/components/node-handle'
|
|
import NodeControl from '@/app/components/workflow/nodes/_base/components/node-control'
|
|
import cn from '@/utils/classnames'
|
|
import BlockIcon from '@/app/components/workflow/block-icon'
|
|
import type {
|
|
NodeProps,
|
|
} from '@/app/components/workflow/types'
|
|
import {
|
|
NodeRunningStatus,
|
|
} from '@/app/components/workflow/types'
|
|
import {
|
|
useNodesReadOnly,
|
|
} from '@/app/components/workflow/hooks'
|
|
|
|
type SimpleNodeProps = NodeProps
|
|
|
|
const SimpleNode: FC<SimpleNodeProps> = ({
|
|
id,
|
|
data,
|
|
}) => {
|
|
const { nodesReadOnly } = useNodesReadOnly()
|
|
|
|
const showSelectedBorder = data.selected || data._isBundled || data._isEntering
|
|
const {
|
|
showRunningBorder,
|
|
showSuccessBorder,
|
|
showFailedBorder,
|
|
showExceptionBorder,
|
|
} = useMemo(() => {
|
|
return {
|
|
showRunningBorder: data._runningStatus === NodeRunningStatus.Running && !showSelectedBorder,
|
|
showSuccessBorder: data._runningStatus === NodeRunningStatus.Succeeded && !showSelectedBorder,
|
|
showFailedBorder: data._runningStatus === NodeRunningStatus.Failed && !showSelectedBorder,
|
|
showExceptionBorder: data._runningStatus === NodeRunningStatus.Exception && !showSelectedBorder,
|
|
}
|
|
}, [data._runningStatus, showSelectedBorder])
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
'flex rounded-2xl border-[2px]',
|
|
showSelectedBorder ? 'border-components-option-card-option-selected-border' : 'border-transparent',
|
|
data._waitingRun && 'opacity-70',
|
|
)}
|
|
style={{
|
|
width: 'auto',
|
|
height: 'auto',
|
|
}}
|
|
>
|
|
<div
|
|
className={cn(
|
|
'group relative pb-1 shadow-xs',
|
|
'rounded-[15px] border border-transparent',
|
|
'w-[240px] bg-workflow-block-bg',
|
|
!data._runningStatus && 'hover:shadow-lg',
|
|
showRunningBorder && '!border-state-accent-solid',
|
|
showSuccessBorder && '!border-state-success-solid',
|
|
showFailedBorder && '!border-state-destructive-solid',
|
|
showExceptionBorder && '!border-state-warning-solid',
|
|
data._isBundled && '!shadow-lg',
|
|
)}
|
|
>
|
|
{
|
|
!data._isCandidate && (
|
|
<NodeTargetHandle
|
|
id={id}
|
|
data={data}
|
|
handleClassName='!top-4 !-left-[9px] !translate-y-0'
|
|
handleId='target'
|
|
/>
|
|
)
|
|
}
|
|
{
|
|
!data._runningStatus && !nodesReadOnly && !data._isCandidate && (
|
|
<NodeControl
|
|
id={id}
|
|
data={data}
|
|
/>
|
|
)
|
|
}
|
|
<div className={cn(
|
|
'flex items-center rounded-t-2xl px-3 pb-2 pt-3',
|
|
)}>
|
|
<BlockIcon
|
|
className='mr-2 shrink-0'
|
|
type={data.type}
|
|
size='md'
|
|
/>
|
|
<div
|
|
title={data.title}
|
|
className='system-sm-semibold-uppercase mr-1 flex grow items-center truncate text-text-primary'
|
|
>
|
|
<div>
|
|
{data.title}
|
|
</div>
|
|
</div>
|
|
{
|
|
(data._runningStatus === NodeRunningStatus.Running || data._singleRunningStatus === NodeRunningStatus.Running) && (
|
|
<RiLoader2Line className='h-3.5 w-3.5 animate-spin text-text-accent' />
|
|
)
|
|
}
|
|
{
|
|
data._runningStatus === NodeRunningStatus.Succeeded && (
|
|
<RiCheckboxCircleFill className='h-3.5 w-3.5 text-text-success' />
|
|
)
|
|
}
|
|
{
|
|
data._runningStatus === NodeRunningStatus.Failed && (
|
|
<RiErrorWarningFill className='h-3.5 w-3.5 text-text-destructive' />
|
|
)
|
|
}
|
|
{
|
|
data._runningStatus === NodeRunningStatus.Exception && (
|
|
<RiAlertFill className='h-3.5 w-3.5 text-text-warning-secondary' />
|
|
)
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default memo(SimpleNode)
|