mirror of
				https://github.com/infiniflow/ragflow.git
				synced 2025-10-31 01:40:20 +00:00 
			
		
		
		
	feat: transform the parser's data structure and add Image to TestingResult (#63)
* feat: add Image to TestingResult * feat: transform the parser's data structure
This commit is contained in:
		
							parent
							
								
									1a156e6569
								
							
						
					
					
						commit
						53be70c7a9
					
				
							
								
								
									
										19
									
								
								web/src/components/image.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								web/src/components/image.tsx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | import { api_host } from '@/utils/api'; | ||||||
|  | 
 | ||||||
|  | interface IImage { | ||||||
|  |   id: string; | ||||||
|  |   className: string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const Image = ({ id, className, ...props }: IImage) => { | ||||||
|  |   return ( | ||||||
|  |     <img | ||||||
|  |       {...props} | ||||||
|  |       src={`${api_host}/document/image/${id}`} | ||||||
|  |       alt="" | ||||||
|  |       className={className} | ||||||
|  |     /> | ||||||
|  |   ); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default Image; | ||||||
| @ -1,7 +1,7 @@ | |||||||
|  | import Image from '@/components/image'; | ||||||
| import { IChunk } from '@/interfaces/database/knowledge'; | import { IChunk } from '@/interfaces/database/knowledge'; | ||||||
| import { api_host } from '@/utils/api'; | import { api_host } from '@/utils/api'; | ||||||
| import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd'; | import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd'; | ||||||
| 
 |  | ||||||
| import { useState } from 'react'; | import { useState } from 'react'; | ||||||
| import styles from './index.less'; | import styles from './index.less'; | ||||||
| 
 | 
 | ||||||
| @ -13,22 +13,6 @@ interface IProps { | |||||||
|   handleCheckboxClick: (chunkId: string, checked: boolean) => void; |   handleCheckboxClick: (chunkId: string, checked: boolean) => void; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| interface IImage { |  | ||||||
|   id: string; |  | ||||||
|   className: string; |  | ||||||
| } |  | ||||||
| // Pass onMouseEnter and onMouseLeave to img tag using props
 |  | ||||||
| const Image = ({ id, className, ...props }: IImage) => { |  | ||||||
|   return ( |  | ||||||
|     <img |  | ||||||
|       {...props} |  | ||||||
|       src={`${api_host}/document/image/${id}`} |  | ||||||
|       alt="" |  | ||||||
|       className={className} |  | ||||||
|     /> |  | ||||||
|   ); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| const ChunkCard = ({ | const ChunkCard = ({ | ||||||
|   item, |   item, | ||||||
|   checked, |   checked, | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ import { | |||||||
|   UploadProps, |   UploadProps, | ||||||
| } from 'antd'; | } from 'antd'; | ||||||
| import classNames from 'classnames'; | import classNames from 'classnames'; | ||||||
| import { ReactElement, useEffect, useRef, useState } from 'react'; | import { ReactElement, useEffect, useMemo, useRef, useState } from 'react'; | ||||||
| import { Nullable } from 'typings'; | import { Nullable } from 'typings'; | ||||||
| import { Link, useDispatch, useNavigate, useSelector } from 'umi'; | import { Link, useDispatch, useNavigate, useSelector } from 'umi'; | ||||||
| 
 | 
 | ||||||
| @ -63,6 +63,24 @@ const UploaderItem = ({ | |||||||
| 
 | 
 | ||||||
|   const documentId = file?.response?.id; |   const documentId = file?.response?.id; | ||||||
| 
 | 
 | ||||||
|  |   const parserList = useMemo(() => { | ||||||
|  |     return parserArray.map((x) => { | ||||||
|  |       const arr = x.split(':'); | ||||||
|  |       return { value: arr[0], label: arr[1] }; | ||||||
|  |     }); | ||||||
|  |   }, [parserArray]); | ||||||
|  | 
 | ||||||
|  |   const saveParser = (parserId: string) => { | ||||||
|  |     dispatch({ | ||||||
|  |       type: 'kFModel/document_change_parser', | ||||||
|  |       payload: { | ||||||
|  |         parser_id: parserId, | ||||||
|  |         doc_id: documentId, | ||||||
|  |         parser_config: parserConfig, | ||||||
|  |       }, | ||||||
|  |     }); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|   const onChange = (e: RadioChangeEvent) => { |   const onChange = (e: RadioChangeEvent) => { | ||||||
|     const val = e.target.value; |     const val = e.target.value; | ||||||
|     setValue(val); |     setValue(val); | ||||||
| @ -72,12 +90,12 @@ const UploaderItem = ({ | |||||||
|   const content = ( |   const content = ( | ||||||
|     <Radio.Group onChange={onChange} value={value}> |     <Radio.Group onChange={onChange} value={value}> | ||||||
|       <Space direction="vertical"> |       <Space direction="vertical"> | ||||||
|         {parserArray.map( |         {parserList.map( | ||||||
|           ( |           ( | ||||||
|             x, // value is lowercase, key is uppercase
 |             x, // value is lowercase, key is uppercase
 | ||||||
|           ) => ( |           ) => ( | ||||||
|             <Radio value={x.toLowerCase()} key={x}> |             <Radio value={x.value} key={x.value}> | ||||||
|               {x} |               {x.label} | ||||||
|             </Radio> |             </Radio> | ||||||
|           ), |           ), | ||||||
|         )} |         )} | ||||||
| @ -92,17 +110,6 @@ const UploaderItem = ({ | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const saveParser = (parserId: string) => { |  | ||||||
|     dispatch({ |  | ||||||
|       type: 'kFModel/document_change_parser', |  | ||||||
|       payload: { |  | ||||||
|         parser_id: parserId, |  | ||||||
|         doc_id: documentId, |  | ||||||
|         parser_config: parserConfig, |  | ||||||
|       }, |  | ||||||
|     }); |  | ||||||
|   }; |  | ||||||
| 
 |  | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     setValue(defaultParserId); |     setValue(defaultParserId); | ||||||
|   }, [defaultParserId]); |   }, [defaultParserId]); | ||||||
|  | |||||||
| @ -33,4 +33,11 @@ | |||||||
|     font-size: 12px; |     font-size: 12px; | ||||||
|     font-weight: 500; |     font-weight: 500; | ||||||
|   } |   } | ||||||
|  |   .image { | ||||||
|  |     width: 100px; | ||||||
|  |   } | ||||||
|  |   .imagePreview { | ||||||
|  |     display: block; | ||||||
|  |     width: 260px; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,15 @@ | |||||||
| import { ReactComponent as SelectedFilesCollapseIcon } from '@/assets/svg/selected-files-collapse.svg'; | import { ReactComponent as SelectedFilesCollapseIcon } from '@/assets/svg/selected-files-collapse.svg'; | ||||||
|  | import Image from '@/components/image'; | ||||||
| import { ITestingChunk } from '@/interfaces/database/knowledge'; | import { ITestingChunk } from '@/interfaces/database/knowledge'; | ||||||
| import { Card, Collapse, Flex, Pagination, PaginationProps, Space } from 'antd'; | import { | ||||||
|  |   Card, | ||||||
|  |   Collapse, | ||||||
|  |   Flex, | ||||||
|  |   Pagination, | ||||||
|  |   PaginationProps, | ||||||
|  |   Popover, | ||||||
|  |   Space, | ||||||
|  | } from 'antd'; | ||||||
| import { useDispatch, useSelector } from 'umi'; | import { useDispatch, useSelector } from 'umi'; | ||||||
| import { TestingModelState } from '../model'; | import { TestingModelState } from '../model'; | ||||||
| import styles from './index.less'; | import styles from './index.less'; | ||||||
| @ -92,7 +101,22 @@ const TestingResult = ({ handleTesting }: IProps) => { | |||||||
|       > |       > | ||||||
|         {chunks.map((x) => ( |         {chunks.map((x) => ( | ||||||
|           <Card key={x.chunk_id} title={<ChunkTitle item={x}></ChunkTitle>}> |           <Card key={x.chunk_id} title={<ChunkTitle item={x}></ChunkTitle>}> | ||||||
|  |             <Flex gap={'middle'}> | ||||||
|  |               {x.img_id && ( | ||||||
|  |                 <Popover | ||||||
|  |                   placement="topRight" | ||||||
|  |                   content={ | ||||||
|  |                     <Image | ||||||
|  |                       id={x.img_id} | ||||||
|  |                       className={styles.imagePreview} | ||||||
|  |                     ></Image> | ||||||
|  |                   } | ||||||
|  |                 > | ||||||
|  |                   <Image id={x.img_id} className={styles.image}></Image> | ||||||
|  |                 </Popover> | ||||||
|  |               )} | ||||||
|               <div>{x.content_with_weight}</div> |               <div>{x.content_with_weight}</div> | ||||||
|  |             </Flex> | ||||||
|           </Card> |           </Card> | ||||||
|         ))} |         ))} | ||||||
|       </Flex> |       </Flex> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 balibabu
						balibabu