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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import {
  RiAlertFill,
  RiCheckboxCircleFill,
  RiLoader2Line,
} from '@remixicon/react'
import type { Node } from '@/app/components/workflow/types'
import { NodeRunningStatus } from '@/app/components/workflow/types'
import cn from '@/utils/classnames'
 
type RetryOnNodeProps = Pick<Node, 'id' | 'data'>
const RetryOnNode = ({
  data,
}: RetryOnNodeProps) => {
  const { t } = useTranslation()
  const { retry_config } = data
  const showSelectedBorder = data.selected || data._isBundled || data._isEntering
  const {
    isRunning,
    isSuccessful,
    isException,
    isFailed,
  } = useMemo(() => {
    return {
      isRunning: data._runningStatus === NodeRunningStatus.Running && !showSelectedBorder,
      isSuccessful: data._runningStatus === NodeRunningStatus.Succeeded && !showSelectedBorder,
      isFailed: data._runningStatus === NodeRunningStatus.Failed && !showSelectedBorder,
      isException: data._runningStatus === NodeRunningStatus.Exception && !showSelectedBorder,
    }
  }, [data._runningStatus, showSelectedBorder])
  const showDefault = !isRunning && !isSuccessful && !isException && !isFailed
 
  if (!retry_config?.retry_enabled)
    return null
 
  if (!showDefault && !data._retryIndex)
    return null
 
  return (
    <div className='px-3'>
      <div className={cn(
        'flex items-center justify-between px-[5px] py-1 bg-workflow-block-parma-bg border-[0.5px] border-transparent rounded-md system-xs-medium-uppercase text-text-tertiary',
        isRunning && 'bg-state-accent-hover border-state-accent-active text-text-accent',
        isSuccessful && 'bg-state-success-hover border-state-success-active text-text-success',
        (isException || isFailed) && 'bg-state-warning-hover border-state-warning-active text-text-warning',
      )}>
        <div className='flex items-center'>
          {
            showDefault && (
              t('workflow.nodes.common.retry.retryTimes', { times: retry_config.max_retries })
            )
          }
          {
            isRunning && (
              <>
                <RiLoader2Line className='animate-spin mr-1 w-3.5 h-3.5' />
                {t('workflow.nodes.common.retry.retrying')}
              </>
            )
          }
          {
            isSuccessful && (
              <>
                <RiCheckboxCircleFill className='mr-1 w-3.5 h-3.5' />
                {t('workflow.nodes.common.retry.retrySuccessful')}
              </>
            )
          }
          {
            (isFailed || isException) && (
              <>
                <RiAlertFill className='mr-1 w-3.5 h-3.5' />
                {t('workflow.nodes.common.retry.retryFailed')}
              </>
            )
          }
        </div>
        {
          !showDefault && !!data._retryIndex && (
            <div>
              {data._retryIndex}/{data.retry_config?.max_retries}
            </div>
          )
        }
      </div>
    </div>
  )
}
 
export default RetryOnNode