import React, { useState, useEffect, useRef } from 'react'; import { Link } from 'react-router-dom'; import SvgIcon from '../../../components/SvgIcon'; export default function DatasetTab({ knowledgeBase }) { const [searchQuery, setSearchQuery] = useState(''); const [selectedDocuments, setSelectedDocuments] = useState([]); const [selectAll, setSelectAll] = useState(false); const [showBatchDropdown, setShowBatchDropdown] = useState(false); const dropdownRef = useRef(null); // Handle click outside dropdown useEffect(() => { function handleClickOutside(event) { if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { setShowBatchDropdown(false); } } // Add event listener document.addEventListener('mousedown', handleClickOutside); return () => { // Remove event listener on cleanup document.removeEventListener('mousedown', handleClickOutside); }; }, [dropdownRef]); // Mock data for documents in this knowledge base const documents = [ { id: '1001', name: '测试数据集 001', description: '产品相关的所有文档和说明', size: '124kb', updatedAt: '2023-05-15', }, { id: '1002', name: '产品分析数据', description: '技术架构和API文档', size: '89kb', updatedAt: '2023-05-10', }, ]; // Handle select all checkbox const handleSelectAll = () => { if (selectAll) { setSelectedDocuments([]); } else { setSelectedDocuments(documents.map((doc) => doc.id)); } setSelectAll(!selectAll); }; // Handle individual document selection const handleSelectDocument = (docId) => { if (selectedDocuments.includes(docId)) { setSelectedDocuments(selectedDocuments.filter((id) => id !== docId)); setSelectAll(false); } else { setSelectedDocuments([...selectedDocuments, docId]); if (selectedDocuments.length + 1 === documents.length) { setSelectAll(true); } } }; // Handle batch delete const handleBatchDelete = () => { if (selectedDocuments.length === 0) return; // Here you would typically call an API to delete the selected documents console.log('Deleting documents:', selectedDocuments); // Reset selection setSelectedDocuments([]); setSelectAll(false); setShowBatchDropdown(false); }; return ( <> {/* Breadcrumb navigation */}
|
ID | 名称 | 描述 | 文档大小 | 更新日期 | 操作 |
---|---|---|---|---|---|---|
handleSelectDocument(doc.id)}
/>
|
#{doc.id} | {doc.name} | {doc.description} | {doc.size} | {doc.updatedAt} |
|