diff --git a/web/app/components/base/pagination/index.tsx b/web/app/components/base/pagination/index.tsx index b64c712425..c0cc9f86ec 100644 --- a/web/app/components/base/pagination/index.tsx +++ b/web/app/components/base/pagination/index.tsx @@ -8,7 +8,7 @@ import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import cn from '@/utils/classnames' -type Props = { +export type Props = { className?: string current: number onChange: (cur: number) => void diff --git a/web/app/components/datasets/documents/index.tsx b/web/app/components/datasets/documents/index.tsx index 2176220843..99de8cbed5 100644 --- a/web/app/components/datasets/documents/index.tsx +++ b/web/app/components/datasets/documents/index.tsx @@ -13,7 +13,6 @@ import s from './style.module.css' import Loading from '@/app/components/base/loading' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' -import Pagination from '@/app/components/base/pagination' import { get } from '@/service/base' import { createDocument, fetchDocuments } from '@/service/datasets' import { useDatasetDetailContext } from '@/context/dataset-detail' @@ -22,8 +21,6 @@ import type { NotionPage } from '@/models/common' import type { CreateDocumentReq } from '@/models/datasets' import { DataSourceType } from '@/models/datasets' import RetryButton from '@/app/components/base/retry-button' -// Custom page count is not currently supported. -const limit = 15 const FolderPlusIcon = ({ className }: React.SVGProps) => { return @@ -75,12 +72,14 @@ type IDocumentsProps = { } export const fetcher = (url: string) => get(url, {}, {}) +const DEFAULT_LIMIT = 15 const Documents: FC = ({ datasetId }) => { const { t } = useTranslation() const [inputValue, setInputValue] = useState('') // the input value const [searchValue, setSearchValue] = useState('') const [currPage, setCurrPage] = React.useState(0) + const [limit, setLimit] = useState(DEFAULT_LIMIT) const router = useRouter() const { dataset } = useDatasetDetailContext() const [notionPageSelectorModalVisible, setNotionPageSelectorModalVisible] = useState(false) @@ -94,7 +93,7 @@ const Documents: FC = ({ datasetId }) => { const query = useMemo(() => { return { page: currPage + 1, limit, keyword: debouncedSearchValue, fetch: isDataSourceNotion ? true : '' } - }, [currPage, debouncedSearchValue, isDataSourceNotion]) + }, [currPage, debouncedSearchValue, isDataSourceNotion, limit]) const { data: documentsRes, error, mutate } = useSWR( { @@ -246,13 +245,20 @@ const Documents: FC = ({ datasetId }) => { {isLoading ? : total > 0 - ? + ? : } - {/* Show Pagination only if the total is more than the limit */} - {(total && total > limit) - ? - : null} setNotionPageSelectorModalVisible(false)} diff --git a/web/app/components/datasets/documents/list.tsx b/web/app/components/datasets/documents/list.tsx index 62da976e5e..cd419847fc 100644 --- a/web/app/components/datasets/documents/list.tsx +++ b/web/app/components/datasets/documents/list.tsx @@ -39,6 +39,8 @@ import { ChuckingMode, DataSourceType, type DocumentDisplayStatus, type SimpleDo import type { CommonResponse } from '@/models/common' import useTimestamp from '@/hooks/use-timestamp' import { useDatasetDetailContextWithSelector as useDatasetDetailContext } from '@/context/dataset-detail' +import type { Props as PaginationProps } from '@/app/components/base/pagination' +import Pagination from '@/app/components/base/pagination' export const useIndexStatus = () => { const { t } = useTranslation() @@ -381,13 +383,20 @@ type IDocumentListProps = { embeddingAvailable: boolean documents: LocalDoc[] datasetId: string + pagination: PaginationProps onUpdate: () => void } /** * Document list component including basic information */ -const DocumentList: FC = ({ embeddingAvailable, documents = [], datasetId, onUpdate }) => { +const DocumentList: FC = ({ + embeddingAvailable, + documents = [], + datasetId, + pagination, + onUpdate, +}) => { const { t } = useTranslation() const { formatTime } = useTimestamp() const router = useRouter() @@ -427,7 +436,7 @@ const DocumentList: FC = ({ embeddingAvailable, documents = }, [onUpdate]) return ( -
+
@@ -520,6 +529,13 @@ const DocumentList: FC = ({ embeddingAvailable, documents = })}
+ {/* Show Pagination only if the total is more than the limit */} + {pagination.total && pagination.total > (pagination.limit || 10) && ( + + )} {isShowRenameModal && currDocument && (