balibabu commited on
Commit
3060a10
·
1 Parent(s): f947a67

fix: Fetch chunk list by @tanstack/react-query #1306 (#1738)

Browse files

### What problem does this PR solve?

fix: Fetch chunk list by @tanstack/react-query #1306

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

web/src/hooks/chunk-hooks.ts CHANGED
@@ -1,12 +1,17 @@
1
- import { useCallback } from 'react';
 
 
 
 
 
 
2
  import { useDispatch } from 'umi';
 
 
 
 
3
  import { useGetKnowledgeSearchParams } from './route-hook';
4
 
5
- interface PayloadType {
6
- doc_id: string;
7
- keywords?: string;
8
- }
9
-
10
  export const useFetchChunkList = () => {
11
  const dispatch = useDispatch();
12
  const { documentId } = useGetKnowledgeSearchParams();
@@ -22,3 +27,104 @@ export const useFetchChunkList = () => {
22
 
23
  return fetchChunkList;
24
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ResponseGetType } from '@/interfaces/database/base';
2
+ import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
3
+ import kbService from '@/services/knowledge-service';
4
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
5
+ import { useDebounce } from 'ahooks';
6
+ import { PaginationProps } from 'antd';
7
+ import { useCallback, useState } from 'react';
8
  import { useDispatch } from 'umi';
9
+ import {
10
+ useGetPaginationWithRouter,
11
+ useHandleSearchChange,
12
+ } from './logic-hooks';
13
  import { useGetKnowledgeSearchParams } from './route-hook';
14
 
 
 
 
 
 
15
  export const useFetchChunkList = () => {
16
  const dispatch = useDispatch();
17
  const { documentId } = useGetKnowledgeSearchParams();
 
27
 
28
  return fetchChunkList;
29
  };
30
+
31
+ export interface IChunkListResult {
32
+ searchString?: string;
33
+ handleInputChange?: React.ChangeEventHandler<HTMLInputElement>;
34
+ pagination: PaginationProps;
35
+ setPagination?: (pagination: { page: number; pageSize: number }) => void;
36
+ available: number | undefined;
37
+ handleSetAvailable: (available: number | undefined) => void;
38
+ }
39
+
40
+ export const useFetchNextChunkList = (): ResponseGetType<{
41
+ data: IChunk[];
42
+ total: number;
43
+ documentInfo: IKnowledgeFile;
44
+ }> &
45
+ IChunkListResult => {
46
+ const { pagination, setPagination } = useGetPaginationWithRouter();
47
+ const { documentId } = useGetKnowledgeSearchParams();
48
+ const { searchString, handleInputChange } = useHandleSearchChange();
49
+ const [available, setAvailable] = useState<number | undefined>();
50
+ const debouncedSearchString = useDebounce(searchString, { wait: 500 });
51
+
52
+ const { data, isFetching: loading } = useQuery({
53
+ queryKey: [
54
+ 'fetchChunkList',
55
+ documentId,
56
+ pagination.current,
57
+ pagination.pageSize,
58
+ debouncedSearchString,
59
+ available,
60
+ ],
61
+
62
+ initialData: { data: [], total: 0, documentInfo: {} },
63
+ // placeholderData: keepPreviousData,
64
+ gcTime: 0,
65
+ queryFn: async () => {
66
+ const { data } = await kbService.chunk_list({
67
+ doc_id: documentId,
68
+ page: pagination.current,
69
+ size: pagination.pageSize,
70
+ available_int: available,
71
+ keywords: searchString,
72
+ });
73
+ if (data.retcode === 0) {
74
+ const res = data.data;
75
+ return {
76
+ data: res.chunks,
77
+ total: res.total,
78
+ documentInfo: res.doc,
79
+ };
80
+ }
81
+
82
+ return (
83
+ data?.data ?? {
84
+ data: [],
85
+ total: 0,
86
+ documentInfo: {},
87
+ }
88
+ );
89
+ },
90
+ });
91
+
92
+ const onInputChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
93
+ (e) => {
94
+ setPagination({ page: 1 });
95
+ handleInputChange(e);
96
+ },
97
+ [handleInputChange, setPagination],
98
+ );
99
+
100
+ const handleSetAvailable = useCallback(
101
+ (a: number | undefined) => {
102
+ setPagination({ page: 1 });
103
+ setAvailable(a);
104
+ },
105
+ [setAvailable, setPagination],
106
+ );
107
+
108
+ return {
109
+ data,
110
+ loading,
111
+ pagination,
112
+ setPagination,
113
+ searchString,
114
+ handleInputChange: onInputChange,
115
+ available,
116
+ handleSetAvailable,
117
+ };
118
+ };
119
+
120
+ export const useSelectChunkList = () => {
121
+ const queryClient = useQueryClient();
122
+ const data = queryClient.getQueriesData<{
123
+ data: IChunk[];
124
+ total: number;
125
+ documentInfo: IKnowledgeFile;
126
+ }>({ queryKey: ['fetchChunkList'] });
127
+
128
+ // console.log('🚀 ~ useSelectChunkList ~ data:', data);
129
+ return data?.at(-1)?.[1];
130
+ };
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.less CHANGED
@@ -17,8 +17,9 @@
17
  .contentEllipsis {
18
  .multipleLineEllipsis(3);
19
  }
 
