import React, { Component, ErrorInfo, ReactNode } from 'react'; import { Button } from '../Button'; import { RefreshCw } from 'lucide-react'; /** * Error boundary specifically for DataTable component. * Catches JavaScript errors in the table rendering and provides a fallback UI. * Handles errors from virtualizer, cell renderers, fetch operations, and child components. */ interface DataTableErrorBoundaryState { hasError: boolean; error?: Error; } interface DataTableErrorBoundaryProps { children: ReactNode; onError?: (error: Error) => void; onReset?: () => void; } export class DataTableErrorBoundary extends Component< DataTableErrorBoundaryProps, DataTableErrorBoundaryState > { constructor(props: DataTableErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): DataTableErrorBoundaryState { // Update state to show fallback UI and store error for logging return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { // Log the error (you can also log to an error reporting service) console.error('DataTable Error Boundary caught an error:', error, errorInfo); // Call parent error handler if provided this.props.onError?.(error); } /** * Reset the error state and attempt to re-render the children. * This can be used to retry after a table error (e.g., network retry). */ private handleReset = () => { this.setState({ hasError: false, error: undefined }); this.props.onReset?.(); }; render() { if (this.state.hasError) { // Custom fallback UI for DataTable errors return (

Table Error

Table failed to load. Please refresh or try again.

{/* Optional: Show technical error details in development */} {process.env.NODE_ENV === 'development' && this.state.error && (
Error Details (Dev)
                {this.state.error.message}
              
)}
); } return this.props.children; } } // Named export for convenience export default DataTableErrorBoundary;