From 609ef85bbc74bbfea754a2f7e0224e230f50bb1f Mon Sep 17 00:00:00 2001 From: nishika26 Date: Tue, 10 Mar 2026 18:35:41 +0530 Subject: [PATCH 1/2] Docs UI: show recently uploaded/cretaed on the list --- app/api/collections/[collection_id]/route.ts | 2 +- app/document/page.tsx | 9 +++++++-- app/knowledge-base/page.tsx | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/api/collections/[collection_id]/route.ts b/app/api/collections/[collection_id]/route.ts index 5bebdb5..2f42cf8 100644 --- a/app/api/collections/[collection_id]/route.ts +++ b/app/api/collections/[collection_id]/route.ts @@ -19,7 +19,7 @@ export async function GET( try { const response = await fetch( - `${backendUrl}/api/v1/collections/${collection_id}?include_docs=true`, + `${backendUrl}/api/v1/collections/${collection_id}?include_docs=true&include_url=true`, { headers: { 'X-API-KEY': apiKey, diff --git a/app/document/page.tsx b/app/document/page.tsx index f197fff..21fe8e1 100644 --- a/app/document/page.tsx +++ b/app/document/page.tsx @@ -90,8 +90,13 @@ export default function DocumentPage() { file_size: fileSizeMap[doc.id] || doc.file_size })); - console.log('Document list:', documentsWithSize); // Debug log - setDocuments(documentsWithSize); + // Sort by inserted_at in descending order (latest first) + const sortedDocuments = documentsWithSize.sort((a: Document, b: Document) => + new Date(b.inserted_at || 0).getTime() - new Date(a.inserted_at || 0).getTime() + ); + + console.log('Document list:', sortedDocuments); // Debug log + setDocuments(sortedDocuments); } catch (err: any) { console.error('Failed to fetch documents:', err); setError(err.message || 'Failed to fetch documents'); diff --git a/app/knowledge-base/page.tsx b/app/knowledge-base/page.tsx index a26eba7..03de8b8 100644 --- a/app/knowledge-base/page.tsx +++ b/app/knowledge-base/page.tsx @@ -272,7 +272,9 @@ export default function KnowledgeBasePage() { const activeOptimistic = prev.filter( (c) => c.id.startsWith('optimistic-') && (!c.job_id || !fetchedJobIds.has(c.job_id)) ); - return [...activeOptimistic, ...enrichedCollections]; + // Sort by inserted_at in descending order (latest first) + const combined = [...activeOptimistic, ...enrichedCollections]; + return combined.sort((a, b) => new Date(b.inserted_at).getTime() - new Date(a.inserted_at).getTime()); }); // If selectedCollection is optimistic and the real one just arrived, fetch full details @@ -318,7 +320,13 @@ export default function KnowledgeBasePage() { // Handle both direct array and wrapped response const documentList = Array.isArray(result) ? result : (result.data || []); - setAvailableDocuments(documentList); + + // Sort by inserted_at in descending order (latest first) + const sortedDocuments = documentList.sort((a: Document, b: Document) => + new Date(b.inserted_at || 0).getTime() - new Date(a.inserted_at || 0).getTime() + ); + + setAvailableDocuments(sortedDocuments); } else { const error = await response.json().catch(() => ({})); console.error('Failed to fetch documents:', response.status, error); @@ -456,6 +464,11 @@ export default function KnowledgeBasePage() { console.error('Failed to update cache:', e); } } + + // If status is successful, refresh the page + if (status.toLowerCase() === 'successful') { + window.location.reload(); + } } } } catch (error) { From 4f277bdf4a9a6f68d630712e6a138f7045408202 Mon Sep 17 00:00:00 2001 From: nishika26 Date: Tue, 10 Mar 2026 19:35:29 +0530 Subject: [PATCH 2/2] preview docs even when kb creation processing --- app/knowledge-base/page.tsx | 54 +++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/app/knowledge-base/page.tsx b/app/knowledge-base/page.tsx index 03de8b8..c9c4bbd 100644 --- a/app/knowledge-base/page.tsx +++ b/app/knowledge-base/page.tsx @@ -464,11 +464,6 @@ export default function KnowledgeBasePage() { console.error('Failed to update cache:', e); } } - - // If status is successful, refresh the page - if (status.toLowerCase() === 'successful') { - window.location.reload(); - } } } } catch (error) { @@ -1170,9 +1165,30 @@ export default function KnowledgeBasePage() { {selectedCollection.documents && selectedCollection.documents.length > 0 && (