2024-07-09 10:43:52 +08:00
|
|
|
import { useTranslate } from '@/hooks/commonHooks';
|
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-09 10:43:52 +08:00
|
|
|
import lowerFirst from 'lodash/lowerFirst';
|
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-07-09 16:34:59 +08:00
|
|
|
import NodePopover from './popover';
|
2024-04-28 19:03:54 +08:00
|
|
|
|
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-07-09 10:43:52 +08:00
|
|
|
const { t } = useTranslate('flow');
|
2024-07-09 16:34:59 +08:00
|
|
|
|
2024-04-28 19:03:54 +08:00
|
|
|
return (
|
2024-07-09 16:34:59 +08:00
|
|
|
<NodePopover nodeId={id}>
|
|
|
|
|
<section
|
|
|
|
|
className={classNames(styles.ragNode, {
|
|
|
|
|
[styles.selectedNode]: selected,
|
|
|
|
|
})}
|
|
|
|
|
style={pick(style, ['backgroundColor', 'width', 'height', 'color'])}
|
2024-07-04 15:10:45 +08:00
|
|
|
>
|
2024-07-09 16:34:59 +08:00
|
|
|
<Handle
|
|
|
|
|
id="c"
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
isConnectable={isConnectable}
|
|
|
|
|
className={styles.handle}
|
|
|
|
|
></Handle>
|
|
|
|
|
<Handle type="source" position={Position.Top} id="d" isConnectable />
|
|
|
|
|
<Handle
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
isConnectable={isConnectable}
|
|
|
|
|
className={styles.handle}
|
|
|
|
|
id="b"
|
|
|
|
|
></Handle>
|
|
|
|
|
<Handle type="source" position={Position.Bottom} id="a" isConnectable />
|
|
|
|
|
<Flex
|
|
|
|
|
vertical
|
|
|
|
|
align="center"
|
|
|
|
|
justify={'center'}
|
|
|
|
|
gap={data.label === Operator.RewriteQuestion ? 0 : 6}
|
2024-07-01 18:58:51 +08:00
|
|
|
>
|
2024-07-09 16:34:59 +08:00
|
|
|
<OperatorIcon
|
|
|
|
|
name={data.label as Operator}
|
|
|
|
|
fontSize={style['iconFontSize'] ?? 24}
|
|
|
|
|
></OperatorIcon>
|
|
|
|
|
<span
|
|
|
|
|
className={styles.type}
|
|
|
|
|
style={{ fontSize: style.fontSize ?? 14 }}
|
|
|
|
|
>
|
|
|
|
|
{t(lowerFirst(data.label))}
|
|
|
|
|
</span>
|
|
|
|
|
<NodeDropdown id={id}></NodeDropdown>
|
|
|
|
|
</Flex>
|
2024-06-27 09:20:19 +08:00
|
|
|
|
2024-07-09 16:34:59 +08:00
|
|
|
<section className={styles.bottomBox}>
|
|
|
|
|
<div className={styles.nodeName}>{data.name}</div>
|
|
|
|
|
</section>
|
2024-06-26 16:57:38 +08:00
|
|
|
</section>
|
2024-07-09 16:34:59 +08:00
|
|
|
</NodePopover>
|
2024-04-28 19:03:54 +08:00
|
|
|
);
|
|
|
|
|
}
|