import type { FC } from 'react' import { memo, useState, } from 'react' import { useTranslation } from 'react-i18next' import { ReactSortable } from 'react-sortablejs' import { RiAddLine, RiDeleteBinLine, RiDraggable, } from '@remixicon/react' import useConfig from './use-config' import ConditionAdd from './components/condition-add' import ConditionList from './components/condition-list' import type { IfElseNodeType } from './types' import Button from '@/app/components/base/button' import type { NodePanelProps } from '@/app/components/workflow/types' import Field from '@/app/components/workflow/nodes/_base/components/field' import { useGetAvailableVars } from '@/app/components/workflow/nodes/variable-assigner/hooks' import cn from '@/utils/classnames' const i18nPrefix = 'workflow.nodes.ifElse' const Panel: FC> = ({ id, data, }) => { const { t } = useTranslation() const getAvailableVars = useGetAvailableVars() const { readOnly, inputs, filterVar, filterNumberVar, handleAddCase, handleRemoveCase, handleSortCase, handleAddCondition, handleUpdateCondition, handleRemoveCondition, handleUpdateConditionLogicalOperator, nodesOutputVars, availableNodes, } = useConfig(id, data) const [willDeleteCaseId, setWillDeleteCaseId] = useState('') const cases = inputs.cases || [] const casesLength = cases.length return (
({ ...caseItem, id: caseItem.case_id }))} setList={handleSortCase} handle='.handle' ghostClass='bg-components-panel-bg' animation={150} > { cases.map((item, index) => (
1 && 'group-hover:block', )} />
{ index === 0 ? 'IF' : 'ELIF' } { casesLength > 1 && (
CASE {index + 1}
) }
{ !!item.conditions.length && (
) }
{ ((index === 0 && casesLength > 1) || (index > 0)) && ( ) }
)) }
{t(`${i18nPrefix}.elseDescription`)}
) } export default memo(Panel)