From 67fafedf64eccbb27f8af7dc63ecf249868be86b Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 9 Apr 2025 23:35:53 +0800 Subject: [PATCH] Fix document list sorting problem while filter is off --- lightrag/api/__init__.py | 2 +- .../src/features/DocumentManager.tsx | 151 ++++++++++-------- 2 files changed, 82 insertions(+), 71 deletions(-) diff --git a/lightrag/api/__init__.py b/lightrag/api/__init__.py index 4e3d1ab4..97955f02 100644 --- a/lightrag/api/__init__.py +++ b/lightrag/api/__init__.py @@ -1 +1 @@ -__api_version__ = "0141" +__api_version__ = "0142" diff --git a/lightrag_webui/src/features/DocumentManager.tsx b/lightrag_webui/src/features/DocumentManager.tsx index 306d5566..1ed54b5a 100644 --- a/lightrag_webui/src/features/DocumentManager.tsx +++ b/lightrag_webui/src/features/DocumentManager.tsx @@ -216,33 +216,42 @@ export default function DocumentManager() { }); }, [sortField, sortDirection, showFileName]); + // Define a new type that includes status information + type DocStatusWithStatus = DocStatusResponse & { status: DocStatus }; + const filteredAndSortedDocs = useMemo(() => { if (!docs) return null; - let filteredDocs = { ...docs }; + // Create a flat array of documents with status information + const allDocuments: DocStatusWithStatus[] = []; - if (statusFilter !== 'all') { - filteredDocs = { - ...docs, - statuses: { - pending: [], - processing: [], - processed: [], - failed: [], - [statusFilter]: docs.statuses[statusFilter] || [] - } - }; + if (statusFilter === 'all') { + // When filter is 'all', include documents from all statuses + Object.entries(docs.statuses).forEach(([status, documents]) => { + documents.forEach(doc => { + allDocuments.push({ + ...doc, + status: status as DocStatus + }); + }); + }); + } else { + // When filter is specific status, only include documents from that status + const documents = docs.statuses[statusFilter] || []; + documents.forEach(doc => { + allDocuments.push({ + ...doc, + status: statusFilter + }); + }); } - if (!sortField || !sortDirection) return filteredDocs; + // Sort all documents together if sort field and direction are specified + if (sortField && sortDirection) { + return sortDocuments(allDocuments); + } - const sortedStatuses = Object.entries(filteredDocs.statuses).reduce((acc, [status, documents]) => { - const sortedDocuments = sortDocuments(documents); - acc[status as DocStatus] = sortedDocuments; - return acc; - }, {} as DocsStatusesResponse['statuses']); - - return { ...filteredDocs, statuses: sortedStatuses }; + return allDocuments; }, [docs, sortField, sortDirection, statusFilter, sortDocuments]); // Calculate document counts for each status @@ -641,69 +650,71 @@ export default function DocumentManager() { - {filteredAndSortedDocs?.statuses && Object.entries(filteredAndSortedDocs.statuses).flatMap(([status, documents]) => - documents.map((doc) => ( - - - {showFileName ? ( - <> -
-
- {getDisplayFileName(doc, 30)} -
-
- {doc.file_path} -
-
-
{doc.id}
- - ) : ( + {filteredAndSortedDocs && filteredAndSortedDocs.map((doc) => ( + + + {showFileName ? ( + <>
- {doc.id} + {getDisplayFileName(doc, 30)}
{doc.file_path}
- )} -
- +
{doc.id}
+ + ) : (
- {doc.content_summary} + {doc.id}
- {doc.content_summary} + {doc.file_path}
-
- - {status === 'processed' && ( - {t('documentPanel.documentManager.status.completed')} - )} - {status === 'processing' && ( - {t('documentPanel.documentManager.status.processing')} - )} - {status === 'pending' && {t('documentPanel.documentManager.status.pending')}} - {status === 'failed' && {t('documentPanel.documentManager.status.failed')}} - {doc.error && ( - - ⚠️ - - )} - - {doc.content_length ?? '-'} - {doc.chunks_count ?? '-'} - - {new Date(doc.created_at).toLocaleString()} - - - {new Date(doc.updated_at).toLocaleString()} - -
- ))) - } + )} +
+ +
+
+ {doc.content_summary} +
+
+ {doc.content_summary} +
+
+
+ + {doc.status === 'processed' && ( + {t('documentPanel.documentManager.status.completed')} + )} + {doc.status === 'processing' && ( + {t('documentPanel.documentManager.status.processing')} + )} + {doc.status === 'pending' && ( + {t('documentPanel.documentManager.status.pending')} + )} + {doc.status === 'failed' && ( + {t('documentPanel.documentManager.status.failed')} + )} + {doc.error && ( + + ⚠️ + + )} + + {doc.content_length ?? '-'} + {doc.chunks_count ?? '-'} + + {new Date(doc.created_at).toLocaleString()} + + + {new Date(doc.updated_at).toLocaleString()} + +
+ ))}