diff --git a/frontend/src/components/file-renderers/csv-renderer.tsx b/frontend/src/components/file-renderers/csv-renderer.tsx index 751b20f1..79a8f099 100644 --- a/frontend/src/components/file-renderers/csv-renderer.tsx +++ b/frontend/src/components/file-renderers/csv-renderer.tsx @@ -4,14 +4,12 @@ import React, { useState, useMemo } from 'react'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; +import { CsvTable } from '@/components/ui/csv-table'; import Papa from 'papaparse'; import { cn } from '@/lib/utils'; -import { - Search, - ChevronUp, - ChevronDown, +import { + Search, FileSpreadsheet, - ArrowUpDown, Filter, } from 'lucide-react'; import { @@ -49,8 +47,8 @@ function parseCSV(content: string) { headers = results.meta.fields || []; } - return { - headers, + return { + headers, data: results.data, meta: results.meta }; @@ -68,7 +66,7 @@ export function CsvRenderer({ const [sortConfig, setSortConfig] = useState({ column: '', direction: null }); const [hiddenColumns, setHiddenColumns] = useState>(new Set()); const [currentPage, setCurrentPage] = useState(1); - const [rowsPerPage] = useState(50); + const [rowsPerPage] = useState(50); const parsedData = parseCSV(content); const isEmpty = parsedData.data.length === 0; @@ -88,18 +86,18 @@ export function CsvRenderer({ filtered = [...filtered].sort((a: any, b: any) => { const aVal = a[sortConfig.column]; const bVal = b[sortConfig.column]; - + if (aVal == null && bVal == null) return 0; if (aVal == null) return sortConfig.direction === 'asc' ? -1 : 1; if (bVal == null) return sortConfig.direction === 'asc' ? 1 : -1; - + if (typeof aVal === 'number' && typeof bVal === 'number') { return sortConfig.direction === 'asc' ? aVal - bVal : bVal - aVal; } - + const aStr = String(aVal).toLowerCase(); const bStr = String(bVal).toLowerCase(); - + if (aStr < bStr) return sortConfig.direction === 'asc' ? -1 : 1; if (aStr > bStr) return sortConfig.direction === 'asc' ? 1 : -1; return 0; @@ -139,36 +137,6 @@ export function CsvRenderer({ }); }; - const getSortIcon = (column: string) => { - if (sortConfig.column !== column) { - return ; - } - return sortConfig.direction === 'asc' ? - : - ; - }; - - const formatCellValue = (value: any) => { - if (value == null) return ''; - if (typeof value === 'number') { - return value.toLocaleString(); - } - if (typeof value === 'boolean') { - return value ? 'Yes' : 'No'; - } - return String(value); - }; - - const getCellClassName = (value: any) => { - if (typeof value === 'number') { - return 'text-right font-mono'; - } - if (typeof value === 'boolean') { - return value ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'; - } - return ''; - }; - if (isEmpty) { return (
@@ -199,12 +167,12 @@ export function CsvRenderer({

- +
Page {currentPage} of {totalPages} - + - +
{Array.from({ length: Math.min(5, totalPages) }, (_, i) => { let pageNum; @@ -345,7 +254,7 @@ export function CsvRenderer({ } else { pageNum = currentPage - 2 + i; } - + return ( + */} {onClick && ( +
+ ))} + + {/* Data rows */} + {data.map((row: any, rowIndex) => ( + headers.map((header, cellIndex) => { + const value = row[header]; + return ( +
+
+ {formatCellValue(value)} +
+
+ ); + }) + ))} + + {/* Empty state for search */} + {data.length === 0 && searchTerm && ( +
+
+

No results found for "{searchTerm}"

+ {onClearSearch && ( + + )} +
+
+ )} +
+ + ); +}