Frontend School

Swiggy Order Dashboard: Sortable & Filterable Table

Machine Coding
medium

Swiggy Order Dashboard: Sortable & Filterable Table

Medium
Data Table
Sorting
Filtering
React
TypeScript

Overview

At Swiggy, efficient management of orders is crucial for seamless operations. Restaurant partners and internal support teams rely on dashboards to quickly find, sort, and filter orders to address issues, track progress, or analyze performance. This problem simulates building a core component of such a dashboard: a dynamic order list table. Your task is to implement a client-side interactive table that allows users to sort orders and apply various filters, enhancing data visibility and operational efficiency.

What you need to do / Task

Your goal is to build a React component that displays a list of mock Swiggy orders in a table, with the following interactive features:

  1. Display Orders: Render all provided mock order data in a clear table format.
  2. Sortable Columns: Implement client-side sorting for the following columns:
    • Order ID (numeric, but string for 'SWG' prefix, so lexicographical comparison is fine initially)
    • Order Value (numeric)
    • Delivery Time (numeric, representing minutes) Clicking a column header should sort the data in ascending order. Clicking the same header again should reverse the sort order (descending).
  3. Filter by Status: Add a dropdown filter that allows users to view orders based on their status (e.g., "PENDING", "COMPLETED", "CANCELLED"). An "All" option should also be available to clear the status filter.
  4. Search by Customer Name: Implement a text input field that filters the orders dynamically as the user types, matching customerName (case-insensitive, partial match).
  5. Combined Interactions: Ensure that sorting and filtering/searching can be applied simultaneously and correctly. For example, a user should be able to search for a customer, then sort the results by order value.

UI/UX expectations

  • Table Layout: A standard HTML <table> should be used, with distinct header and body sections.
  • Sorting Indicators: Sortable column headers should visually indicate their sortable nature (e.g., via cursor change) and display the current sort direction (e.g., up/down arrow icons).
  • Filter Controls:
    • The status filter should be a <select> dropdown element.
    • The customer name search should be an <input type="text"> element.
  • Readability: Basic styling (e.g., borders, padding) to make the table and controls legible. Focus on functionality over pixel-perfect design.

Acceptance criteria

  • The table renders all mock orders correctly upon initial load.
  • Clicking the 'Order ID' column header sorts orders lexicographically in ascending order, then descending on a second click.
  • Clicking the 'Order Value' column header sorts orders numerically in ascending order, then descending on a second click.
  • Clicking the 'Delivery Time' column header sorts orders numerically in ascending order, then descending on a second click.
  • Selecting a status from the dropdown (e.g., "COMPLETED") correctly filters the table to show only orders with that status.
  • Typing into the customer name search box (e.g., "john") filters the table to show only orders where the customer name contains "john" (case-insensitive).
  • All filters and sorts can be combined, and the resulting data reflects all active criteria correctly.

Constraints

Constraints & assumptions

  • Environment: React (functional components, hooks) with TypeScript.
  • Data Source: All order data will be provided as a local mock array within the App.tsx file. No API calls are required.
  • Data Size: The mock data will contain a small to medium number of orders (e.g., 20-50 entries).
  • Libraries: Do not use external table libraries (e.g., react-table, ag-grid). Implement sorting and filtering logic manually.
  • Styling: Basic CSS for readability is expected. Focus on functionality.
  • Client-side only: All sorting, filtering, and searching must be performed client-side on the provided mock data.

Out of scope

  • Pagination
  • Server-side data fetching or operations
  • Real-time updates or websockets
  • Complex accessibility features beyond standard HTML elements
  • Advanced UI/UX features (e.g., drag-and-drop columns, column resizing)

What interviewers evaluate

  • Correctness and Robustness: Accuracy of sorting and filtering logic, including edge cases (e.g., empty search, no matching results).
  • Code Structure and Readability: Organization of components, state management, use of hooks, and adherence to clean code principles.
  • React Proficiency: Effective use of React's lifecycle, state, and props for building interactive UI.
  • Problem Solving: How well the candidate approaches combining multiple interactive features (sorting, filtering, searching) and manages the derived state.

Loading editor...