yangdx commited on
Commit
82a4723
·
1 Parent(s): b91c1e8

Fix document list sorting problem while filter is off

Browse files
lightrag/api/__init__.py CHANGED
@@ -1 +1 @@
1
- __api_version__ = "0141"
 
1
+ __api_version__ = "0142"
lightrag_webui/src/features/DocumentManager.tsx CHANGED
@@ -216,33 +216,42 @@ export default function DocumentManager() {
216
  });
217
  }, [sortField, sortDirection, showFileName]);
218
 
 
 
 
219
  const filteredAndSortedDocs = useMemo(() => {
220
  if (!docs) return null;
221
 
222
- let filteredDocs = { ...docs };
223
-
224
- if (statusFilter !== 'all') {
225
- filteredDocs = {
226
- ...docs,
227
- statuses: {
228
- pending: [],
229
- processing: [],
230
- processed: [],
231
- failed: [],
232
- [statusFilter]: docs.statuses[statusFilter] || []
233
- }
234
- };
 
 
 
 
 
 
 
 
 
235
  }
236
 
237
- if (!sortField || !sortDirection) return filteredDocs;
238
-
239
- const sortedStatuses = Object.entries(filteredDocs.statuses).reduce((acc, [status, documents]) => {
240
- const sortedDocuments = sortDocuments(documents);
241
- acc[status as DocStatus] = sortedDocuments;
242
- return acc;
243
- }, {} as DocsStatusesResponse['statuses']);
244
 
245
- return { ...filteredDocs, statuses: sortedStatuses };
246
  }, [docs, sortField, sortDirection, statusFilter, sortDocuments]);
247
 
248
  // Calculate document counts for each status
@@ -641,69 +650,71 @@ export default function DocumentManager() {
641
  </TableRow>
642
  </TableHeader>
643
  <TableBody className="text-sm overflow-auto">
644
- {filteredAndSortedDocs?.statuses && Object.entries(filteredAndSortedDocs.statuses).flatMap(([status, documents]) =>
645
- documents.map((doc) => (
646
- <TableRow key={doc.id}>
647
- <TableCell className="truncate font-mono overflow-visible max-w-[250px]">
648
- {showFileName ? (
649
- <>
650
- <div className="group relative overflow-visible tooltip-container">
651
- <div className="truncate">
652
- {getDisplayFileName(doc, 30)}
653
- </div>
654
- <div className="invisible group-hover:visible tooltip">
655
- {doc.file_path}
656
- </div>
657
- </div>
658
- <div className="text-xs text-gray-500">{doc.id}</div>
659
- </>
660
- ) : (
661
  <div className="group relative overflow-visible tooltip-container">
662
  <div className="truncate">
663
- {doc.id}
664
  </div>
665
  <div className="invisible group-hover:visible tooltip">
666
  {doc.file_path}
667
  </div>
668
  </div>
669
- )}
670
- </TableCell>
671
- <TableCell className="max-w-xs min-w-45 truncate overflow-visible">
672
  <div className="group relative overflow-visible tooltip-container">
673
  <div className="truncate">
674
- {doc.content_summary}
675
  </div>
676
  <div className="invisible group-hover:visible tooltip">
677
- {doc.content_summary}
678
  </div>
679
  </div>
680
- </TableCell>
681
- <TableCell>
682
- {status === 'processed' && (
683
- <span className="text-green-600">{t('documentPanel.documentManager.status.completed')}</span>
684
- )}
685
- {status === 'processing' && (
686
- <span className="text-blue-600">{t('documentPanel.documentManager.status.processing')}</span>
687
- )}
688
- {status === 'pending' && <span className="text-yellow-600">{t('documentPanel.documentManager.status.pending')}</span>}
689
- {status === 'failed' && <span className="text-red-600">{t('documentPanel.documentManager.status.failed')}</span>}
690
- {doc.error && (
691
- <span className="ml-2 text-red-500" title={doc.error}>
692
- ⚠️
693
- </span>
694
- )}
695
- </TableCell>
696
- <TableCell>{doc.content_length ?? '-'}</TableCell>
697
- <TableCell>{doc.chunks_count ?? '-'}</TableCell>
698
- <TableCell className="truncate">
699
- {new Date(doc.created_at).toLocaleString()}
700
- </TableCell>
701
- <TableCell className="truncate">
702
- {new Date(doc.updated_at).toLocaleString()}
703
- </TableCell>
704
- </TableRow>
705
- )))
706
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
  </TableBody>
708
  </Table>
709
  </div>
 
216
  });
