You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useTranslate } from '@/hooks/common-hooks';
  2. import { Flex } from 'antd';
  3. import classNames from 'classnames';
  4. import lowerFirst from 'lodash/lowerFirst';
  5. import pick from 'lodash/pick';
  6. import { Handle, NodeProps, Position } from 'reactflow';
  7. import { Operator, operatorMap } from '../../constant';
  8. import { NodeData } from '../../interface';
  9. import OperatorIcon from '../../operator-icon';
  10. import NodeDropdown from './dropdown';
  11. import styles from './index.less';
  12. import NodePopover from './popover';
  13. const ZeroGapOperators = [Operator.RewriteQuestion, Operator.KeywordExtract];
  14. export function RagNode({
  15. id,
  16. data,
  17. isConnectable = true,
  18. selected,
  19. }: NodeProps<NodeData>) {
  20. const style = operatorMap[data.label as Operator];
  21. const { t } = useTranslate('flow');
  22. return (
  23. <NodePopover nodeId={id}>
  24. <section
  25. className={classNames(styles.ragNode, {
  26. [styles.selectedNode]: selected,
  27. })}
  28. style={pick(style, ['backgroundColor', 'width', 'height', 'color'])}
  29. >
  30. <Handle
  31. id="c"
  32. type="source"
  33. position={Position.Left}
  34. isConnectable={isConnectable}
  35. className={styles.handle}
  36. ></Handle>
  37. <Handle type="source" position={Position.Top} id="d" isConnectable />
  38. <Handle
  39. type="source"
  40. position={Position.Right}
  41. isConnectable={isConnectable}
  42. className={styles.handle}
  43. id="b"
  44. ></Handle>
  45. <Handle type="source" position={Position.Bottom} id="a" isConnectable />
  46. <Flex
  47. vertical
  48. align="center"
  49. justify={'space-around'}
  50. gap={ZeroGapOperators.some((x) => x === data.label) ? 0 : 6}
  51. >
  52. <Flex flex={1} justify="center" align="center">
  53. <OperatorIcon
  54. name={data.label as Operator}
  55. fontSize={style?.iconFontSize ?? 24}
  56. width={style?.iconWidth}
  57. ></OperatorIcon>
  58. </Flex>
  59. <Flex flex={1}>
  60. <span
  61. className={styles.type}
  62. style={{ fontSize: style?.fontSize ?? 14 }}
  63. >
  64. {t(lowerFirst(data.label))}
  65. </span>
  66. </Flex>
  67. <Flex flex={1}>
  68. {' '}
  69. <NodeDropdown id={id}></NodeDropdown>
  70. </Flex>
  71. </Flex>
  72. <section className={styles.bottomBox}>
  73. <div className={styles.nodeName}>{data.name}</div>
  74. </section>
  75. </section>
  76. </NodePopover>
  77. );
  78. }