import { useTheme } from '@/components/theme-provider'; import { ISwitchCondition, ISwitchNode } from '@/interfaces/database/flow'; import { Handle, NodeProps, Position } from '@xyflow/react'; import { Divider, Flex } from 'antd'; import classNames from 'classnames'; import { useGetComponentLabelByValue } from '../../hooks/use-get-begin-query'; 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 }); const { theme } = useTheme(); return (
{positions.map((position, idx) => { return (
{idx < positions.length - 1 && position.text} {getConditionKey(idx, positions.length)} {position.condition && ( )}
); })}
); }