217
  }, [sortField, sortDirection, showFileName]);
218
 
219
+ // Define a new type that includes status information
220
+ type DocStatusWithStatus = DocStatusResponse & { status: DocStatus };
221
+
222
  const filteredAndSortedDocs = useMemo(() => {
223
  if (!docs) return null;
224
 
225
+ // Create a flat array of documents with status information
226
+ const allDocuments: DocStatusWithStatus[] = [];
227
+
228
+ if (statusFilter === 'all') {
229
+ // When filter is 'all', include documents from all statuses
230
+ Object.entries(docs.statuses).forEach(([status, documents]) => {
231
+ documents.forEach(doc => {
232
+ allDocuments.push({
233
+ ...doc,
234
+ status: status as DocStatus
235
+ });
236
+ });
237
+ });
238
+ } else {
239
+ // When filter is specific status, only include documents from that status
240
+ const documents = docs.statuses[statusFilter] || [];
241
+ documents.forEach(doc => {
242
+ allDocuments.push({
243
+ ...doc,
244
+ status: statusFilter
245
+ });
246
+ });
247
  }
248
 
249
+ // Sort all documents together if sort field and direction are specified
250
+ if (sortField && sortDirection) {
251
+ return sortDocuments(allDocuments);
252
+ }
 
 
 
253
 
254
+ return allDocuments;
255
  }, [docs, sortField, sortDirection, statusFilter, sortDocuments]);
256
 
257
  // Calculate document counts for each status
 
650
  </TableRow>
651
  </TableHeader>
652
  <TableBody className="text-sm overflow-auto">
653
+ {filteredAndSortedDocs && filteredAndSortedDocs.map((doc) => (
654
+ <TableRow key={doc.id}>
655
+ <TableCell className="truncate font-mono overflow-visible max-w-[250px]">
656
+ {showFileName ? (
657
+ <>
 
 
 
 
 
 
 
 
 
 
 
 
658
  <div className="group relative overflow-visible tooltip-container">
659
  <div className="truncate">
660
+ {getDisplayFileName(doc, 30)}
661
  </div>
662
  <div className="invisible group-hover:visible tooltip">
663
  {doc.file_path}
664
  </div>
665
  </div>
666
+ <div className="text-xs text-gray-500">{doc.id}</div>
667
+ </>
668
+ ) : (
669
  <div className="group relative overflow-visible tooltip-container">
670
  <div className="truncate">
671
+ {doc.id}
672
  </div>
673
  <div className="invisible group-hover:visible tooltip">
674
+ {doc.file_path}
675
  </div>
676
  </div>
677
+ )}
678
+ </TableCell>
679
+ <TableCell className="max-w-xs min-w-45 truncate overflow-visible">
680
+ <div className="group relative overflow-visible tooltip-container">
681
+ <div className="truncate">
682
+ {doc.content_summary}
683
+ </div>
684
+ <div className="invisible group-hover:visible tooltip">
685
+ {doc.content_summary}
686
+ </div>
687
+ </div>
688
+ </TableCell>
689
+ <TableCell>
690
+ {doc.status === 'processed' && (
691
+ <span className="text-green-600">{t('documentPanel.documentManager.status.completed')}</span>
692
+ )}
693
+ {doc.status === 'processing' && (
694
+ <span className="text-blue-600">{t('documentPanel.documentManager.status.processing')}</span>
695
+ )}
696
+ {doc.status === 'pending' && (
697
+ <span className="text-yellow-600">{t('documentPanel.documentManager.status.pending')}</span>
698
+ )}
699
+ {doc.status === 'failed' && (
700
+ <span className="text-red-600">{t('documentPanel.documentManager.status.failed')}</span>
701
+ )}
702
+ {doc.error && (
703
+ <span className="ml-2 text-red-500" title={doc.error}>
704
+ ⚠️
705
+ </span>
706
+ )}
707
+ </TableCell>
708
+ <TableCell>{doc.content_length ?? '-'}</TableCell>
709
+ <TableCell>{doc.chunks_count ?? '-'}</TableCell>
710
+ <TableCell className="truncate">
711
+ {new Date(doc.created_at).toLocaleString()}
712
+ </TableCell>
713
+ <TableCell className="truncate">
714
+ {new Date(doc.updated_at).toLocaleString()}
715
+ </TableCell>
716
+ </TableRow>
717
+ ))}
718
  </TableBody>
719
  </Table>
720
  </div>