Added technical details section
This commit is contained in:
parent
a5e4e54811
commit
fc5f67e244
1 changed files with 101 additions and 11 deletions
|
|
@ -7,7 +7,7 @@ import {
|
||||||
Loader2,
|
Loader2,
|
||||||
Search,
|
Search,
|
||||||
} from "lucide-react";
|
} 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 { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { ProtectedRoute } from "@/components/protected-route";
|
import { ProtectedRoute } from "@/components/protected-route";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
@ -22,6 +22,12 @@ import { Label } from "@/components/ui/label";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { Input } from "@/components/ui/input";
|
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() {
|
function ChunksPageContent() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
@ -33,12 +39,21 @@ function ChunksPageContent() {
|
||||||
const [chunksFilteredByQuery, setChunksFilteredByQuery] = useState<
|
const [chunksFilteredByQuery, setChunksFilteredByQuery] = useState<
|
||||||
ChunkResult[]
|
ChunkResult[]
|
||||||
>([]);
|
>([]);
|
||||||
|
const averageChunkLength = useMemo(
|
||||||
|
() =>
|
||||||
|
chunks.reduce((acc, chunk) => acc + chunk.text.length, 0) /
|
||||||
|
chunks.length || 0,
|
||||||
|
[chunks]
|
||||||
|
);
|
||||||
|
|
||||||
const [selectAll, setSelectAll] = useState(false);
|
const [selectAll, setSelectAll] = useState(false);
|
||||||
const [queryInputText, setQueryInputText] = useState(
|
const [queryInputText, setQueryInputText] = useState(
|
||||||
parsedFilterData?.query ?? ""
|
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(() => {
|
useEffect(() => {
|
||||||
if (queryInputText === "") {
|
if (queryInputText === "") {
|
||||||
setChunksFilteredByQuery(chunks);
|
setChunksFilteredByQuery(chunks);
|
||||||
|
|
@ -52,13 +67,14 @@ function ChunksPageContent() {
|
||||||
}, [queryInputText, chunks]);
|
}, [queryInputText, chunks]);
|
||||||
|
|
||||||
const handleCopy = useCallback((text: string) => {
|
const handleCopy = useCallback((text: string) => {
|
||||||
console.log("copying text to clipboard:", text);
|
|
||||||
navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(text);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Use the same search query as the knowledge page, but we'll filter for the specific file
|
const fileData = (data as File[]).find(
|
||||||
const { data = [], isFetching } = useGetSearchQuery("*", parsedFilterData);
|
(file: File) => file.filename === filename
|
||||||
console.log({ data });
|
);
|
||||||
|
|
||||||
|
console.log({ fileData });
|
||||||
// Extract chunks for the specific file
|
// Extract chunks for the specific file
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!filename || !(data as File[]).length) {
|
if (!filename || !(data as File[]).length) {
|
||||||
|
|
@ -66,11 +82,8 @@ function ChunksPageContent() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileData = (data as File[]).find(
|
|
||||||
(file: File) => file.filename === filename
|
|
||||||
);
|
|
||||||
setChunks(fileData?.chunks || []);
|
setChunks(fileData?.chunks || []);
|
||||||
}, [data, filename]);
|
}, [data, filename, fileData?.chunks]);
|
||||||
|
|
||||||
const handleBack = useCallback(() => {
|
const handleBack = useCallback(() => {
|
||||||
router.back();
|
router.back();
|
||||||
|
|
@ -90,9 +103,11 @@ function ChunksPageContent() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log({ data });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`fixed inset-0 md:left-72 top-[53px] flex flex-col transition-all duration-300 ${
|
className={`fixed inset-0 md:left-72 top-[53px] flex flex-row transition-all duration-300 ${
|
||||||
isMenuOpen && isPanelOpen
|
isMenuOpen && isPanelOpen
|
||||||
? "md:right-[704px]"
|
? "md:right-[704px]"
|
||||||
: // Both open: 384px (menu) + 320px (KF panel)
|
: // Both open: 384px (menu) + 320px (KF panel)
|
||||||
|
|
@ -210,7 +225,7 @@ function ChunksPageContent() {
|
||||||
</span> */}
|
</span> */}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<blockquote className="text-sm text-muted-foreground leading-relaxed">
|
<blockquote className="text-sm text-muted-foreground leading-relaxed border-l-2 border-color-input ml-1.5 pl-4">
|
||||||
{chunk.text}
|
{chunk.text}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -220,6 +235,81 @@ function ChunksPageContent() {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/* Right panel - Summary (TODO), Technical details, */}
|
||||||
|
<div className="w-[320px] py-20 px-2">
|
||||||
|
<div className="mb-8">
|
||||||
|
<h2 className="text-xl font-semibold mt-3 mb-4">Technical details</h2>
|
||||||
|
<dl>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Total chunks</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{chunks.length}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Avg length</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{averageChunkLength.toFixed(0)} chars
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Process time</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{/* {averageChunkLength.toFixed(0)} chars */}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Model</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{/* {averageChunkLength.toFixed(0)} chars */}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div className="mb-8">
|
||||||
|
<h2 className="text-xl font-semibold mt-2 mb-3">Original document</h2>
|
||||||
|
<dl>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Name</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{fileData?.filename}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Type</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{fileData ? getFileTypeLabel(fileData.mimetype) : "Unknown"}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Size</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{fileData?.size
|
||||||
|
? `${Math.round(fileData.size / 1024)} KB`
|
||||||
|
: "Unknown"}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Uploaded</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{fileData?.uploaded || "Unknown"}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Source</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
{/* {fileData?.uploaded || "Unknown"} */}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 mb-2.5">
|
||||||
|
<dt className="text-sm/6 text-muted-foreground">Updated</dt>
|
||||||
|
<dd className="mt-1 text-sm/6 text-gray-100 sm:col-span-2 sm:mt-0">
|
||||||
|
N/A
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue