diff --git a/lightrag_webui/src/features/DocumentManager.tsx b/lightrag_webui/src/features/DocumentManager.tsx index 11d3b239..7b78df13 100644 --- a/lightrag_webui/src/features/DocumentManager.tsx +++ b/lightrag_webui/src/features/DocumentManager.tsx @@ -33,7 +33,7 @@ import { errorMessage } from '@/lib/utils' import { toast } from 'sonner' import { useBackendState } from '@/stores/state' -import { RefreshCwIcon, ActivityIcon, ArrowUpIcon, ArrowDownIcon, FilterIcon } from 'lucide-react' +import { RefreshCwIcon, ActivityIcon, ArrowUpIcon, ArrowDownIcon, RotateCcwIcon } from 'lucide-react' import PipelineStatusDialog from '@/components/documents/PipelineStatusDialog' type StatusFilter = DocStatus | 'all'; @@ -606,6 +606,62 @@ export default function DocumentManager() { await fetchDocuments() }, [fetchDocuments]) + // Handle manual refresh with pagination reset logic + const handleManualRefresh = useCallback(async () => { + try { + setIsRefreshing(true); + + // Fetch documents from the first page + const request: DocumentsRequest = { + status_filter: statusFilter === 'all' ? null : statusFilter, + page: 1, + page_size: pagination.page_size, + sort_field: sortField, + sort_direction: sortDirection + }; + + const response = await getDocumentsPaginated(request); + + if (!isMountedRef.current) return; + + // Check if total count is less than current page size and page size is not already 10 + if (response.pagination.total_count < pagination.page_size && pagination.page_size !== 10) { + // Reset page size to 10 which will trigger a new fetch + handlePageSizeChange(10); + } else { + // Update pagination state + setPagination(response.pagination); + setCurrentPageDocs(response.documents); + setStatusCounts(response.status_counts); + + // Update legacy docs state for backward compatibility + const legacyDocs: DocsStatusesResponse = { + statuses: { + processed: response.documents.filter(doc => doc.status === 'processed'), + processing: response.documents.filter(doc => doc.status === 'processing'), + pending: response.documents.filter(doc => doc.status === 'pending'), + failed: response.documents.filter(doc => doc.status === 'failed') + } + }; + + if (response.pagination.total_count > 0) { + setDocs(legacyDocs); + } else { + setDocs(null); + } + } + + } catch (err) { + if (isMountedRef.current) { + toast.error(t('documentPanel.documentManager.errors.loadFailed', { error: errorMessage(err) })); + } + } finally { + if (isMountedRef.current) { + setIsRefreshing(false); + } + } + }, [statusFilter, pagination.page_size, sortField, sortDirection, handlePageSizeChange, t]); + // Handle showFileName change - switch sort field if currently sorting by first column useEffect(() => { @@ -707,7 +763,6 @@ export default function DocumentManager() {