diff --git a/web/src/components/ui/message.ts b/web/src/components/ui/message.ts new file mode 100644 index 000000000..24c834ffb --- /dev/null +++ b/web/src/components/ui/message.ts @@ -0,0 +1,29 @@ +import { toast } from 'sonner'; + +const message = { + success: (msg: string) => { + toast.success(msg, { + position: 'top-center', + closeButton: false, + }); + }, + error: (msg: string) => { + toast.error(msg, { + position: 'top-center', + closeButton: false, + }); + }, + warning: (msg: string) => { + toast.warning(msg, { + position: 'top-center', + closeButton: false, + }); + }, + info: (msg: string) => { + toast.info(msg, { + position: 'top-center', + closeButton: false, + }); + }, +}; +export default message; diff --git a/web/src/components/ui/ragflow-pagination.tsx b/web/src/components/ui/ragflow-pagination.tsx index 264df10f1..dc0f14e6a 100644 --- a/web/src/components/ui/ragflow-pagination.tsx +++ b/web/src/components/ui/ragflow-pagination.tsx @@ -97,30 +97,73 @@ export function RAGFlowPagination({ setCurrentPageSize(pageSize.toString()); }, [pageSize]); + // Generates an array of page numbers to display + const displayedPages = useMemo(() => { + const totalPages = pages.length; + const maxDisplayedPages = 5; + + if (totalPages <= maxDisplayedPages) { + return pages; + } + + const left = Math.max(2, currentPage - 2); + const right = Math.min(totalPages - 1, currentPage + 2); + + const newPages = []; + + newPages.push(1); + + if (left > 2) { + newPages.push(-1); // Indicates an ellipsis + } + + for (let i = left; i <= right; i++) { + newPages.push(i); + } + + if (right < totalPages - 1) { + newPages.push(-1); + } + + if (totalPages > 1) { + newPages.push(totalPages); + } + + return newPages; + }, [pages, currentPage]); + return ( -
+
Total {total} - {pages.map((x) => ( - - - {x} - - - ))} - - - + + {displayedPages.map((page, index) => + page === -1 ? ( + + + + ) : ( + + + {page} + + + ), + )} + diff --git a/web/src/components/ui/spin.tsx b/web/src/components/ui/spin.tsx new file mode 100644 index 000000000..945ae857e --- /dev/null +++ b/web/src/components/ui/spin.tsx @@ -0,0 +1,47 @@ +import { cn } from '@/lib/utils'; +import React from 'react'; + +interface SpinProps { + spinning?: boolean; + size?: 'small' | 'default' | 'large'; + className?: string; + children?: React.ReactNode; +} + +const sizeClasses = { + small: 'w-4 h-4', + default: 'w-6 h-6', + large: 'w-8 h-8', +}; + +export const Spin: React.FC = ({ + spinning = true, + size = 'default', + className, + children, +}) => { + return ( +
+ {spinning && ( +
+
+
+ )} + {children} +
+ ); +}; diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx index 0dfd42089..f1b05a3a8 100644 --- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx +++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx @@ -1,6 +1,4 @@ import { useFetchNextChunkList, useSwitchChunk } from '@/hooks/chunk-hooks'; -import type { PaginationProps } from 'antd'; -import { Flex, Pagination, Space, Spin, message } from 'antd'; import classNames from 'classnames'; import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -19,6 +17,12 @@ import ChunkResultBar from './components/chunk-result-bar'; import CheckboxSets from './components/chunk-result-bar/checkbox-sets'; import DocumentHeader from './components/document-preview/document-header'; +import message from '@/components/ui/message'; +import { + RAGFlowPagination, + RAGFlowPaginationType, +} from '@/components/ui/ragflow-pagination'; +import { Spin } from '@/components/ui/spin'; import styles from './index.less'; const Chunk = () => { @@ -49,7 +53,7 @@ const Chunk = () => { documentId, } = useUpdateChunk(); - const onPaginationChange: PaginationProps['onShowSizeChange'] = ( + const onPaginationChange: RAGFlowPaginationType['onChange'] = ( page, size, ) => { @@ -123,21 +127,8 @@ const Chunk = () => { return ( <>
- {/* */} - {/* */} - -
+
+
@@ -150,9 +141,11 @@ const Chunk = () => {
)} -
@@ -180,12 +173,14 @@ const Chunk = () => { />
- {data.map((item) => ( { textMode={textMode} > ))} - +
- + onChange={(page, pageSize) => { + onPaginationChange(page, pageSize); + }} + >
-
- + + {chunkUpdatingVisible && (