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..1bf82c9fa6 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( { @@ -196,7 +195,7 @@ const Documents: FC = ({ datasetId }) => { } const documentsList = isDataSourceNotion ? documentsWithProgress?.data : documentsRes?.data - + const [selectedIds, setSelectedIds] = useState([]) const { run: handleSearch } = useDebounceFn(() => { setSearchValue(inputValue) }, { wait: 500 }) @@ -246,13 +245,22 @@ 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..cd7162603b 100644 --- a/web/app/components/datasets/documents/list.tsx +++ b/web/app/components/datasets/documents/list.tsx @@ -1,9 +1,9 @@ 'use client' import type { FC } from 'react' -import React, { useCallback, useEffect, useState } from 'react' +import React, { useCallback, useEffect, useMemo, useState } from 'react' import { useBoolean, useDebounceFn } from 'ahooks' import { ArrowDownIcon } from '@heroicons/react/24/outline' -import { pick } from 'lodash-es' +import { pick, uniq } from 'lodash-es' import { RiArchive2Line, RiDeleteBinLine, @@ -39,6 +39,9 @@ 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' +import Checkbox from '@/app/components/base/checkbox' export const useIndexStatus = () => { const { t } = useTranslation() @@ -380,14 +383,25 @@ type LocalDoc = SimpleDocumentDetail & { percent?: number } type IDocumentListProps = { embeddingAvailable: boolean documents: LocalDoc[] + selectedIds: string[] + onSelectedIdChange: (selectedIds: string[]) => void datasetId: string + pagination: PaginationProps onUpdate: () => void } /** * Document list component including basic information */ -const DocumentList: FC = ({ embeddingAvailable, documents = [], datasetId, onUpdate }) => { +const DocumentList: FC = ({ + embeddingAvailable, + documents = [], + selectedIds, + onSelectedIdChange, + datasetId, + pagination, + onUpdate, +}) => { const { t } = useTranslation() const { formatTime } = useTimestamp() const router = useRouter() @@ -426,12 +440,37 @@ const DocumentList: FC = ({ embeddingAvailable, documents = onUpdate() }, [onUpdate]) + const isAllSelected = useMemo(() => { + return localDocs.length > 0 && localDocs.every(doc => selectedIds.includes(doc.id)) + }, [localDocs, selectedIds]) + + const isSomeSelected = useMemo(() => { + return localDocs.some(doc => selectedIds.includes(doc.id)) + }, [localDocs, selectedIds]) + + const onSelectedAll = useCallback(() => { + if (isAllSelected) + onSelectedIdChange([]) + else + onSelectedIdChange(uniq([...selectedIds, ...localDocs.map(doc => doc.id)])) + }, [isAllSelected, localDocs, onSelectedIdChange, selectedIds]) + return ( -
+
- + - {localDocs.map((doc) => { + {localDocs.map((doc, index) => { const isFile = doc.data_source_type === DataSourceType.FILE const fileType = isFile ? doc.data_source_detail_dict?.upload_file?.extension : '' return = ({ embeddingAvailable, documents = onClick={() => { router.push(`/datasets/${datasetId}/documents/${doc.id}`) }}> - +
# +
e.stopPropagation()}> + + # +
+
{t('datasetDocuments.list.table.header.fileName')} @@ -451,7 +490,7 @@ const DocumentList: FC = ({ embeddingAvailable, documents =
{doc.position} +
e.stopPropagation()}> + + { + onSelectedIdChange( + selectedIds.includes(doc.id) + ? selectedIds.filter(id => id !== doc.id) + : [...selectedIds, doc.id], + ) + }} + /> + {/* {doc.position} */} + {index + 1} +
+
@@ -520,6 +576,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 && (