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';
|
2024-06-13 09:09:34 +08:00
|
|
|
import { CopyOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Flex, MenuProps, Space, Typography } from 'antd';
|
2024-06-12 17:38:41 +08:00
|
|
|
import { useCallback } from 'react';
|
2024-06-13 09:09:34 +08:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-06-12 17:38:41 +08:00
|
|
|
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-13 09:09:34 +08:00
|
|
|
const { Text } = Typography;
|
|
|
|
|
|
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-13 09:09:34 +08:00
|
|
|
const { t } = useTranslation();
|
2024-06-12 17:38:41 +08:00
|
|
|
const deleteNodeById = useGraphStore((store) => store.deleteNodeById);
|
2024-06-13 09:09:34 +08:00
|
|
|
const duplicateNodeById = useGraphStore((store) => store.duplicateNode);
|
|
|
|
|
|
2024-06-12 17:38:41 +08:00
|
|
|
const deleteNode = useCallback(() => {
|
|
|
|
|
deleteNodeById(id);
|
|
|
|
|
}, [id, deleteNodeById]);
|
|
|
|
|
|
2024-06-13 09:09:34 +08:00
|
|
|
const duplicateNode = useCallback(() => {
|
|
|
|
|
duplicateNodeById(id);
|
|
|
|
|
}, [id, duplicateNodeById]);
|
|
|
|
|
|
|
|
|
|
const description = operatorMap[data.label as Operator].description;
|
|
|
|
|
|
|
|
|
|
const items: MenuProps['items'] = [
|
|
|
|
|
{
|
|
|
|
|
key: '2',
|
|
|
|
|
onClick: duplicateNode,
|
|
|
|
|
label: (
|
|
|
|
|
<Flex justify={'space-between'}>
|
|
|
|
|
{t('common.copy')}
|
|
|
|
|
<CopyOutlined />
|
|
|
|
|
</Flex>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
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}
|
2024-06-13 09:09:34 +08:00
|
|
|
items={items}
|
2024-06-12 17:38:41 +08:00
|
|
|
></OperateDropdown>
|
|
|
|
|
</Flex>
|
2024-06-13 09:09:34 +08:00
|
|
|
<div>
|
|
|
|
|
<Text
|
|
|
|
|
ellipsis={{ tooltip: description }}
|
|
|
|
|
style={{ width: 130 }}
|
|
|
|
|
className={styles.description}
|
|
|
|
|
>
|
|
|
|
|
{description}
|
|
|
|
|
</Text>
|
2024-06-11 18:01:19 +08:00
|
|
|
</div>
|
|
|
|
|
</section>
|
2024-04-28 19:03:54 +08:00
|
|
|
);
|
|
|
|
|
}
|