diff --git a/web/app/components/datasets/documents/index.tsx b/web/app/components/datasets/documents/index.tsx index 99de8cbed5..1bf82c9fa6 100644 --- a/web/app/components/datasets/documents/index.tsx +++ b/web/app/components/datasets/documents/index.tsx @@ -195,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 }) @@ -249,6 +249,8 @@ const Documents: FC = ({ datasetId }) => { embeddingAvailable={embeddingAvailable} documents={documentsList || []} datasetId={datasetId} onUpdate={mutate} + selectedIds={selectedIds} + onSelectedIdChange={setSelectedIds} pagination={{ total, limit, diff --git a/web/app/components/datasets/documents/list.tsx b/web/app/components/datasets/documents/list.tsx index cd419847fc..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, @@ -41,6 +41,7 @@ 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() @@ -382,6 +383,8 @@ type LocalDoc = SimpleDocumentDetail & { percent?: number } type IDocumentListProps = { embeddingAvailable: boolean documents: LocalDoc[] + selectedIds: string[] + onSelectedIdChange: (selectedIds: string[]) => void datasetId: string pagination: PaginationProps onUpdate: () => void @@ -393,6 +396,8 @@ type IDocumentListProps = { const DocumentList: FC = ({ embeddingAvailable, documents = [], + selectedIds, + onSelectedIdChange, datasetId, pagination, onUpdate, @@ -435,12 +440,37 @@ const DocumentList: FC = ({ 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 = ({ onClick={() => { router.push(`/datasets/${datasetId}/documents/${doc.id}`) }}> - +
# +
e.stopPropagation()}> + + # +
+
{t('datasetDocuments.list.table.header.fileName')} @@ -460,7 +490,7 @@ const DocumentList: FC = ({
{doc.position} +
e.stopPropagation()}> + + { + onSelectedIdChange( + selectedIds.includes(doc.id) + ? selectedIds.filter(id => id !== doc.id) + : [...selectedIds, doc.id], + ) + }} + /> + {/* {doc.position} */} + {index + 1} +
+