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:
balibabu 2024-02-08 18:50:11 +08:00 committed by GitHub
parent 1a156e6569
commit 53be70c7a9
5 changed files with 75 additions and 34 deletions

View 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;

View File

@ -1,7 +1,7 @@
import Image from '@/components/image';
import { IChunk } from '@/interfaces/database/knowledge';
import { api_host } from '@/utils/api';
import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd';
import { useState } from 'react';
import styles from './index.less';
@ -13,22 +13,6 @@ interface IProps {
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 = ({
item,
checked,

View File

@ -28,7 +28,7 @@ import {
UploadProps,
} from 'antd';
import classNames from 'classnames';
import { ReactElement, useEffect, useRef, useState } from 'react';
import { ReactElement, useEffect, useMemo, useRef, useState } from 'react';
import { Nullable } from 'typings';
import { Link, useDispatch, useNavigate, useSelector } from 'umi';
@ -63,6 +63,24 @@ const UploaderItem = ({
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 val = e.target.value;
setValue(val);
@ -72,12 +90,12 @@ const UploaderItem = ({
const content = (
<Radio.Group onChange={onChange} value={value}>
<Space direction="vertical">
{parserArray.map(
{parserList.map(
(
x, // value is lowercase, key is uppercase
) => (
<Radio value={x.toLowerCase()} key={x}>
{x}
<Radio value={x.value} key={x.value}>
{x.label}
</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(() => {
setValue(defaultParserId);
}, [defaultParserId]);

View File

@ -33,4 +33,11 @@
font-size: 12px;
font-weight: 500;
}
.image {
width: 100px;
}
.imagePreview {
display: block;
width: 260px;
}
}

View File

@ -1,6 +1,15 @@
import { ReactComponent as SelectedFilesCollapseIcon } from '@/assets/svg/selected-files-collapse.svg';
import Image from '@/components/image';
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 { TestingModelState } from '../model';
import styles from './index.less';
@ -92,7 +101,22 @@ const TestingResult = ({ handleTesting }: IProps) => {
>
{chunks.map((x) => (
<Card key={x.chunk_id} title={<ChunkTitle item={x}></ChunkTitle>}>
<div>{x.content_with_weight}</div>
<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>
</Flex>
</Card>
))}
</Flex>