fix(webui): resolve document status grouping issue in DocumentManager
- Fix documents being grouped by status after pagination and sorting - Use backend-sorted data directly from currentPageDocs instead of re-grouping - Preserve backend sort order to prevent status-based grouping - Maintain backward compatibility with legacy docs structure - Ensure all sorting fields (file name, dates, ID) work correctly without status grouping The issue occurred because the frontend was re-grouping already-sorted data from the backend by status, breaking the intended sort order. Now documents are displayed in the exact order returned by the backend API. Fixes: Document list sorting by file name was grouping by status instead of maintaining proper sort order across all documents.
This commit is contained in:
parent
d3623cc9ae
commit
7db788aa66
1 changed files with 12 additions and 2 deletions
|
|
@ -183,7 +183,7 @@ export default function DocumentManager() {
|
|||
const setDocumentsPageSize = useSettingsStore.use.setDocumentsPageSize()
|
||||
|
||||
// New pagination state
|
||||
const [, setCurrentPageDocs] = useState<DocStatusResponse[]>([])
|
||||
const [currentPageDocs, setCurrentPageDocs] = useState<DocStatusResponse[]>([])
|
||||
const [pagination, setPagination] = useState<PaginationInfo>({
|
||||
page: 1,
|
||||
page_size: documentsPageSize,
|
||||
|
|
@ -292,6 +292,16 @@ export default function DocumentManager() {
|
|||
type DocStatusWithStatus = DocStatusResponse & { status: DocStatus };
|
||||
|
||||
const filteredAndSortedDocs = useMemo(() => {
|
||||
// Use currentPageDocs directly if available (from paginated API)
|
||||
// This preserves the backend's sort order and prevents status grouping
|
||||
if (currentPageDocs && currentPageDocs.length > 0) {
|
||||
return currentPageDocs.map(doc => ({
|
||||
...doc,
|
||||
status: doc.status as DocStatus
|
||||
})) as DocStatusWithStatus[];
|
||||
}
|
||||
|
||||
// Fallback to legacy docs structure for backward compatibility
|
||||
if (!docs) return null;
|
||||
|
||||
// Create a flat array of documents with status information
|
||||
|
|
@ -324,7 +334,7 @@ export default function DocumentManager() {
|
|||
}
|
||||
|
||||
return allDocuments;
|
||||
}, [docs, sortField, sortDirection, statusFilter, sortDocuments]);
|
||||
}, [currentPageDocs, docs, sortField, sortDirection, statusFilter, sortDocuments]);
|
||||
|
||||
// Calculate current page selection state (after filteredAndSortedDocs is defined)
|
||||
const currentPageDocIds = useMemo(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue