diff --git a/frontend/src/components/file-renderers/csv-renderer.tsx b/frontend/src/components/file-renderers/csv-renderer.tsx index 7c793410..1577dc2c 100644 --- a/frontend/src/components/file-renderers/csv-renderer.tsx +++ b/frontend/src/components/file-renderers/csv-renderer.tsx @@ -1,190 +1,190 @@ -"use client"; +// "use client"; -import { useState, useEffect, useMemo } from "react"; -import { readString } from "react-papaparse"; -import { ScrollArea } from "@/components/ui/scroll-area"; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import { Input } from "@/components/ui/input"; -import { Button } from "@/components/ui/button"; -import { Search, ChevronLeft, ChevronRight } from "lucide-react"; -import { cn } from "@/lib/utils"; +// import { useState, useEffect, useMemo } from "react"; +// import { readString } from "react-papaparse"; +// import { ScrollArea } from "@/components/ui/scroll-area"; +// import { +// Table, +// TableBody, +// TableCell, +// TableHead, +// TableHeader, +// TableRow, +// } from "@/components/ui/table"; +// import { Input } from "@/components/ui/input"; +// import { Button } from "@/components/ui/button"; +// import { Search, ChevronLeft, ChevronRight } from "lucide-react"; +// import { cn } from "@/lib/utils"; -interface CsvRendererProps { - content: string; - className?: string; -} +// interface CsvRendererProps { +// content: string; +// className?: string; +// } -interface ParsedCsvData { - data: Record[]; - headers: string[]; - errors?: any[]; -} +// interface ParsedCsvData { +// data: Record[]; +// headers: string[]; +// errors?: any[]; +// } -// Define the PapaParse result interface -interface PapaParseResult { - data: Record[]; - errors: { message: string; row: number }[]; - meta: { - delimiter: string; - linebreak: string; - aborted: boolean; - truncated: boolean; - cursor: number; - fields: string[]; - }; -} +// // Define the PapaParse result interface +// interface PapaParseResult { +// data: Record[]; +// errors: { message: string; row: number }[]; +// meta: { +// delimiter: string; +// linebreak: string; +// aborted: boolean; +// truncated: boolean; +// cursor: number; +// fields: string[]; +// }; +// } -export function CsvRenderer({ content, className }: CsvRendererProps) { - const [searchTerm, setSearchTerm] = useState(""); - const [currentPage, setCurrentPage] = useState(1); - const rowsPerPage = 15; +// export function CsvRenderer({ content, className }: CsvRendererProps) { +// const [searchTerm, setSearchTerm] = useState(""); +// const [currentPage, setCurrentPage] = useState(1); +// const rowsPerPage = 15; - // Parse CSV data - const parsedData = useMemo(() => { - if (!content) return { data: [], headers: [] }; +// // Parse CSV data +// const parsedData = useMemo(() => { +// if (!content) return { data: [], headers: [] }; - try { - let headers: string[] = []; - let data: Record[] = []; +// try { +// let headers: string[] = []; +// let data: Record[] = []; - readString(content, { - header: true, - skipEmptyLines: true, - complete: (results: any) => { - if (results.errors && results.errors.length > 0) { - console.error("CSV parsing errors:", results.errors); - } +// readString(content, { +// header: true, +// skipEmptyLines: true, +// complete: (results: any) => { +// if (results.errors && results.errors.length > 0) { +// console.error("CSV parsing errors:", results.errors); +// } - headers = results.meta.fields || []; - data = results.data || []; - }, - error: (error: Error) => { - console.error("CSV parsing error:", error); - } - }); +// headers = results.meta.fields || []; +// data = results.data || []; +// }, +// error: (error: Error) => { +// console.error("CSV parsing error:", error); +// } +// }); - return { - data, - headers, - }; - } catch (error) { - console.error("Failed to parse CSV:", error); - return { data: [], headers: [] }; - } - }, [content]); +// return { +// data, +// headers, +// }; +// } catch (error) { +// console.error("Failed to parse CSV:", error); +// return { data: [], headers: [] }; +// } +// }, [content]); - // Filter data based on search term - const filteredData = useMemo(() => { - if (!searchTerm.trim()) return parsedData.data; +// // Filter data based on search term +// const filteredData = useMemo(() => { +// if (!searchTerm.trim()) return parsedData.data; - const lowerCaseSearchTerm = searchTerm.toLowerCase(); - return parsedData.data.filter((row: Record) => { - return Object.values(row).some((value: any) => { - if (value === null || value === undefined) return false; - return String(value).toLowerCase().includes(lowerCaseSearchTerm); - }); - }); - }, [parsedData.data, searchTerm]); +// const lowerCaseSearchTerm = searchTerm.toLowerCase(); +// return parsedData.data.filter((row: Record) => { +// return Object.values(row).some((value: any) => { +// if (value === null || value === undefined) return false; +// return String(value).toLowerCase().includes(lowerCaseSearchTerm); +// }); +// }); +// }, [parsedData.data, searchTerm]); - // Paginate data - const paginatedData = useMemo(() => { - const startIndex = (currentPage - 1) * rowsPerPage; - return filteredData.slice(startIndex, startIndex + rowsPerPage); - }, [filteredData, currentPage, rowsPerPage]); +// // Paginate data +// const paginatedData = useMemo(() => { +// const startIndex = (currentPage - 1) * rowsPerPage; +// return filteredData.slice(startIndex, startIndex + rowsPerPage); +// }, [filteredData, currentPage, rowsPerPage]); - // Calculate total pages - const totalPages = Math.max(1, Math.ceil(filteredData.length / rowsPerPage)); +// // Calculate total pages +// const totalPages = Math.max(1, Math.ceil(filteredData.length / rowsPerPage)); - // Reset to first page when search changes - useEffect(() => { - setCurrentPage(1); - }, [searchTerm]); +// // Reset to first page when search changes +// useEffect(() => { +// setCurrentPage(1); +// }, [searchTerm]); - return ( -
- {/* Search and pagination controls */} -
-
- - setSearchTerm(e.target.value)} - className="pl-9" - /> -
+// return ( +//
+// {/* Search and pagination controls */} +//
+//
+// +// setSearchTerm(e.target.value)} +// className="pl-9" +// /> +//
-
- +//
+// - - Page {currentPage} of {totalPages} - +// +// Page {currentPage} of {totalPages} +// - -
-
+// +//
+//
- {/* Table */} - -
- - - - {parsedData.headers.map((header, index) => ( - - {header} - - ))} - - - - {paginatedData.length > 0 ? ( - paginatedData.map((row, rowIndex) => ( - - {parsedData.headers.map((header, cellIndex) => ( - - {row[header] || ""} - - ))} - - )) - ) : ( - - - {searchTerm ? "No results found." : "No data available."} - - - )} - -
-
-
-
- ); -} \ No newline at end of file +// {/* Table */} +// +//
+// +// +// +// {parsedData.headers.map((header, index) => ( +// +// {header} +// +// ))} +// +// +// +// {paginatedData.length > 0 ? ( +// paginatedData.map((row, rowIndex) => ( +// +// {parsedData.headers.map((header, cellIndex) => ( +// +// {row[header] || ""} +// +// ))} +// +// )) +// ) : ( +// +// +// {searchTerm ? "No results found." : "No data available."} +// +// +// )} +// +//
+//
+//
+//
+// ); +// } \ No newline at end of file