wwf
2 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useUpdateNodeInternals } from 'reactflow'
import { NodeSourceHandle } from '../node-handle'
import { ErrorHandleTypeEnum } from './types'
import type { Node } from '@/app/components/workflow/types'
import { NodeRunningStatus } from '@/app/components/workflow/types'
import cn from '@/utils/classnames'
 
type ErrorHandleOnNodeProps = Pick<Node, 'id' | 'data'>
const ErrorHandleOnNode = ({
  id,
  data,
}: ErrorHandleOnNodeProps) => {
  const { t } = useTranslation()
  const { error_strategy } = data
  const updateNodeInternals = useUpdateNodeInternals()
 
  useEffect(() => {
    if (error_strategy === ErrorHandleTypeEnum.failBranch)
      updateNodeInternals(id)
  }, [error_strategy, id, updateNodeInternals])
 
  if (!error_strategy)
    return null
 
  return (
    <div className='relative pt-1 pb-2 px-3'>
      <div className={cn(
        'relative flex items-center justify-between px-[5px] h-6 bg-workflow-block-parma-bg rounded-md',
        data._runningStatus === NodeRunningStatus.Exception && 'border-[0.5px] border-components-badge-status-light-warning-halo bg-state-warning-hover',
      )}>
        <div className='system-xs-medium-uppercase text-text-tertiary'>
          {t('workflow.common.onFailure')}
        </div>
        <div className={cn(
          'system-xs-medium text-text-secondary',
          data._runningStatus === NodeRunningStatus.Exception && 'text-text-warning',
        )}>
          {
            error_strategy === ErrorHandleTypeEnum.defaultValue && (
              t('workflow.nodes.common.errorHandle.defaultValue.output')
            )
          }
          {
            error_strategy === ErrorHandleTypeEnum.failBranch && (
              t('workflow.nodes.common.errorHandle.failBranch.title')
            )
          }
        </div>
        {
          error_strategy === ErrorHandleTypeEnum.failBranch && (
            <NodeSourceHandle
              id={id}
              data={data}
              handleId={ErrorHandleTypeEnum.failBranch}
              handleClassName='!top-1/2 !-right-[21px] !-translate-y-1/2 after:!bg-workflow-link-line-failure-button-bg'
              nodeSelectorClassName='!bg-workflow-link-line-failure-button-bg'
            />
          )
        }
      </div>
    </div>
  )
}
 
export default ErrorHandleOnNode