2024-07-01 18:58:51 +08:00
|
|
|
import { Flex } from 'antd';
|
2024-06-05 10:46:06 +08:00
|
|
|
import classNames from 'classnames';
|
2024-07-01 18:58:51 +08:00
|
|
|
import pick from 'lodash/pick';
|
|
|
|
|
import { Handle, NodeProps, Position } from 'reactflow';
|
2024-07-03 10:15:19 +08:00
|
|
|
import { Operator, operatorMap } from '../../constant';
|
2024-06-25 16:17:12 +08:00
|
|
|
import { NodeData } from '../../interface';
|
2024-06-11 18:01:19 +08:00
|
|
|
import OperatorIcon from '../../operator-icon';
|
2024-06-27 14:57:40 +08:00
|
|
|
import NodeDropdown from './dropdown';
|
2024-04-28 19:03:54 +08:00
|
|
|
import styles from './index.less';
|
|
|
|
|
|
2024-06-12 17:38:41 +08:00
|
|
|
export function RagNode({
|
|
|
|
|
id,
|
2024-04-28 19:03:54 +08:00
|
|
|
data,
|
|
|
|
|
isConnectable = true,
|
2024-06-05 10:46:06 +08:00
|
|
|
selected,
|
2024-06-25 16:17:12 +08:00
|
|
|
}: NodeProps<NodeData>) {
|
2024-07-01 18:58:51 +08:00
|
|
|
const style = operatorMap[data.label as Operator];
|
2024-06-13 09:09:34 +08:00
|
|
|
|
2024-04-28 19:03:54 +08:00
|
|
|
return (
|
2024-06-11 18:01:19 +08:00
|
|
|
<section
|
2024-06-12 17:38:41 +08:00
|
|
|
className={classNames(styles.ragNode, {
|
2024-06-05 10:46:06 +08:00
|
|
|
[styles.selectedNode]: selected,
|
|
|
|
|
})}
|
2024-07-01 18:58:51 +08:00
|
|
|
style={pick(style, ['backgroundColor', 'width', 'height', 'color'])}
|
2024-06-05 10:46:06 +08:00
|
|
|
>
|
2024-04-28 19:03:54 +08:00
|
|
|
<Handle
|
2024-06-11 19:31:52 +08:00
|
|
|
id="c"
|
|
|
|
|
type="source"
|
2024-05-27 08:21:30 +08:00
|
|
|
position={Position.Left}
|
2024-04-28 19:03:54 +08:00
|
|
|
isConnectable={isConnectable}
|
2024-06-05 10:46:06 +08:00
|
|
|
className={styles.handle}
|
2024-06-27 09:20:19 +08:00
|
|
|
></Handle>
|
2024-06-11 19:31:52 +08:00
|
|
|
<Handle type="source" position={Position.Top} id="d" isConnectable />
|
2024-04-28 19:03:54 +08:00
|
|
|
<Handle
|
|
|
|
|
type="source"
|
2024-05-27 08:21:30 +08:00
|
|
|
position={Position.Right}
|
2024-04-28 19:03:54 +08:00
|
|
|
isConnectable={isConnectable}
|
2024-06-05 10:46:06 +08:00
|
|
|
className={styles.handle}
|
2024-06-11 19:31:52 +08:00
|
|
|
id="b"
|
2024-06-27 09:20:19 +08:00
|
|
|
></Handle>
|
2024-06-11 19:31:52 +08:00
|
|
|
<Handle type="source" position={Position.Bottom} id="a" isConnectable />
|
2024-07-01 18:58:51 +08:00
|
|
|
<Flex vertical align="center" justify={'center'} gap={6}>
|
|
|
|
|
<OperatorIcon
|
|
|
|
|
name={data.label as Operator}
|
|
|
|
|
fontSize={style['iconFontSize'] ?? 24}
|
|
|
|
|
></OperatorIcon>
|
|
|
|
|
<span
|
|
|
|
|
className={styles.type}
|
|
|
|
|
style={{ fontSize: style.fontSize ?? 14 }}
|
|
|
|
|
>
|
|
|
|
|
{data.label}
|
|
|
|
|
</span>
|
|
|
|
|
<NodeDropdown id={id}></NodeDropdown>
|
2024-06-12 17:38:41 +08:00
|
|
|
</Flex>
|
2024-06-27 09:20:19 +08:00
|
|
|
|
2024-06-26 16:57:38 +08:00
|
|
|
<section className={styles.bottomBox}>
|
2024-07-01 17:12:04 +08:00
|
|
|
<div className={styles.nodeName}>{data.name}</div>
|
2024-06-26 16:57:38 +08:00
|
|
|
</section>
|
2024-06-11 18:01:19 +08:00
|
|
|
</section>
|
2024-04-28 19:03:54 +08:00
|
|
|
);
|
|
|
|
|
}
|