2024-06-05 10:46:06 +08:00
|
|
|
import classNames from 'classnames';
|
2024-04-28 19:03:54 +08:00
|
|
|
import { Handle, NodeProps, Position } from 'reactflow';
|
|
|
|
|
|
2024-06-27 14:57:40 +08:00
|
|
|
import { Flex, Space } from 'antd';
|
2024-06-27 09:20:19 +08:00
|
|
|
import get from 'lodash/get';
|
|
|
|
|
import { CategorizeAnchorPointPositions, Operator } 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 09:20:19 +08:00
|
|
|
import CategorizeHandle from './categorize-handle';
|
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-06-27 09:20:19 +08:00
|
|
|
const isCategorize = data.label === Operator.Categorize;
|
|
|
|
|
const categoryData = get(data, 'form.category_description') ?? {};
|
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-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-06-27 09:20:19 +08:00
|
|
|
{isCategorize &&
|
|
|
|
|
Object.keys(categoryData).map((x, idx) => (
|
|
|
|
|
<CategorizeHandle
|
|
|
|
|
top={CategorizeAnchorPointPositions[idx].top}
|
|
|
|
|
right={CategorizeAnchorPointPositions[idx].right}
|
|
|
|
|
key={idx}
|
|
|
|
|
text={x}
|
|
|
|
|
idx={idx}
|
|
|
|
|
></CategorizeHandle>
|
|
|
|
|
))}
|
2024-06-26 16:57:38 +08:00
|
|
|
<Flex vertical align="center" justify="center">
|
2024-06-12 17:38:41 +08:00
|
|
|
<Space size={6}>
|
2024-06-11 18:01:19 +08:00
|
|
|
<OperatorIcon
|
|
|
|
|
name={data.label as Operator}
|
2024-06-26 16:57:38 +08:00
|
|
|
fontSize={16}
|
2024-06-11 18:01:19 +08:00
|
|
|
></OperatorIcon>
|
2024-06-27 14:57:40 +08:00
|
|
|
<NodeDropdown id={id}></NodeDropdown>
|
2024-06-11 18:01:19 +08:00
|
|
|
</Space>
|
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}>
|
|
|
|
|
<div className={styles.nodeName}>{id}</div>
|
|
|
|
|
</section>
|
2024-06-11 18:01:19 +08:00
|
|
|
</section>
|
2024-04-28 19:03:54 +08:00
|
|
|
);
|
|
|
|
|
}
|