import { useTranslation } from 'react-i18next' import { RiArrowRightSLine } from '@remixicon/react' import Button from '@/app/components/base/button' import type { LoopDurationMap, LoopVariableMap, NodeTracing, } from '@/types/workflow' import { Loop } from '@/app/components/base/icons/src/vender/workflow' type LoopLogTriggerProps = { nodeInfo: NodeTracing onShowLoopResultList: (loopResultList: NodeTracing[][], loopResultDurationMap: LoopDurationMap, loopVariableMap: LoopVariableMap) => void } const LoopLogTrigger = ({ nodeInfo, onShowLoopResultList, }: LoopLogTriggerProps) => { const { t } = useTranslation() const getErrorCount = (details: NodeTracing[][] | undefined) => { if (!details || details.length === 0) return 0 return details.reduce((acc, loop) => { if (loop.some(item => item.status === 'failed')) acc++ return acc }, 0) } const getCount = (loop_curr_length: number | undefined, loop_length: number) => { if ((loop_curr_length && loop_curr_length < loop_length) || !loop_length) return loop_curr_length return loop_length } const handleOnShowLoopDetail = (e: React.MouseEvent) => { e.stopPropagation() e.nativeEvent.stopImmediatePropagation() onShowLoopResultList( nodeInfo.details || [], nodeInfo?.loopDurationMap || nodeInfo.execution_metadata?.loop_duration_map || {}, nodeInfo.execution_metadata?.loop_variable_map || {}, ) } return ( ) } export default LoopLogTrigger