diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts b/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
index 134f8db21e..64a130cc80 100644
--- a/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
+++ b/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
@@ -1,6 +1,8 @@
import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
-import { useCallback, useState } from 'react';
+import { useCallback, useMemo, useState } from 'react';
+import { IHighlight } from 'react-pdf-highlighter';
import { useSelector } from 'umi';
+import { v4 as uuid } from 'uuid';
export const useSelectDocumentInfo = () => {
const documentInfo: IKnowledgeFile = useSelector(
@@ -28,5 +30,46 @@ export const useHandleChunkCardClick = () => {
export const useGetSelectedChunk = (selectedChunkId: string) => {
const chunkList: IChunk[] = useSelectChunkList();
- return chunkList.find((x) => x.chunk_id === selectedChunkId);
+ return (
+ chunkList.find((x) => x.chunk_id === selectedChunkId) ?? ({} as IChunk)
+ );
+};
+
+export const useGetChunkHighlights = (
+ selectedChunkId: string,
+): IHighlight[] => {
+ const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId);
+
+ const highlights: IHighlight[] = useMemo(() => {
+ return Array.isArray(selectedChunk?.positions)
+ ? selectedChunk?.positions?.map((x) => {
+ const actualPositions = x.map((y, index) =>
+ index !== 0 ? y / 0.7 : y,
+ );
+ const boundingRect = {
+ width: 849,
+ height: 1200,
+ x1: actualPositions[1],
+ x2: actualPositions[2],
+ y1: actualPositions[3],
+ y2: actualPositions[4],
+ };
+ return {
+ id: uuid(),
+ comment: {
+ text: '',
+ emoji: '',
+ },
+ content: { text: selectedChunk.content_with_weight },
+ position: {
+ boundingRect: boundingRect,
+ rects: [boundingRect],
+ pageNumber: x[0],
+ },
+ };
+ })
+ : [];
+ }, [selectedChunk]);
+
+ return highlights;
};
diff --git a/web/src/pages/add-knowledge/components/knowledge-file/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/index.tsx
index eafed785ef..70576f86ff 100644
--- a/web/src/pages/add-knowledge/components/knowledge-file/index.tsx
+++ b/web/src/pages/add-knowledge/components/knowledge-file/index.tsx
@@ -23,7 +23,7 @@ import {
import type { ColumnsType } from 'antd/es/table';
import { PaginationProps } from 'antd/lib';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
-import { Link, useDispatch, useNavigate, useSelector } from 'umi';
+import { useDispatch, useNavigate, useSelector } from 'umi';
import CreateEPModal from './createEFileModal';
import styles from './index.less';
import ParsingActionCell from './parsing-action-cell';
@@ -144,19 +144,22 @@ const KnowledgeFile = () => {
});
}, [dispatch]);
+ const linkToUploadPage = useCallback(() => {
+ navigate(`/knowledge/dataset/upload?id=${knowledgeBaseId}`);
+ }, [navigate, knowledgeBaseId]);
+
const actionItems: MenuProps['items'] = useMemo(() => {
return [
{
key: '1',
+ onClick: linkToUploadPage,
label: (
),
@@ -164,9 +167,10 @@ const KnowledgeFile = () => {
{ type: 'divider' },
{
key: '2',
+ onClick: showCEFModal,
label: (
-