import type { FC } from 'react' import type { IterationNodeType } from './types' import type { NodePanelProps } from '@/app/components/workflow/types' import { Fieldset, FieldsetLegend } from '@langgenius/dify-ui/fieldset' import { Select, SelectContent, SelectItem, SelectItemIndicator, SelectItemText, SelectLabel, SelectTrigger, } from '@langgenius/dify-ui/select' import { Slider } from '@langgenius/dify-ui/slider' import { Switch } from '@langgenius/dify-ui/switch' import * as React from 'react' import { useTranslation } from 'react-i18next' import Input from '@/app/components/base/input' import Field from '@/app/components/workflow/nodes/_base/components/field' import { ErrorHandleMode } from '@/app/components/workflow/types' import { MAX_PARALLEL_LIMIT } from '@/config' import { MIN_ITERATION_PARALLEL_NUM } from '../../constants' import Split from '../_base/components/split' import VarReferencePicker from '../_base/components/variable/var-reference-picker' import useConfig from './use-config' const i18nPrefix = 'nodes.iteration' const Panel: FC> = ({ id, data }) => { const { t } = useTranslation() const maxParallelismLabel = t(($) => $[`${i18nPrefix}.MaxParallelismTitle`], { ns: 'workflow' }) const errorResponseMethodLabel = t(($) => $[`${i18nPrefix}.errorResponseMethod`], { ns: 'workflow', }) const responseMethod = [ { value: ErrorHandleMode.Terminated, name: t(($) => $[`${i18nPrefix}.ErrorMethod.operationTerminated`], { ns: 'workflow' }), }, { value: ErrorHandleMode.ContinueOnError, name: t(($) => $[`${i18nPrefix}.ErrorMethod.continueOnError`], { ns: 'workflow' }), }, { value: ErrorHandleMode.RemoveAbnormalOutput, name: t(($) => $[`${i18nPrefix}.ErrorMethod.removeAbnormalOutput`], { ns: 'workflow' }), }, ] const { readOnly, inputs, filterInputVar, handleInputChange, childrenNodeVars, iterationChildrenNodes, handleOutputVarChange, changeParallel, changeErrorResponseMode, changeParallelNums, changeFlattenOutput, } = useConfig(id, data) const selectedResponseMethod = responseMethod.find( (item) => item.value === inputs.error_handle_mode, ) return (
$[`${i18nPrefix}.input`], { ns: 'workflow' })} required operations={
Array
} >
$[`${i18nPrefix}.output`], { ns: 'workflow' })} required operations={
Array
} >
$[`${i18nPrefix}.parallelMode`], { ns: 'workflow' })} tooltip={
{t(($) => $[`${i18nPrefix}.parallelPanelDesc`], { ns: 'workflow' })}
} inline >
{inputs.is_parallel && (
{t(($) => $[`${i18nPrefix}.MaxParallelismDesc`], { ns: 'workflow' })}
} >
{maxParallelismLabel} { changeParallelNums(Number(e.target.value)) }} />
)}
value={selectedResponseMethod?.value ?? null} onValueChange={(nextValue) => { if (nextValue == null) return const nextItem = responseMethod.find((item) => item.value === nextValue) if (nextItem) changeErrorResponseMode(nextItem) }} > {errorResponseMethodLabel} {selectedResponseMethod?.name ?? t(($) => $['placeholder.select'], { ns: 'common' })} {responseMethod.map((item) => ( {item.name} ))}
$[`${i18nPrefix}.flattenOutput`], { ns: 'workflow' })} tooltip={
{t(($) => $[`${i18nPrefix}.flattenOutputDesc`], { ns: 'workflow' })}
} inline >
) } export default React.memo(Panel)