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-12 17:38:41 +08:00
|
|
|
import OperateDropdown from '@/components/operate-dropdown';
|
|
|
|
|
import { Flex, Space } from 'antd';
|
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
import { Operator, operatorMap } from '../../constant';
|
2024-06-11 18:01:19 +08:00
|
|
|
import OperatorIcon from '../../operator-icon';
|
2024-06-12 17:38:41 +08:00
|
|
|
import useGraphStore from '../../store';
|
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-05-27 08:21:30 +08:00
|
|
|
}: NodeProps<{ label: string }>) {
|
2024-06-12 17:38:41 +08:00
|
|
|
const deleteNodeById = useGraphStore((store) => store.deleteNodeById);
|
|
|
|
|
const deleteNode = useCallback(() => {
|
|
|
|
|
deleteNodeById(id);
|
|
|
|
|
}, [id, deleteNodeById]);
|
|
|
|
|
|
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}
|
|
|
|
|
>
|
|
|
|
|
{/* <PlusCircleOutlined style={{ fontSize: 10 }} /> */}
|
|
|
|
|
</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-05 10:46:06 +08:00
|
|
|
>
|
|
|
|
|
{/* <PlusCircleOutlined style={{ fontSize: 10 }} /> */}
|
|
|
|
|
</Handle>
|
2024-06-11 19:31:52 +08:00
|
|
|
<Handle type="source" position={Position.Bottom} id="a" isConnectable />
|
2024-06-12 17:38:41 +08:00
|
|
|
<Flex gap={10} justify={'space-between'}>
|
|
|
|
|
<Space size={6}>
|
2024-06-11 18:01:19 +08:00
|
|
|
<OperatorIcon
|
|
|
|
|
name={data.label as Operator}
|
|
|
|
|
fontSize={12}
|
|
|
|
|
></OperatorIcon>
|
2024-06-12 17:38:41 +08:00
|
|
|
<span>{data.label}</span>
|
2024-06-11 18:01:19 +08:00
|
|
|
</Space>
|
2024-06-12 17:38:41 +08:00
|
|
|
<OperateDropdown
|
|
|
|
|
iconFontSize={14}
|
|
|
|
|
deleteItem={deleteNode}
|
|
|
|
|
></OperateDropdown>
|
|
|
|
|
</Flex>
|
|
|
|
|
<div className={styles.description}>
|
|
|
|
|
{operatorMap[data.label as Operator].description}
|
2024-06-11 18:01:19 +08:00
|
|
|
</div>
|
|
|
|
|
</section>
|
2024-04-28 19:03:54 +08:00
|
|
|
);
|
|
|
|
|
}
|