static-nodes.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { IFlowNode } from '@/types/flow';
  2. import { Avatar, Empty, List } from 'antd';
  3. import React, { DragEvent } from 'react';
  4. import { useTranslation } from 'react-i18next';
  5. const StaticNodes: React.FC<{ nodes: IFlowNode[] }> = ({ nodes }) => {
  6. const { t } = useTranslation();
  7. function onDragStart(event: DragEvent, node: IFlowNode) {
  8. event.dataTransfer.setData('application/reactflow', JSON.stringify(node));
  9. event.dataTransfer.effectAllowed = 'move';
  10. }
  11. if (nodes?.length > 0) {
  12. return (
  13. <List
  14. className='overflow-hidden overflow-y-auto w-full'
  15. size='small'
  16. itemLayout='horizontal'
  17. dataSource={nodes}
  18. renderItem={node => (
  19. <List.Item
  20. className='cursor-move hover:bg-[#F1F5F9] dark:hover:bg-theme-dark p-0 py-2'
  21. draggable
  22. onDragStart={event => onDragStart(event, node)}
  23. >
  24. <List.Item.Meta
  25. className='flex items-center justify-center'
  26. avatar={<Avatar src={'/icons/node/vis.png'} size={'large'} />}
  27. title={<p className='line-clamp-1 font-medium'>{node.label}</p>}
  28. description={<p className='line-clamp-2'>{node.description}</p>}
  29. />
  30. </List.Item>
  31. )}
  32. />
  33. );
  34. } else {
  35. return <Empty className='px-2' description={t('no_node')} />;
  36. }
  37. };
  38. export default StaticNodes;