'use client'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import type { WidgetConfig, TableData, TableWidgetConfig } from '@/lib/pipeline-types'; import { WidgetWrapper } from './WidgetWrapper'; interface DataTableWidgetProps { config: WidgetConfig; data: TableData | null; loading: boolean; error?: string; onRefresh?: () => void; onPageChange?: (page: number) => void; currentPage?: number; } /** * Data table widget with pagination. */ export function DataTableWidget({ config, data, loading, error, onRefresh, onPageChange, currentPage = 1, }: DataTableWidgetProps) { const tableConfig = config.config as unknown as TableWidgetConfig; const rows = data?.data || []; const total = data?.total || 0; const pageSize = tableConfig.page_size || 10; const totalPages = Math.ceil(total / pageSize); return ( {rows.length === 0 ? (
No data available
) : (
{/* Table */}
{tableConfig.columns.map((col) => ( ))} {rows.map((row, rowIndex) => ( {tableConfig.columns.map((col) => ( ))} ))}
{col.header}
{formatCellValue(row[col.key], col.format)}
{/* Pagination */} {tableConfig.show_pagination !== false && totalPages > 1 && onPageChange && (
Showing {(currentPage - 1) * pageSize + 1} to{' '} {Math.min(currentPage * pageSize, total)} of {total}
Page {currentPage} of {totalPages}
)}
)}
); } function formatCellValue(value: unknown, format?: string): string { if (value === null || value === undefined) return '-'; if (typeof value === 'number') { if (format?.includes('%')) { return `${value.toFixed(1)}%`; } return value.toLocaleString(); } return String(value); }