20
  .contentText {
21
- word-break: break-all;
22
  }
23
 
24
  .chunkCard {
 
17
  .contentEllipsis {
18
  .multipleLineEllipsis(3);
19
  }
20
+
21
  .contentText {
22
+ word-break: break-all !important;
23
  }
24
 
25
  .chunkCard {
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-toolbar/index.tsx CHANGED
@@ -1,5 +1,6 @@
1
  import { ReactComponent as FilterIcon } from '@/assets/filter.svg';
2
  import { KnowledgeRouteKey } from '@/constants/knowledge';
 
3
  import { useTranslate } from '@/hooks/common-hooks';
4
  import { useKnowledgeBaseId } from '@/hooks/knowledge-hooks';
5
  import {
@@ -27,16 +28,18 @@ import {
27
  Space,
28
  Typography,
29
  } from 'antd';
30
- import { ChangeEventHandler, useCallback, useMemo, useState } from 'react';
31
- import { Link, useDispatch, useSelector } from 'umi';
32
  import { ChunkTextMode } from '../../constant';
33
- import { ChunkModelState } from '../../model';
34
 
35
  const { Text } = Typography;
36
 
37
- interface IProps {
 
 
 
 
38
  checked: boolean;
39
- getChunkList: () => void;
40
  selectAllChunk: (checked: boolean) => void;
41
  createChunk: () => void;
42
  removeChunk: () => void;
@@ -45,17 +48,19 @@ interface IProps {
45
  }
46
 
47
  const ChunkToolBar = ({
48
- getChunkList,
49
  selectAllChunk,
50
  checked,
51
  createChunk,
52
  removeChunk,
53
  switchChunk,
54
  changeChunkTextMode,
 
 
 
 
55
  }: IProps) => {
56
- const { documentInfo, available, searchString }: ChunkModelState =
57
- useSelector((state: any) => state.chunkModel);
58
- const dispatch = useDispatch();
59
  const knowledgeBaseId = useKnowledgeBaseId();
60
  const [isShowSearchBox, setIsShowSearchBox] = useState(false);
61
  const { t } = useTranslate('chunk');
@@ -71,17 +76,17 @@ const ChunkToolBar = ({
71
  setIsShowSearchBox(true);
72
  };
73
 
74
- const handleSearchChange: ChangeEventHandler<HTMLInputElement> = (e) => {
75
- const val = e.target.value;
76
- dispatch({ type: 'chunkModel/setSearchString', payload: val });
77
- dispatch({
78
- type: 'chunkModel/throttledGetChunkList',
79
- payload: documentInfo.id,
80
- });
81
- };
82
 
83
  const handleSearchBlur = () => {
84
- if (!searchString.trim()) {
85
  setIsShowSearchBox(false);
86
  }
87
  };
@@ -155,8 +160,7 @@ const ChunkToolBar = ({
155
 
156
  const handleFilterChange = (e: RadioChangeEvent) => {
157
  selectAllChunk(false);
158
- dispatch({ type: 'chunkModel/setAvailable', payload: e.target.value });
159
- getChunkList();
160
  };
161
 
162
  const filterContent = (
@@ -178,8 +182,8 @@ const ChunkToolBar = ({
178
  <ArrowLeftOutlined />
179
  </Link>
180
  <FilePdfOutlined />
181
- <Text ellipsis={{ tooltip: documentInfo.name }} style={{ width: 150 }}>
182
- {documentInfo.name}
183
  </Text>
184
  </Space>
185
  <Space>
@@ -202,7 +206,7 @@ const ChunkToolBar = ({
202
  placeholder={t('search')}
203
  prefix={<SearchOutlined />}
204
  allowClear
205
- onChange={handleSearchChange}
206
  onBlur={handleSearchBlur}
207
  value={searchString}
208
  />
 
1
  import { ReactComponent as FilterIcon } from '@/assets/filter.svg';
2
  import { KnowledgeRouteKey } from '@/constants/knowledge';
3
+ import { IChunkListResult, useSelectChunkList } from '@/hooks/chunk-hooks';
4
  import { useTranslate } from '@/hooks/common-hooks';
5
  import { useKnowledgeBaseId } from '@/hooks/knowledge-hooks';
6
  import {
 
28
  Space,
29
  Typography,
30
  } from 'antd';
31
+ import { useCallback, useMemo, useState } from 'react';
32
+ import { Link } from 'umi';
33
  import { ChunkTextMode } from '../../constant';
 
34
 
35
  const { Text } = Typography;
36
 
37
+ interface IProps
38
+ extends Pick<
39
+ IChunkListResult,
40
+ 'searchString' | 'handleInputChange' | 'available' | 'handleSetAvailable'
41
+ > {
42
  checked: boolean;
 
43
  selectAllChunk: (checked: boolean) => void;
44
  createChunk: () => void;
45
  removeChunk: () => void;
 
48
  }
49
 
50
  const ChunkToolBar = ({
 
51
  selectAllChunk,
52
  checked,
53
  createChunk,
54
  removeChunk,
55
  switchChunk,
56
  changeChunkTextMode,
57
+ available,
58
+ handleSetAvailable,
59
+ searchString,
60
+ handleInputChange,
61
  }: IProps) => {
62
+ const data = useSelectChunkList();
63
+ const documentInfo = data?.documentInfo;
 
64
  const knowledgeBaseId = useKnowledgeBaseId();
65
  const [isShowSearchBox, setIsShowSearchBox] = useState(false);
66
  const { t } = useTranslate('chunk');
 
76
  setIsShowSearchBox(true);
77
  };
78
 
79
+ // const handleSearchChange: ChangeEventHandler<HTMLInputElement> = (e) => {
80
+ // const val = e.target.value;
81
+ // dispatch({ type: 'chunkModel/setSearchString', payload: val });
82
+ // dispatch({
83
+ // type: 'chunkModel/throttledGetChunkList',
84
+ // payload: documentInfo.id,
85
+ // });
86
+ // };
87
 
88
  const handleSearchBlur = () => {
89
+ if (!searchString?.trim()) {
90
  setIsShowSearchBox(false);
91
  }
92
  };
 
160
 
161
  const handleFilterChange = (e: RadioChangeEvent) => {
162
  selectAllChunk(false);
163
+ handleSetAvailable(e.target.value);
 
164
  };
165
 
166
  const filterContent = (
 
182
  <ArrowLeftOutlined />
183
  </Link>
184
  <FilePdfOutlined />
185
+ <Text ellipsis={{ tooltip: documentInfo?.name }} style={{ width: 150 }}>
186
+ {documentInfo?.name}
187
  </Text>
188
  </Space>
189
  <Space>
 
206
  placeholder={t('search')}
207
  prefix={<SearchOutlined />}
208
  allowClear
209
+ onChange={handleInputChange}
210
  onBlur={handleSearchBlur}
211
  value={searchString}
212
  />
web/src/pages/add-knowledge/components/knowledge-chunk/components/document-preview/preview.tsx CHANGED
@@ -1,5 +1,5 @@
1
  import { Skeleton } from 'antd';
2
- import { useEffect, useRef } from 'react';
3
  import {
4
  AreaHighlight,
5
  Highlight,
@@ -8,7 +8,6 @@ import {
8
  PdfLoader,
9
  Popup,
10
  } from 'react-pdf-highlighter';
11
- import { useGetChunkHighlights } from '../../hooks';
12
  import { useGetDocumentUrl } from './hooks';
13
 
14
  import { useCatchDocumentError } from '@/components/pdf-previewer/hooks';
@@ -16,7 +15,8 @@ import FileError from '@/pages/document-viewer/file-error';
16
  import styles from './index.less';
17
 
18
  interface IProps {
19
- selectedChunkId: string;
 
20
  }
21
  const HighlightPopup = ({
22
  comment,
@@ -30,11 +30,10 @@ const HighlightPopup = ({
30
  ) : null;
31
 
32
  // TODO: merge with DocumentPreviewer
33
- const Preview = ({ selectedChunkId }: IProps) => {
34
  const url = useGetDocumentUrl();
35
  useCatchDocumentError(url);
36
- const { highlights: state, setWidthAndHeight } =
37
- useGetChunkHighlights(selectedChunkId);
38
  const ref = useRef<(highlight: IHighlight) => void>(() => {});
39
  const error = useCatchDocumentError(url);
40
 
@@ -120,4 +119,12 @@ const Preview = ({ selectedChunkId }: IProps) => {
120
  );
121
  };
122
 
123
- export default Preview;
 
 
 
 
 
 
 
 
 
1
  import { Skeleton } from 'antd';
2
+ import { memo, useEffect, useRef } from 'react';
3
  import {
4
  AreaHighlight,
5
  Highlight,
 
8
  PdfLoader,
9
  Popup,
10
  } from 'react-pdf-highlighter';
 
11
  import { useGetDocumentUrl } from './hooks';
12
 
13
  import { useCatchDocumentError } from '@/components/pdf-previewer/hooks';
 
15
  import styles from './index.less';
16
 
17
  interface IProps {
18
+ highlights: IHighlight[];
19
+ setWidthAndHeight: (width: number, height: number) => void;
20
  }
21
  const HighlightPopup = ({
22
  comment,
 
30
  ) : null;
31
 
32
  // TODO: merge with DocumentPreviewer
33
+ const Preview = ({ highlights: state, setWidthAndHeight }: IProps) => {
34
  const url = useGetDocumentUrl();
35
  useCatchDocumentError(url);
36
+
 
37
  const ref = useRef<(highlight: IHighlight) => void>(() => {});
38
  const error = useCatchDocumentError(url);
39
 
 
119
  );
120
  };
121
 
122
+ const compare = (oldProps: IProps, newProps: IProps) => {
123
+ const arePropsEqual =
124
+ oldProps.highlights === newProps.highlights ||
125
+ (oldProps.highlights.length === 0 && newProps.highlights.length === 0);
126
+
127
+ return arePropsEqual;
128
+ };
129
+
130
+ export default memo(Preview);
web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts CHANGED
@@ -1,24 +1,17 @@
 
1
  import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
2
- import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
3
  import { buildChunkHighlights } from '@/utils/document-util';
4
  import { useCallback, useMemo, useState } from 'react';
5
  import { IHighlight } from 'react-pdf-highlighter';
6
- import { useSelector } from 'umi';
7
  import { ChunkTextMode } from './constant';
8
 
9
- export const useSelectDocumentInfo = () => {
10
- const documentInfo: IKnowledgeFile = useSelector(
11
- (state: any) => state.chunkModel.documentInfo,
12
- );
13
- return documentInfo;
14
- };
15
-
16
- export const useSelectChunkList = () => {
17
- const chunkList: IChunk[] = useSelector(
18
- (state: any) => state.chunkModel.data,
19
- );
20
- return chunkList;
21
- };
22
 
23
  export const useHandleChunkCardClick = () => {
24
  const [selectedChunkId, setSelectedChunkId] = useState<string>('');
@@ -31,9 +24,9 @@ export const useHandleChunkCardClick = () => {
31
  };
32
 
33
  export const useGetSelectedChunk = (selectedChunkId: string) => {
34
- const chunkList: IChunk[] = useSelectChunkList();
35
  return (
36
- chunkList.find((x) => x.chunk_id === selectedChunkId) ?? ({} as IChunk)
37
  );
38
  };
39
 
@@ -45,14 +38,14 @@ export const useGetChunkHighlights = (selectedChunkId: string) => {
45
  return buildChunkHighlights(selectedChunk, size);
46
  }, [selectedChunk, size]);
47
 
48
- const setWidthAndHeight = (width: number, height: number) => {
49
  setSize((pre) => {
50
  if (pre.height !== height || pre.width !== width) {
51
  return { height, width };
52
  }
53
  return pre;
54
  });
55
- };
56
 
57
  return { highlights, setWidthAndHeight };
58
  };
 
1
+ import { useSelectChunkList } from '@/hooks/chunk-hooks';
2
  import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
3
+ import { IChunk } from '@/interfaces/database/knowledge';
4
  import { buildChunkHighlights } from '@/utils/document-util';
5
  import { useCallback, useMemo, useState } from 'react';
6
  import { IHighlight } from 'react-pdf-highlighter';
 
7
  import { ChunkTextMode } from './constant';
8
 
9
+ // export const useSelectChunkList = () => {
10
+ // const chunkList: IChunk[] = useSelector(
11
+ // (state: any) => state.chunkModel.data,
12
+ // );
13
+ // return chunkList;
14
+ // };
 
 
 
 
 
 
 
15
 
16
  export const useHandleChunkCardClick = () => {
17
  const [selectedChunkId, setSelectedChunkId] = useState<string>('');
 
24
  };
25
 
26
  export const useGetSelectedChunk = (selectedChunkId: string) => {
27
+ const data = useSelectChunkList();
28
  return (
29
+ data?.data?.find((x) => x.chunk_id === selectedChunkId) ?? ({} as IChunk)
30
  );
31
  };
32
 
 
38
  return buildChunkHighlights(selectedChunk, size);
39
  }, [selectedChunk, size]);
40
 
41
+ const setWidthAndHeight = useCallback((width: number, height: number) => {
42
  setSize((pre) => {
43
  if (pre.height !== height || pre.width !== width) {
44
  return { height, width };
45
  }
46
  return pre;
47
  });
48
+ }, []);
49
 
50
  return { highlights, setWidthAndHeight };
51
  };
web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx CHANGED
@@ -1,45 +1,46 @@
1
- import { useFetchChunkList } from '@/hooks/chunk-hooks';
2
  import { useDeleteChunkByIds } from '@/hooks/knowledge-hooks';
3
  import type { PaginationProps } from 'antd';
4
  import { Divider, Flex, Pagination, Space, Spin, message } from 'antd';
5
  import classNames from 'classnames';
6
  import { useCallback, useEffect, useState } from 'react';
7
- import { useDispatch, useSearchParams, useSelector } from 'umi';
8
  import ChunkCard from './components/chunk-card';
9
  import CreatingModal from './components/chunk-creating-modal';
10
  import ChunkToolBar from './components/chunk-toolbar';
11
  import DocumentPreview from './components/document-preview/preview';
12
  import {
13
  useChangeChunkTextMode,
 
14
  useHandleChunkCardClick,
15
- useSelectChunkListLoading,
16
- useSelectDocumentInfo,
17
  } from './hooks';
18
- import { ChunkModelState } from './model';
19
 
20
  import { useTranslation } from 'react-i18next';
21
  import styles from './index.less';
22
 
23
  const Chunk = () => {
24
  const dispatch = useDispatch();
25
- const chunkModel: ChunkModelState = useSelector(
26
- (state: any) => state.chunkModel,
27
- );
28
  const [selectedChunkIds, setSelectedChunkIds] = useState<string[]>([]);
29
  const [searchParams] = useSearchParams();
30
- const { data = [], total, pagination } = chunkModel;
31
- const loading = useSelectChunkListLoading();
32
  const documentId: string = searchParams.get('doc_id') || '';
33
  const [chunkId, setChunkId] = useState<string | undefined>();
34
  const { removeChunk } = useDeleteChunkByIds();
35
- const documentInfo = useSelectDocumentInfo();
 
 
 
 
 
 
 
 
36
  const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();
37
- const isPdf = documentInfo.type === 'pdf';
38
  const { t } = useTranslation();
39
  const { changeChunkTextMode, textMode } = useChangeChunkTextMode();
40
 
41
- const getChunkList = useFetchChunkList();
42
-
43
  const handleEditChunk = useCallback(
44
  (chunk_id?: string) => {
45
  setChunkId(chunk_id);
@@ -57,14 +58,8 @@ const Chunk = () => {
57
  size,
58
  ) => {
59
  setSelectedChunkIds([]);
60
- dispatch({
61
- type: 'chunkModel/setPagination',
62
- payload: {
63
- current: page,
64
- pageSize: size,
65
- },
66
- });
67
- getChunkList();
68
  };
69
 
70
  const selectAllChunk = useCallback(
@@ -125,38 +120,44 @@ const Chunk = () => {
125
  },
126
  });
127
  if (!chunkIds && resCode === 0) {
128
- getChunkList();
129
  }
130
  },
131
  [
132
  dispatch,
133
  documentId,
134
- getChunkList,
135
  selectedChunkIds,
136
  showSelectedChunkWarning,
137
  ],
138
  );
139
 
 
 
 
140
  useEffect(() => {
141
- getChunkList();
142
  return () => {
143
  dispatch({
144
  type: 'chunkModel/resetFilter', // TODO: need to reset state uniformly
145
  });
146
  };
147
- }, [dispatch, getChunkList]);
148
 
149
  return (
150
  <>
151
  <div className={styles.chunkPage}>
152
  <ChunkToolBar
153
- getChunkList={getChunkList}
154
  selectAllChunk={selectAllChunk}
155
  createChunk={handleEditChunk}
156
  removeChunk={handleRemoveChunk}
157
  checked={selectedChunkIds.length === data.length}
158
  switchChunk={switchChunk}
159
  changeChunkTextMode={changeChunkTextMode}
 
 
 
 
160
  ></ChunkToolBar>
161
  <Divider></Divider>
162
  <Flex flex={1} gap={'middle'}>
@@ -193,33 +194,22 @@ const Chunk = () => {
193
  </Spin>
194
  <div className={styles.pageFooter}>
195
  <Pagination
196
- responsive
197
- showLessItems
198
- showQuickJumper
199
- showSizeChanger
200
- onChange={onPaginationChange}
201
- pageSize={pagination.pageSize}
202
- pageSizeOptions={[10, 30, 60, 90]}
203
- current={pagination.current}
204
- size={'small'}
205
  total={total}
206
- showTotal={(total) => (
207
- <Space>
208
- {t('total', { keyPrefix: 'common' })}
209
- {total}
210
- </Space>
211
- )}
212
  />
213
  </div>
214
  </Flex>
215
 
216
- {isPdf && (
217
  <section className={styles.documentPreview}>
218
  <DocumentPreview
219
- selectedChunkId={selectedChunkId}
 
220
  ></DocumentPreview>
221
  </section>
222
- )}
223
  </Flex>
224
  </div>
225
  <CreatingModal doc_id={documentId} chunkId={chunkId} />
 
1
+ import { useFetchNextChunkList } from '@/hooks/chunk-hooks';
2
  import { useDeleteChunkByIds } from '@/hooks/knowledge-hooks';
3
  import type { PaginationProps } from 'antd';
4
  import { Divider, Flex, Pagination, Space, Spin, message } from 'antd';
5
  import classNames from 'classnames';
6
  import { useCallback, useEffect, useState } from 'react';
7
+ import { useDispatch, useSearchParams } from 'umi';
8
  import ChunkCard from './components/chunk-card';
9
  import CreatingModal from './components/chunk-creating-modal';
10
  import ChunkToolBar from './components/chunk-toolbar';
11
  import DocumentPreview from './components/document-preview/preview';
12
  import {
13
  useChangeChunkTextMode,
14
+ useGetChunkHighlights,
15
  useHandleChunkCardClick,
 
 
16
  } from './hooks';
 
17
 
18
  import { useTranslation } from 'react-i18next';
19
  import styles from './index.less';
20
 
21
  const Chunk = () => {
22
  const dispatch = useDispatch();
23
+
 
 
24
  const [selectedChunkIds, setSelectedChunkIds] = useState<string[]>([]);
25
  const [searchParams] = useSearchParams();
26
+ // const loading = useSelectChunkListLoading();
 
27
  const documentId: string = searchParams.get('doc_id') || '';
28
  const [chunkId, setChunkId] = useState<string | undefined>();
29
  const { removeChunk } = useDeleteChunkByIds();
30
+ const {
31
+ data: { documentInfo, data = [], total },
32
+ pagination,
33
+ loading,
34
+ searchString,
35
+ handleInputChange,
36
+ available,
37
+ handleSetAvailable,
38
+ } = useFetchNextChunkList();
39
  const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();
40
+ const isPdf = documentInfo?.type === 'pdf';
41
  const { t } = useTranslation();
42
  const { changeChunkTextMode, textMode } = useChangeChunkTextMode();
43
 
 
 
44
  const handleEditChunk = useCallback(
45
  (chunk_id?: string) => {
46
  setChunkId(chunk_id);
 
58
  size,
59
  ) => {
60
  setSelectedChunkIds([]);
61
+ pagination.onChange?.(page, size);
62
+ // getChunkList();
 
 
 
 
 
 
63
  };
64
 
65
  const selectAllChunk = useCallback(
 
120
  },
121
  });
122
  if (!chunkIds && resCode === 0) {
123
+ // getChunkList();
124
  }
125
  },
126
  [
127
  dispatch,
128
  documentId,
129
+ // getChunkList,
130
  selectedChunkIds,
131
  showSelectedChunkWarning,
132
  ],
133
  );
134
 
135
+ const { highlights, setWidthAndHeight } =
136
+ useGetChunkHighlights(selectedChunkId);
137
+
138
  useEffect(() => {
139
+ // getChunkList();
140
  return () => {
141
  dispatch({
142
  type: 'chunkModel/resetFilter', // TODO: need to reset state uniformly
143
  });
144
  };
145
+ }, [dispatch]);
146
 
147
  return (
148
  <>
149
  <div className={styles.chunkPage}>
150
  <ChunkToolBar
 
151
  selectAllChunk={selectAllChunk}
152
  createChunk={handleEditChunk}
153
  removeChunk={handleRemoveChunk}
154
  checked={selectedChunkIds.length === data.length}
155
  switchChunk={switchChunk}
156
  changeChunkTextMode={changeChunkTextMode}
157
+ searchString={searchString}
158
+ handleInputChange={handleInputChange}
159
+ available={available}
160
+ handleSetAvailable={handleSetAvailable}
161
  ></ChunkToolBar>
162
  <Divider></Divider>
163
  <Flex flex={1} gap={'middle'}>
 
194
  </Spin>
195
  <div className={styles.pageFooter}>
196
  <Pagination
197
+ {...pagination}
 
 
 
 
 
 
 
 
198
  total={total}
199
+ size={'small'}
200
+ onChange={onPaginationChange}
 
 
 
 
201
  />
202
  </div>
203
  </Flex>
204
 
205
+ {
206
  <section className={styles.documentPreview}>
207
  <DocumentPreview
208
+ highlights={highlights}
209
+ setWidthAndHeight={setWidthAndHeight}
210
  ></DocumentPreview>
211
  </section>
212
+ }
213
  </Flex>
214
  </div>
215
  <CreatingModal doc_id={documentId} chunkId={chunkId} />
web/src/pages/force-graph.tsx CHANGED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { memo, useState } from 'react';
2
+
3
+ function compare(oldProps, newProps) {
4
+ return true;
5
+ }
6
+
7
+ const Greeting = memo(function Greeting({ name }) {
8
+ console.log('Greeting was rendered at', new Date().toLocaleTimeString());
9
+ return (
10
+ <h3>
11
+ Hello{name && ', '}
12
+ {name}!
13
+ </h3>
14
+ );
15
+ }, compare);
16
+
17
+ export default function MyApp() {
18
+ const [name, setName] = useState('');
19
+ const [address, setAddress] = useState('');
20
+ return (
21
+ <>
22
+ <label>
23
+ Name{': '}
24
+ <input value={name} onChange={(e) => setName(e.target.value)} />
25
+ </label>
26
+ <label>
27
+ Address{': '}
28
+ <input value={address} onChange={(e) => setAddress(e.target.value)} />
29
+ </label>
30
+ <Greeting name={name} />
31
+ </>
32
+ );
33
+ }
web/src/routes.ts CHANGED
@@ -98,6 +98,11 @@ const routes = [
98
  component: '@/pages/document-viewer',
99
  layout: false,
100
  },
 
 
 
 
 
101
  {
102
  path: '/*',
103
  component: '@/pages/404',
 
98
  component: '@/pages/document-viewer',
99
  layout: false,
100
  },
101
+ {
102
+ path: 'force',
103
+ component: '@/pages/force-graph',
104
+ layout: false,
105
+ },
106
  {
107
  path: '/*',
108
  component: '@/pages/404',