import type { FC } from 'react' import React, { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { RiAddLine } from '@remixicon/react' import Split from '../_base/components/split' import ResultPanel from '../../run/result-panel' import InputNumberWithSlider from '../_base/components/input-number-with-slider' import type { LoopNodeType } from './types' import useConfig from './use-config' import ConditionWrap from './components/condition-wrap' import LoopVariable from './components/loop-variables' import type { NodePanelProps } from '@/app/components/workflow/types' import Field from '@/app/components/workflow/nodes/_base/components/field' import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form' import formatTracing from '@/app/components/workflow/run/utils/format-log' import { useLogs } from '@/app/components/workflow/run/hooks' import { LOOP_NODE_MAX_COUNT } from '@/config' const i18nPrefix = 'workflow.nodes.loop' const Panel: FC> = ({ id, data, }) => { const { t } = useTranslation() const { readOnly, inputs, childrenNodeVars, loopChildrenNodes, isShowSingleRun, hideSingleRun, runningStatus, handleRun, handleStop, runResult, loopRunResult, handleAddCondition, handleUpdateCondition, handleRemoveCondition, handleToggleConditionLogicalOperator, handleAddSubVariableCondition, handleRemoveSubVariableCondition, handleUpdateSubVariableCondition, handleToggleSubVariableConditionLogicalOperator, handleUpdateLoopCount, handleAddLoopVariable, handleRemoveLoopVariable, handleUpdateLoopVariable, } = useConfig(id, data) const nodeInfo = useMemo(() => { const formattedNodeInfo = formatTracing(loopRunResult, t)[0] if (runResult && formattedNodeInfo) { return { ...formattedNodeInfo, execution_metadata: { ...runResult.execution_metadata, ...formattedNodeInfo.execution_metadata, }, } } return formattedNodeInfo }, [runResult, loopRunResult, t]) const logsParams = useLogs() return (
{t('workflow.nodes.loop.loopVariables')}
} operations={
} >
{t(`${i18nPrefix}.breakCondition`)}
} tooltip={t(`${i18nPrefix}.breakConditionTip`)} >
{t(`${i18nPrefix}.loopMaxCount`)}
} >
{ const roundedVal = Math.round(val) handleUpdateLoopCount(Number.isNaN(roundedVal) ? 1 : roundedVal) }} />
{/* Error handling for the Loop node is currently not considered. */} {/*
*/} {isShowSingleRun && ( } /> )} ) } export default React.memo(Panel)