import { Divider, Flex } from 'antd'; import classNames from 'classnames'; import { Handle, NodeProps, Position } from 'reactflow'; import { useGetComponentLabelByValue } from '../../hooks'; import { ISwitchCondition, NodeData } from '../../interface'; import { RightHandleStyle } from './handle-icon'; import { useBuildSwitchHandlePositions } from './hooks'; import styles from './index.less'; import NodeHeader from './node-header'; const getConditionKey = (idx: number, length: number) => { if (idx === 0 && length !== 1) { return 'If'; } else if (idx === length - 1) { return 'Else'; } return 'ElseIf'; }; const ConditionBlock = ({ condition, nodeId, }: { condition: ISwitchCondition; nodeId: string; }) => { const items = condition?.items ?? []; const getLabel = useGetComponentLabelByValue(nodeId); return ( {items.map((x, idx) => (
{getLabel(x?.cpn_id)}
{x?.operator} {x?.value}
{idx + 1 < items.length && ( {condition?.logical_operator} )}
))}
); }; export function SwitchNode({ id, data, selected }: NodeProps) { const { positions } = useBuildSwitchHandlePositions({ data, id }); return (
{positions.map((position, idx) => { return (
{idx < positions.length - 1 && position.text} {getConditionKey(idx, positions.length)} {position.condition && ( )}
); })}
); }