您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

loop-log-trigger.tsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { useTranslation } from 'react-i18next'
  2. import { RiArrowRightSLine } from '@remixicon/react'
  3. import Button from '@/app/components/base/button'
  4. import type {
  5. LoopDurationMap,
  6. LoopVariableMap,
  7. NodeTracing,
  8. } from '@/types/workflow'
  9. import { Loop } from '@/app/components/base/icons/src/vender/workflow'
  10. type LoopLogTriggerProps = {
  11. nodeInfo: NodeTracing
  12. onShowLoopResultList: (loopResultList: NodeTracing[][], loopResultDurationMap: LoopDurationMap, loopVariableMap: LoopVariableMap) => void
  13. }
  14. const LoopLogTrigger = ({
  15. nodeInfo,
  16. onShowLoopResultList,
  17. }: LoopLogTriggerProps) => {
  18. const { t } = useTranslation()
  19. const getErrorCount = (details: NodeTracing[][] | undefined) => {
  20. if (!details || details.length === 0)
  21. return 0
  22. return details.reduce((acc, loop) => {
  23. if (loop.some(item => item.status === 'failed'))
  24. acc++
  25. return acc
  26. }, 0)
  27. }
  28. const getCount = (loop_curr_length: number | undefined, loop_length: number) => {
  29. if ((loop_curr_length && loop_curr_length < loop_length) || !loop_length)
  30. return loop_curr_length
  31. return loop_length
  32. }
  33. const handleOnShowLoopDetail = (e: React.MouseEvent<HTMLButtonElement>) => {
  34. e.stopPropagation()
  35. e.nativeEvent.stopImmediatePropagation()
  36. onShowLoopResultList(
  37. nodeInfo.details || [],
  38. nodeInfo?.loopDurationMap || nodeInfo.execution_metadata?.loop_duration_map || {},
  39. nodeInfo.execution_metadata?.loop_variable_map || {},
  40. )
  41. }
  42. return (
  43. <Button
  44. className='flex w-full cursor-pointer items-center gap-2 self-stretch rounded-lg border-none bg-components-button-tertiary-bg-hover px-3 py-2 hover:bg-components-button-tertiary-bg-hover'
  45. onClick={handleOnShowLoopDetail}
  46. >
  47. <Loop className='h-4 w-4 shrink-0 text-components-button-tertiary-text' />
  48. <div className='system-sm-medium flex-1 text-left text-components-button-tertiary-text'>{t('workflow.nodes.loop.loop', { count: getCount(nodeInfo.details?.length, nodeInfo.metadata?.loop_length) })}{getErrorCount(nodeInfo.details) > 0 && (
  49. <>
  50. {t('workflow.nodes.loop.comma')}
  51. {t('workflow.nodes.loop.error', { count: getErrorCount(nodeInfo.details) })}
  52. </>
  53. )}</div>
  54. <RiArrowRightSLine className='h-4 w-4 shrink-0 text-components-button-tertiary-text' />
  55. </Button>
  56. )
  57. }
  58. export default LoopLogTrigger