Fix document list sorting problem while filter is off
This commit is contained in:
@@ -1 +1 @@
|
|||||||
__api_version__ = "0141"
|
__api_version__ = "0142"
|
||||||
|
@@ -216,33 +216,42 @@ export default function DocumentManager() {
|
|||||||
});
|
});
|
||||||
}, [sortField, sortDirection, showFileName]);
|
}, [sortField, sortDirection, showFileName]);
|
||||||
|
|
||||||
|
// Define a new type that includes status information
|
||||||
|
type DocStatusWithStatus = DocStatusResponse & { status: DocStatus };
|
||||||
|
|
||||||
const filteredAndSortedDocs = useMemo(() => {
|
const filteredAndSortedDocs = useMemo(() => {
|
||||||
if (!docs) return null;
|
if (!docs) return null;
|
||||||
|
|
||||||
let filteredDocs = { ...docs };
|
// Create a flat array of documents with status information
|
||||||
|
const allDocuments: DocStatusWithStatus[] = [];
|
||||||
|
|
||||||
if (statusFilter !== 'all') {
|
if (statusFilter === 'all') {
|
||||||
filteredDocs = {
|
// When filter is 'all', include documents from all statuses
|
||||||
...docs,
|
Object.entries(docs.statuses).forEach(([status, documents]) => {
|
||||||
statuses: {
|
documents.forEach(doc => {
|
||||||
pending: [],
|
allDocuments.push({
|
||||||
processing: [],
|
...doc,
|
||||||
processed: [],
|
status: status as DocStatus
|
||||||
failed: [],
|
});
|
||||||
[statusFilter]: docs.statuses[statusFilter] || []
|
});
|
||||||
}
|
});
|
||||||
};
|
} 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]) => {
|
return allDocuments;
|
||||||
const sortedDocuments = sortDocuments(documents);
|
|
||||||
acc[status as DocStatus] = sortedDocuments;
|
|
||||||
return acc;
|
|
||||||
}, {} as DocsStatusesResponse['statuses']);
|
|
||||||
|
|
||||||
return { ...filteredDocs, statuses: sortedStatuses };
|
|
||||||
}, [docs, sortField, sortDirection, statusFilter, sortDocuments]);
|
}, [docs, sortField, sortDirection, statusFilter, sortDocuments]);
|
||||||
|
|
||||||
// Calculate document counts for each status
|
// Calculate document counts for each status
|
||||||
@@ -641,8 +650,7 @@ export default function DocumentManager() {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="text-sm overflow-auto">
|
<TableBody className="text-sm overflow-auto">
|
||||||
{filteredAndSortedDocs?.statuses && Object.entries(filteredAndSortedDocs.statuses).flatMap(([status, documents]) =>
|
{filteredAndSortedDocs && filteredAndSortedDocs.map((doc) => (
|
||||||
documents.map((doc) => (
|
|
||||||
<TableRow key={doc.id}>
|
<TableRow key={doc.id}>
|
||||||
<TableCell className="truncate font-mono overflow-visible max-w-[250px]">
|
<TableCell className="truncate font-mono overflow-visible max-w-[250px]">
|
||||||
{showFileName ? (
|
{showFileName ? (
|
||||||
@@ -679,14 +687,18 @@ export default function DocumentManager() {
|
|||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{status === 'processed' && (
|
{doc.status === 'processed' && (
|
||||||
<span className="text-green-600">{t('documentPanel.documentManager.status.completed')}</span>
|
<span className="text-green-600">{t('documentPanel.documentManager.status.completed')}</span>
|
||||||
)}
|
)}
|
||||||
{status === 'processing' && (
|
{doc.status === 'processing' && (
|
||||||
<span className="text-blue-600">{t('documentPanel.documentManager.status.processing')}</span>
|
<span className="text-blue-600">{t('documentPanel.documentManager.status.processing')}</span>
|
||||||
)}
|
)}
|
||||||
{status === 'pending' && <span className="text-yellow-600">{t('documentPanel.documentManager.status.pending')}</span>}
|
{doc.status === 'pending' && (
|
||||||
{status === 'failed' && <span className="text-red-600">{t('documentPanel.documentManager.status.failed')}</span>}
|
<span className="text-yellow-600">{t('documentPanel.documentManager.status.pending')}</span>
|
||||||
|
)}
|
||||||
|
{doc.status === 'failed' && (
|
||||||
|
<span className="text-red-600">{t('documentPanel.documentManager.status.failed')}</span>
|
||||||
|
)}
|
||||||
{doc.error && (
|
{doc.error && (
|
||||||
<span className="ml-2 text-red-500" title={doc.error}>
|
<span className="ml-2 text-red-500" title={doc.error}>
|
||||||
⚠️
|
⚠️
|
||||||
@@ -702,8 +714,7 @@ export default function DocumentManager() {
|
|||||||
{new Date(doc.updated_at).toLocaleString()}
|
{new Date(doc.updated_at).toLocaleString()}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)))
|
))}
|
||||||
}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user