Skip to content

Repository files navigation

Geo Data Dashboard

A React-based Geo Data Dashboard that consumes and visualizes spatial + tabular data. Built with Next.js, shadcn/ui, and Leaflet.

πŸš€ Features

  • Data Table

    • Fetch paginated data from mock API
    • Columns: Project Name, Latitude, Longitude, Status, Last Updated
    • Client-side sorting on all columns
    • Real-time search/filtering across multiple fields
    • Click row to highlight corresponding marker on map
  • Map Integration

    • Interactive map using Leaflet with OpenStreetMap tiles
    • Plot markers using latitude/longitude from table data
    • Click marker to highlight corresponding row in table
    • Visual distinction for selected markers (red) vs default (blue)
    • Auto-centering based on data bounds
  • Performance Optimizations

    • Handles 5k+ rows efficiently using React.memo
    • Memoized filtering and sorting operations
    • Optimized re-renders with useMemo and useCallback
    • Optional pagination mode for very large datasets
  • State Management

    • Local state only (no Redux)
    • Proper separation of UI vs data logic
    • Clean component architecture

πŸ“‹ Prerequisites

  • Node.js 18+
  • npm or yarn

πŸ› οΈ Installation

  1. Clone the repository:
git clone <your-repo-url>
cd geo-data-dashboard
  1. Install dependencies:
npm install
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser

πŸ“ Project Structure

geo-data-dashboard/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ layout.tsx          # Root layout
β”‚   β”‚   β”œβ”€β”€ page.tsx             # Main page (Dashboard)
β”‚   β”‚   └── globals.css          # Global styles + shadcn/ui variables
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ ui/                  # shadcn/ui components
β”‚   β”‚   β”‚   β”œβ”€β”€ button.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ input.tsx
β”‚   β”‚   β”‚   └── table.tsx
β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx        # Main dashboard component
β”‚   β”‚   β”œβ”€β”€ DataTable.tsx        # Table with sorting/filtering
β”‚   β”‚   └── Map.tsx              # Leaflet map component
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ api.ts               # API service functions
β”‚   β”‚   └── utils.ts             # Utility functions (cn helper)
β”‚   └── types/
β”‚       └── index.ts             # TypeScript type definitions
β”œβ”€β”€ components.json              # shadcn/ui configuration
β”œβ”€β”€ package.json
└── README.md

🎨 Tech Stack & Decisions

Framework: Next.js 16

  • Decision: Used Next.js instead of Vite/CRA for better SSR capabilities and built-in optimizations
  • Benefits: Server-side rendering, automatic code splitting, optimized production builds

UI Library: shadcn/ui

  • Decision: Chosen for its modern, accessible, and customizable components
  • Benefits:
    • Copy-paste components (not a dependency)
    • Built on Radix UI primitives
    • Fully customizable with Tailwind CSS
    • TypeScript support out of the box

Map Library: Leaflet + React-Leaflet

  • Decision: Leaflet chosen over Mapbox/OpenLayers for:
    • Free and open-source (no API keys required)
    • Lightweight and performant
    • Excellent React integration via react-leaflet
    • Extensive plugin ecosystem
  • Tile Provider: OpenStreetMap (free, no API key needed)

Styling: Tailwind CSS

  • Decision: Utility-first CSS framework
  • Benefits: Rapid development, consistent design system, built-in dark mode support

State Management: Local State (useState, useMemo, useCallback)

  • Decision: No Redux/Context API for global state
  • Rationale:
    • Simple data flow (fetch β†’ display β†’ interact)
    • Component-level state is sufficient
    • Better performance with local state
    • Easier to understand and maintain

Performance Optimizations

  1. React.memo:

    • Wrapped DataTable and Map components
    • Memoized individual table rows and map markers
    • Prevents unnecessary re-renders
  2. useMemo:

    • Filtered and sorted data computation
    • Map center calculation
    • Icon creation (prevents recreation on each render)
  3. useCallback:

    • Event handlers (onRowClick, onMarkerClick, handleSort)
    • Prevents child component re-renders
  4. Pagination Option:

    • Optional pagination mode for datasets > 50 items
    • Reduces DOM nodes for better performance with 5k+ rows

πŸ”Œ API Integration

The dashboard fetches data from:

https://6986b1548bacd1d773eb8675.mockapi.io/api/geo-data/get-all

The API service (src/lib/api.ts) handles:

  • Fetching all geo data
  • Pagination support (if API supports it)
  • Error handling and data transformation
  • Flexible response format handling

🎯 Key Features Implementation

Table-Map Synchronization

  • Table β†’ Map: Clicking a table row highlights the corresponding marker (red icon)
  • Map β†’ Table: Clicking a marker scrolls to and highlights the corresponding row
  • Visual Feedback: Selected items have distinct styling (border, background color)

Sorting

  • Click column headers to sort
  • Visual indicators (chevrons) show sort direction
  • Supports ascending/descending toggle
  • Works with filtered data

Filtering

  • Real-time search across:
    • Project Name
    • Status
    • Latitude
    • Longitude
  • Client-side filtering for instant results
  • Shows filtered count vs total count

Responsive Design

  • Split-screen layout (table | map)
  • Responsive grid (stacks on mobile)
  • Scrollable table container
  • Full-height map container

πŸ§ͺ Testing the Application

  1. Load Data: Data automatically loads on page mount
  2. Search: Type in the search box to filter results
  3. Sort: Click column headers to sort
  4. Select Row: Click any table row to see marker highlight
  5. Select Marker: Click any map marker to see row highlight
  6. Pagination: Toggle pagination mode for large datasets

πŸ“Š Performance Benchmarks

  • 5,000+ rows: Smooth scrolling and interaction
  • Filtering: Instant results (< 50ms)
  • Sorting: Fast even with large datasets
  • Map Rendering: Efficient marker rendering with memoization

πŸ› Known Issues / Limitations

  1. API Response Format: The mock API response format may vary. The code handles multiple formats but may need adjustment for specific API structures.

  2. Map Tiles: Uses OpenStreetMap tiles which may have rate limits. For production, consider:

    • Using a tile service with API key
    • Implementing tile caching
    • Using Mapbox or other commercial providers
  3. Large Datasets: While optimized for 5k+ rows, extremely large datasets (10k+) may benefit from:

    • Virtual scrolling (react-window)
    • Server-side pagination
    • Data virtualization

πŸš€ Deployment

Build for Production

npm run build
npm start

Deploy to Vercel

  1. Push code to GitHub
  2. Import project in Vercel
  3. Deploy automatically

πŸ“ Development Notes

Adding New Features

  • Components are modular and easy to extend
  • Type definitions in src/types/index.ts
  • API functions in src/lib/api.ts

Customizing Styles

  • shadcn/ui components can be modified in src/components/ui/
  • Global styles in src/app/globals.css
  • Tailwind config can be extended as needed

πŸ‘¨β€πŸ’» Development Time

Estimated Time Spent: ~8-10 hours

  • Setup and configuration: 1 hour
  • Component development: 4 hours
  • Map integration: 2 hours
  • Performance optimization: 1.5 hours
  • Testing and refinement: 1.5 hours

πŸ“„ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments


Note: This project was built as an assignment demonstrating React skills, component architecture, and performance optimization techniques.

Releases

Packages

Contributors

Languages