A performant React table application built with TanStack Table, featuring character data management with selection, filtering, sorting, and searching capabilities.
- High-Performance Table: Renders 1000+ character entries efficiently using TanStack Table
- Row Selection: Checkbox-based selection with "Select All" functionality
- Real-time Search: Search characters by name or location with instant filtering
- Health Filtering: Dropdown filter for character health status (Healthy, Injured, Critical)
- Power Sorting: Sortable power column with ascending/descending toggle
- Submit Action: Console logging of selected character IDs
- Loading States: Proper loading indicators during data fetch
- Accessibility: ARIA labels, keyboard navigation, and screen reader support
- TypeScript: Fully typed codebase with proper type definitions
- Modern UI: Built with shadcn/ui components and Tailwind CSS
- JSON Server: Mock API with 1200+ character entries
- Comprehensive Testing: Jest/Vitest tests covering all functionality
- Modular Architecture: Clean separation of concerns with custom hooks
- Performance Optimized: Efficient rendering and state management
- Frontend: React 19, TypeScript, Vite
- UI Components: shadcn/ui, Tailwind CSS, Lucide React icons
- Table Management: TanStack Table v8
- Virtualization: react-virtuoso for performance
- State Management: React hooks (useState, useEffect, useMemo)
- API: JSON Server for mock data
- Testing: Vitest, React Testing Library, Jest DOM
- Code Quality: Biome (linting & formatting)
-
Install dependencies
npm install
-
Set up environment variables
npm run setup-env:dev
-
Generate character data
npm run generate-data
-
Start the development server and the JSON server
npm run dev
-
Open your browser Navigate to
http://localhost:3000/demo/table
-
Search Characters
- Use the search input to filter by character name or location
- Search is case-insensitive and updates in real-time
-
Select Rows
- Click individual checkboxes to select specific characters
- Use the header checkbox to select/deselect all visible rows
- Selected count is displayed in the submit button
-
Filter by Health
- Click the filter icon next to "Health" column header
- Select one or more health statuses (Healthy, Injured, Critical)
- Multiple selections are supported
-
Sort by Power
- Click the chevron icon next to "Power" column header
- Toggle between ascending and descending order
- Visual indicators show current sort direction
-
Submit Selection
- Click "Submit Selected" button to log selected character IDs
- Button is disabled when no rows are selected
- Selected IDs are logged to browser console
-
Virtual Scrolling
- Table automatically virtualizes rows using react-virtuoso for optimal performance
- Only visible rows are rendered in the DOM
- Smooth scrolling through 1200+ characters
- Virtualization info displayed at the bottom
Run the test suite:
npm test- Component Tests: Table rendering, interactions, and state management
- Hook Tests: Data fetching, error handling, and loading states
- User Interactions: Search, selection, filtering, and sorting
- Accessibility: ARIA labels and keyboard navigation
src/
βββ components/
β βββ ui/ # shadcn/ui components
β βββ global/ # Reusable global components
β β βββ DataTable.tsx # Core table with virtualization
β β βββ DataTableToolbar.tsx # Search, filters, and actions
β β βββ columns.tsx # Column definitions
β β βββ __tests__/ # Global component tests
β βββ pages/ # Page-specific components
β β βββ CharacterTable.tsx # Main table component (orchestrator)
β β βββ __tests__/ # Page component tests
β βββ __tests__/ # General component tests
βββ config/ # Configuration files
β βββ api.ts # API configuration
β βββ environment.ts # Environment variables
βββ data/
β βββ characters.ts # Character data types and generation
β βββ demo-table-data.ts # Demo data for testing
βββ hooks/
β βββ useCharacters.ts # Data fetching hook
β βββ useDebounce.ts # Debounce utility hook
β βββ __tests__/ # Hook tests
βββ integrations/
β βββ tanstack-query/ # TanStack Query setup
β βββ devtools.tsx # Query devtools
β βββ root-provider.tsx # Query provider
βββ routes/
β βββ __root.tsx # Root route with devtools
β βββ index.tsx # Home route (redirects to table)
β βββ demo.table.tsx # Table demo route
βββ lib/
β βββ utils.ts # Utility functions
βββ main.tsx # Application entry point
βββ styles.css # Global styles
βββ test-setup.ts # Test configuration
interface Character {
id: string; // Unique identifier
name: string; // Character full name
location: "Konoha" | "Suna" | "Kiri" | "Iwa" | "Kumo";
health: "Healthy" | "Injured" | "Critical";
power: number; // Min: 100, Max: 10,000
viewed: boolean; // Default: false
}- react-virtuoso: Efficient virtualization for rendering 1000+ rows
- Virtual Scrolling: Only renders visible rows in the viewport
- Smart Fallback: Graceful degradation in test environments
- Memoized Components: Optimized re-rendering with React.memo
- Debounced Search: Reduced API calls during typing
- Lazy Loading: Components loaded on demand
- Optimized Filters: Client-side filtering for instant results
The table follows the shadcn/ui tasks example pattern with clear separation of concerns:
- Main component that coordinates all table functionality
- Manages state for search, filters, and selection
- Handles data filtering and business logic
- Search input with real-time filtering
- Health status filter dropdown with badges
- Reset filters functionality
- Submit selected button with count
- Handles table rendering with TanStack Table
- Implements virtualization with react-virtuoso
- Manages row selection and sorting
- Provides fallback rendering for tests
- Centralized column configuration
- Reusable column definitions
- Type-safe column accessors
- Custom cell renderers and headers
The application uses a simplified routing structure:
/- Redirects to/demo/table/demo/table- Main table demo with all features- Root Layout - Includes TanStack DevTools for development
- Single Table Element: Fixed the previous issue of having separate table elements for header and body
- Sticky Header: Header stays visible while scrolling through virtualized rows
- Clean Navigation: Removed unnecessary routes and header component
- Direct Access: Home route automatically redirects to the table demo
npm run dev- Start development servernpm run build- Build for productionnpm run build:netlify- Build for Netlify deployment (includes embedded data)npm run test- Run test suitenpm run json-server- Start JSON server (development only)npm run generate-data- Generate character datanpm run generate-embedded-data- Generate embedded data for Netlify functionsnpm run test:netlify- Test Netlify function locallynpm run setup-env- Set up environment variables (default: development)npm run setup-env:dev- Set up development environment variablesnpm run setup-env:prod- Set up production environment variablesnpm run lint- Run linternpm run format- Format code
The application uses environment variables for configuration. Set up your environment:
# Quick setup for development
npm run setup-env:dev
# Quick setup for production
npm run setup-env:prodVITE_API_BASE_URL- API server URL (default: auto-detected)VITE_DEV_MODE- Enable development featuresVITE_ENABLE_DEVTOOLS- Enable development tools
See env.example for all available variables.
The application can be deployed to any static hosting service:
-
Build the application
npm run build
-
Deploy the
distfolder to your hosting service -
Ensure JSON server is running or replace with a real API
GET /characters- Fetch all charactersGET /characters/:id- Fetch specific characterPOST /characters- Create new characterPUT /characters/:id- Update characterDELETE /characters/:id- Delete character
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
This project is part of a frontend engineering assignment and is for demonstration purposes.
β
JSON Server: 1200+ unique character entries
β
Selection Column: Checkbox-based row selection
β
Health Filter: Dropdown with multiple selection
β
Power Sorting: Ascending/descending toggle
β
Real-time Search: Name and location filtering
β
Submit Button: Console logging of selected IDs
β
Loading States: Proper loading indicators
β
Accessibility: ARIA labels and keyboard support
β
Performance: Optimized for 1000+ rows
β
Testing: Comprehensive Jest test suite
β
TypeScript: Fully typed codebase
β
Clean Code: Modular, maintainable architecture
https://dope-security-fe-assignment-vibhor-sharma.netlify.app/