balibabu
commited on
Commit
·
7c4aa10
1
Parent(s):
e5aa7c3
feat: jumping from the chunk list page to the file list page keeps th… (#174)
Browse files* feat: jumping from the chunk list page to the file list page keeps the original page number.
* feat: jump to the file upload page and reset the file list page number to 1
- web/src/hooks/routeHook.ts +12 -1
- web/src/layouts/components/header/index.tsx +3 -2
- web/src/layouts/components/right-toolbar/index.tsx +1 -1
- web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-toolbar/index.tsx +12 -5
- web/src/pages/add-knowledge/components/knowledge-file/hooks.ts +1 -1
- web/src/pages/add-knowledge/components/knowledge-file/model.ts +19 -0
- web/src/pages/add-knowledge/index.tsx +9 -8
- web/src/pages/knowledge/knowledge-card/index.tsx +3 -1
web/src/hooks/routeHook.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import { KnowledgeSearchParams } from '@/constants/knowledge';
|
| 2 |
-
import {
|
|
|
|
| 3 |
|
| 4 |
export enum SegmentIndex {
|
| 5 |
Second = '2',
|
|
@@ -31,3 +32,13 @@ export const useGetKnowledgeSearchParams = () => {
|
|
| 31 |
currentQueryParameters.get(KnowledgeSearchParams.KnowledgeId) || '',
|
| 32 |
};
|
| 33 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import { KnowledgeSearchParams } from '@/constants/knowledge';
|
| 2 |
+
import { useCallback } from 'react';
|
| 3 |
+
import { useLocation, useNavigate, useSearchParams } from 'umi';
|
| 4 |
|
| 5 |
export enum SegmentIndex {
|
| 6 |
Second = '2',
|
|
|
|
| 32 |
currentQueryParameters.get(KnowledgeSearchParams.KnowledgeId) || '',
|
| 33 |
};
|
| 34 |
};
|
| 35 |
+
|
| 36 |
+
export const useNavigateWithFromState = () => {
|
| 37 |
+
const navigate = useNavigate();
|
| 38 |
+
return useCallback(
|
| 39 |
+
(path: string) => {
|
| 40 |
+
navigate(path, { state: { from: path } });
|
| 41 |
+
},
|
| 42 |
+
[navigate],
|
| 43 |
+
);
|
| 44 |
+
};
|
web/src/layouts/components/header/index.tsx
CHANGED
|
@@ -6,8 +6,9 @@ import Toolbar from '../right-toolbar';
|
|
| 6 |
|
| 7 |
import styles from './index.less';
|
| 8 |
|
|
|
|
| 9 |
import { useCallback, useMemo } from 'react';
|
| 10 |
-
import { useLocation
|
| 11 |
|
| 12 |
const { Header } = Layout;
|
| 13 |
|
|
@@ -15,7 +16,7 @@ const RagHeader = () => {
|
|
| 15 |
const {
|
| 16 |
token: { colorBgContainer },
|
| 17 |
} = theme.useToken();
|
| 18 |
-
const navigate =
|
| 19 |
const { pathname } = useLocation();
|
| 20 |
|
| 21 |
const tagsData = useMemo(
|
|
|
|
| 6 |
|
| 7 |
import styles from './index.less';
|
| 8 |
|
| 9 |
+
import { useNavigateWithFromState } from '@/hooks/routeHook';
|
| 10 |
import { useCallback, useMemo } from 'react';
|
| 11 |
+
import { useLocation } from 'umi';
|
| 12 |
|
| 13 |
const { Header } = Layout;
|
| 14 |
|
|
|
|
| 16 |
const {
|
| 17 |
token: { colorBgContainer },
|
| 18 |
} = theme.useToken();
|
| 19 |
+
const navigate = useNavigateWithFromState();
|
| 20 |
const { pathname } = useLocation();
|
| 21 |
|
| 22 |
const tagsData = useMemo(
|
web/src/layouts/components/right-toolbar/index.tsx
CHANGED
|
@@ -11,7 +11,7 @@ const Circle = ({ children }: React.PropsWithChildren) => {
|
|
| 11 |
};
|
| 12 |
|
| 13 |
const handleGithubCLick = () => {
|
| 14 |
-
window.open('https://github.com/infiniflow/
|
| 15 |
};
|
| 16 |
|
| 17 |
const RightToolBar = () => {
|
|
|
|
| 11 |
};
|
| 12 |
|
| 13 |
const handleGithubCLick = () => {
|
| 14 |
+
window.open('https://github.com/infiniflow/ragflow', 'target');
|
| 15 |
};
|
| 16 |
|
| 17 |
const RightToolBar = () => {
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-toolbar/index.tsx
CHANGED
|
@@ -80,12 +80,13 @@ const ChunkToolBar = ({
|
|
| 80 |
removeChunk();
|
| 81 |
}, [removeChunk]);
|
| 82 |
|
| 83 |
-
const handleEnabledClick = () => {
|
| 84 |
switchChunk(1);
|
| 85 |
-
};
|
| 86 |
-
|
|
|
|
| 87 |
switchChunk(0);
|
| 88 |
-
};
|
| 89 |
|
| 90 |
const items: MenuProps['items'] = useMemo(() => {
|
| 91 |
return [
|
|
@@ -129,7 +130,13 @@ const ChunkToolBar = ({
|
|
| 129 |
),
|
| 130 |
},
|
| 131 |
];
|
| 132 |
-
}, [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
const content = (
|
| 135 |
<Menu style={{ width: 200 }} items={items} selectable={false} />
|
|
|
|
| 80 |
removeChunk();
|
| 81 |
}, [removeChunk]);
|
| 82 |
|
| 83 |
+
const handleEnabledClick = useCallback(() => {
|
| 84 |
switchChunk(1);
|
| 85 |
+
}, [switchChunk]);
|
| 86 |
+
|
| 87 |
+
const handleDisabledClick = useCallback(() => {
|
| 88 |
switchChunk(0);
|
| 89 |
+
}, [switchChunk]);
|
| 90 |
|
| 91 |
const items: MenuProps['items'] = useMemo(() => {
|
| 92 |
return [
|
|
|
|
| 130 |
),
|
| 131 |
},
|
| 132 |
];
|
| 133 |
+
}, [
|
| 134 |
+
checked,
|
| 135 |
+
handleSelectAllCheck,
|
| 136 |
+
handleDelete,
|
| 137 |
+
handleEnabledClick,
|
| 138 |
+
handleDisabledClick,
|
| 139 |
+
]);
|
| 140 |
|
| 141 |
const content = (
|
| 142 |
<Menu style={{ width: 200 }} items={items} selectable={false} />
|
web/src/pages/add-knowledge/components/knowledge-file/hooks.ts
CHANGED
|
@@ -74,7 +74,7 @@ export const useGetPagination = (fetchDocumentList: () => void) => {
|
|
| 74 |
showQuickJumper: true,
|
| 75 |
total: kFModel.total,
|
| 76 |
showSizeChanger: true,
|
| 77 |
-
current: kFModel.pagination.
|
| 78 |
pageSize: kFModel.pagination.pageSize,
|
| 79 |
pageSizeOptions: [1, 2, 10, 20, 50, 100],
|
| 80 |
onChange: onPageChange,
|
|
|
|
| 74 |
showQuickJumper: true,
|
| 75 |
total: kFModel.total,
|
| 76 |
showSizeChanger: true,
|
| 77 |
+
current: kFModel.pagination.current,
|
| 78 |
pageSize: kFModel.pagination.pageSize,
|
| 79 |
pageSizeOptions: [1, 2, 10, 20, 50, 100],
|
| 80 |
onChange: onPageChange,
|
web/src/pages/add-knowledge/components/knowledge-file/model.ts
CHANGED
|
@@ -223,5 +223,24 @@ const model: DvaModel<KFModelState> = {
|
|
| 223 |
return data;
|
| 224 |
},
|
| 225 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
};
|
| 227 |
export default model;
|
|
|
|
| 223 |
return data;
|
| 224 |
},
|
| 225 |
},
|
| 226 |
+
subscriptions: {
|
| 227 |
+
setup({ dispatch, history }) {
|
| 228 |
+
history.listen(({ location }) => {
|
| 229 |
+
const state: { from: string } = (location.state ?? {
|
| 230 |
+
from: '',
|
| 231 |
+
}) as { from: string };
|
| 232 |
+
if (
|
| 233 |
+
state.from === '/knowledge' || // TODO: Just directly determine whether the current page is on the knowledge list page.
|
| 234 |
+
location.pathname === '/knowledge/dataset/upload'
|
| 235 |
+
) {
|
| 236 |
+
dispatch({
|
| 237 |
+
type: 'kFModel/setPagination',
|
| 238 |
+
payload: { current: 1, pageSize: 10 },
|
| 239 |
+
});
|
| 240 |
+
}
|
| 241 |
+
console.info(location);
|
| 242 |
+
});
|
| 243 |
+
},
|
| 244 |
+
},
|
| 245 |
};
|
| 246 |
export default model;
|
web/src/pages/add-knowledge/index.tsx
CHANGED
|
@@ -1,9 +1,13 @@
|
|
| 1 |
import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
|
| 2 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import { Breadcrumb } from 'antd';
|
| 4 |
import { ItemType } from 'antd/es/breadcrumb/Breadcrumb';
|
| 5 |
-
import {
|
| 6 |
-
import { Link, Outlet, useDispatch, useLocation
|
| 7 |
import Siderbar from './components/knowledge-sidebar';
|
| 8 |
import {
|
| 9 |
KnowledgeDatasetRouteKey,
|
|
@@ -15,7 +19,6 @@ import styles from './index.less';
|
|
| 15 |
|
| 16 |
const KnowledgeAdding = () => {
|
| 17 |
const dispatch = useDispatch();
|
| 18 |
-
const navigate = useNavigate();
|
| 19 |
const knowledgeBaseId = useKnowledgeBaseId();
|
| 20 |
|
| 21 |
const location = useLocation();
|
|
@@ -25,14 +28,12 @@ const KnowledgeAdding = () => {
|
|
| 25 |
const datasetActiveKey: KnowledgeDatasetRouteKey =
|
| 26 |
useThirdPathName() as KnowledgeDatasetRouteKey;
|
| 27 |
|
| 28 |
-
const gotoList =
|
| 29 |
-
navigate('/knowledge');
|
| 30 |
-
}, [navigate]);
|
| 31 |
|
| 32 |
const breadcrumbItems: ItemType[] = useMemo(() => {
|
| 33 |
const items: ItemType[] = [
|
| 34 |
{
|
| 35 |
-
title: <a onClick={gotoList}>Knowledge Base</a>,
|
| 36 |
},
|
| 37 |
{
|
| 38 |
title: datasetActiveKey ? (
|
|
|
|
| 1 |
import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
|
| 2 |
+
import {
|
| 3 |
+
useNavigateWithFromState,
|
| 4 |
+
useSecondPathName,
|
| 5 |
+
useThirdPathName,
|
| 6 |
+
} from '@/hooks/routeHook';
|
| 7 |
import { Breadcrumb } from 'antd';
|
| 8 |
import { ItemType } from 'antd/es/breadcrumb/Breadcrumb';
|
| 9 |
+
import { useEffect, useMemo } from 'react';
|
| 10 |
+
import { Link, Outlet, useDispatch, useLocation } from 'umi';
|
| 11 |
import Siderbar from './components/knowledge-sidebar';
|
| 12 |
import {
|
| 13 |
KnowledgeDatasetRouteKey,
|
|
|
|
| 19 |
|
| 20 |
const KnowledgeAdding = () => {
|
| 21 |
const dispatch = useDispatch();
|
|
|
|
| 22 |
const knowledgeBaseId = useKnowledgeBaseId();
|
| 23 |
|
| 24 |
const location = useLocation();
|
|
|
|
| 28 |
const datasetActiveKey: KnowledgeDatasetRouteKey =
|
| 29 |
useThirdPathName() as KnowledgeDatasetRouteKey;
|
| 30 |
|
| 31 |
+
const gotoList = useNavigateWithFromState();
|
|
|
|
|
|
|
| 32 |
|
| 33 |
const breadcrumbItems: ItemType[] = useMemo(() => {
|
| 34 |
const items: ItemType[] = [
|
| 35 |
{
|
| 36 |
+
title: <a onClick={() => gotoList('/knowledge')}>Knowledge Base</a>,
|
| 37 |
},
|
| 38 |
{
|
| 39 |
title: datasetActiveKey ? (
|
web/src/pages/knowledge/knowledge-card/index.tsx
CHANGED
|
@@ -56,7 +56,9 @@ const KnowledgeCard = ({ item }: IProps) => {
|
|
| 56 |
};
|
| 57 |
|
| 58 |
const handleCardClick = () => {
|
| 59 |
-
navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${item.id}
|
|
|
|
|
|
|
| 60 |
};
|
| 61 |
|
| 62 |
return (
|
|
|
|
| 56 |
};
|
| 57 |
|
| 58 |
const handleCardClick = () => {
|
| 59 |
+
navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${item.id}`, {
|
| 60 |
+
state: { from: 'list' },
|
| 61 |
+
});
|
| 62 |
};
|
| 63 |
|
| 64 |
return (
|