From fd26c9118797b2b487f414d1e99e9918b0d32d1f Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 23 Sep 2025 17:20:37 -0300 Subject: [PATCH] fetch task files and display them on knowledge page --- frontend/src/app/knowledge/page.tsx | 60 ++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/knowledge/page.tsx b/frontend/src/app/knowledge/page.tsx index 2b2d9e9f..5155f4e2 100644 --- a/frontend/src/app/knowledge/page.tsx +++ b/frontend/src/app/knowledge/page.tsx @@ -17,11 +17,10 @@ import "@/components/AgGrid/registerAgGridModules"; import "@/components/AgGrid/agGridStyles.css"; import { toast } from "sonner"; import { KnowledgeActionsDropdown } from "@/components/knowledge-actions-dropdown"; +import { StatusBadge } from "@/components/ui/status-badge"; import { DeleteConfirmationDialog } from "../../../components/confirmation-dialog"; import { useDeleteDocument } from "../api/mutations/useDeleteDocument"; -// import { StatusBadge } from "@/components/ui/status-badge"; - // Function to get the appropriate icon for a connector type function getSourceIcon(connectorType?: string) { switch (connectorType) { @@ -46,7 +45,7 @@ function getSourceIcon(connectorType?: string) { function SearchPage() { const router = useRouter(); - const { isMenuOpen } = useTask(); + const { isMenuOpen, files: taskFiles } = useTask(); const { selectedFilter, setSelectedFilter, parsedFilterData, isPanelOpen } = useKnowledgeFilter(); const [selectedRows, setSelectedRows] = useState([]); @@ -63,7 +62,31 @@ function SearchPage() { gridRef.current?.api.setGridOption("quickFilterText", e.target.value); }; - const fileResults = data as File[]; + // Convert TaskFiles to File format and merge with backend results + const taskFilesAsFiles: File[] = taskFiles.map((taskFile) => { + return { + filename: taskFile.filename, + mimetype: taskFile.mimetype, + source_url: taskFile.source_url, + size: taskFile.size, + connector_type: taskFile.connector_type, + status: taskFile.status, + }; + }); + + const backendFiles = data as File[]; + + const filteredTaskFiles = taskFilesAsFiles.filter((taskFile) => { + return ( + taskFile.status !== "active" && + !backendFiles.some( + (backendFile) => backendFile.filename === taskFile.filename, + ) + ); + }); + + // Combine task files first, then backend files + const fileResults = [...backendFiles, ...filteredTaskFiles]; const gridRef = useRef(null); @@ -77,8 +100,9 @@ function SearchPage() { minWidth: 220, cellRenderer: ({ data, value }: CustomCellRendererProps) => { return ( -
{ router.push( `/knowledge/chunks?filename=${encodeURIComponent( @@ -91,7 +115,7 @@ function SearchPage() { {value} -
+ ); }, }, @@ -114,6 +138,7 @@ function SearchPage() { { field: "chunkCount", headerName: "Chunks", + valueFormatter: (params) => params.data?.chunkCount?.toString() || "-", }, { field: "avgScore", @@ -122,21 +147,20 @@ function SearchPage() { cellRenderer: ({ value }: CustomCellRendererProps) => { return ( - {value.toFixed(2)} + {value?.toFixed(2) ?? "-"} ); }, }, - // LOOK HERE LUCAS!!!! - // { - // field: "status", - // headerName: "Status", - // cellRenderer: ({ data }: CustomCellRendererProps) => { - // // Default to 'active' status if no status is provided - // const status = data?.status || "processing"; - // return ; - // }, - // }, + { + field: "status", + headerName: "Status", + cellRenderer: ({ data }: CustomCellRendererProps) => { + // Default to 'active' status if no status is provided + const status = data?.status || "active"; + return ; + }, + }, { cellRenderer: ({ data }: CustomCellRendererProps) => { return ;