From fc5f67e244f02f18523e95824bb7be13d006cdd9 Mon Sep 17 00:00:00 2001 From: Brent O'Neill Date: Mon, 22 Sep 2025 14:23:03 -0600 Subject: [PATCH] Added technical details section --- frontend/src/app/knowledge/chunks/page.tsx | 112 +++++++++++++++++++-- 1 file changed, 101 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/knowledge/chunks/page.tsx b/frontend/src/app/knowledge/chunks/page.tsx index 450032a8..0a5a00a3 100644 --- a/frontend/src/app/knowledge/chunks/page.tsx +++ b/frontend/src/app/knowledge/chunks/page.tsx @@ -7,7 +7,7 @@ import { Loader2, Search, } from "lucide-react"; -import { Suspense, useCallback, useEffect, useState } from "react"; +import { Suspense, useCallback, useEffect, useMemo, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { ProtectedRoute } from "@/components/protected-route"; import { Button } from "@/components/ui/button"; @@ -22,6 +22,12 @@ import { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; +const getFileTypeLabel = (mimetype: string) => { + if (mimetype === "application/pdf") return "PDF"; + if (mimetype === "text/plain") return "Text"; + if (mimetype === "application/msword") return "Word Document"; +}; + function ChunksPageContent() { const router = useRouter(); const searchParams = useSearchParams(); @@ -33,12 +39,21 @@ function ChunksPageContent() { const [chunksFilteredByQuery, setChunksFilteredByQuery] = useState< ChunkResult[] >([]); + const averageChunkLength = useMemo( + () => + chunks.reduce((acc, chunk) => acc + chunk.text.length, 0) / + chunks.length || 0, + [chunks] + ); const [selectAll, setSelectAll] = useState(false); const [queryInputText, setQueryInputText] = useState( parsedFilterData?.query ?? "" ); + // Use the same search query as the knowledge page, but we'll filter for the specific file + const { data = [], isFetching } = useGetSearchQuery("*", parsedFilterData); + useEffect(() => { if (queryInputText === "") { setChunksFilteredByQuery(chunks); @@ -52,13 +67,14 @@ function ChunksPageContent() { }, [queryInputText, chunks]); const handleCopy = useCallback((text: string) => { - console.log("copying text to clipboard:", text); navigator.clipboard.writeText(text); }, []); - // Use the same search query as the knowledge page, but we'll filter for the specific file - const { data = [], isFetching } = useGetSearchQuery("*", parsedFilterData); - console.log({ data }); + const fileData = (data as File[]).find( + (file: File) => file.filename === filename + ); + + console.log({ fileData }); // Extract chunks for the specific file useEffect(() => { if (!filename || !(data as File[]).length) { @@ -66,11 +82,8 @@ function ChunksPageContent() { return; } - const fileData = (data as File[]).find( - (file: File) => file.filename === filename - ); setChunks(fileData?.chunks || []); - }, [data, filename]); + }, [data, filename, fileData?.chunks]); const handleBack = useCallback(() => { router.back(); @@ -90,9 +103,11 @@ function ChunksPageContent() { ); } + console.log({ data }); + return (
*/}
-
+
{chunk.text}
@@ -220,6 +235,81 @@ function ChunksPageContent() { )} + {/* Right panel - Summary (TODO), Technical details, */} +
+
+

Technical details

+
+
+
Total chunks
+
+ {chunks.length} +
+
+
+
Avg length
+
+ {averageChunkLength.toFixed(0)} chars +
+
+
+
Process time
+
+ {/* {averageChunkLength.toFixed(0)} chars */} +
+
+
+
Model
+
+ {/* {averageChunkLength.toFixed(0)} chars */} +
+
+
+
+
+

Original document

+
+
+
Name
+
+ {fileData?.filename} +
+
+
+
Type
+
+ {fileData ? getFileTypeLabel(fileData.mimetype) : "Unknown"} +
+
+
+
Size
+
+ {fileData?.size + ? `${Math.round(fileData.size / 1024)} KB` + : "Unknown"} +
+
+
+
Uploaded
+
+ {fileData?.uploaded || "Unknown"} +
+
+
+
Source
+
+ {/* {fileData?.uploaded || "Unknown"} */} +
+
+
+
Updated
+
+ N/A +
+
+
+
+
); }