Frontend School

Dynamic Dashboard with Lazy-Loaded Tabs

Machine Coding
hard

Dynamic Dashboard with Lazy-Loaded Tabs

Hard
React
TypeScript
UI
Tabs
Dynamic Content
Lazy Loading
State Management

Overview

PhonePe's merchant partners rely on intuitive dashboards to monitor their business performance. This problem focuses on building a crucial part of such a dashboard: a dynamic, tabbed interface that efficiently displays various types of widgets. The challenge lies in handling dynamic content configuration and implementing a lazy-loading strategy for tab content to optimize performance and user experience.

What you need to do / Task

Your goal is to build a React application that renders a dynamic dashboard based on a given configuration. Specifically, you must:

  1. Render Tabs: Display a navigation bar with tabs based on the DASHBOARD_CONFIG provided.
  2. Tab Switching: Implement functionality to switch between tabs, highlighting the currently active tab.
  3. Dynamic Widget Rendering: For the active tab, dynamically render the widgets specified in its configuration (MetricCard, TransactionList). You will need a mechanism to map widget types to their corresponding React components.
  4. Lazy Loading: Implement a lazy-loading strategy where the content (widgets and their data) for a tab is only fetched and rendered when that specific tab becomes active. Content for inactive tabs should not be rendered or fetched.
  5. Loading State: Display a clear loading indicator (e.g., "Loading widgets...") while the content for an active tab is being fetched.

UI/UX expectations

  • The dashboard should have a clear header and a horizontal tab navigation.
  • Tab buttons should be visually distinct, with the active tab clearly highlighted.
  • Widgets within an active tab should be laid out cleanly (e.g., using a grid or flexbox for multiple widgets).
  • A visible loading state should appear when switching to a tab whose content is not yet loaded.
  • MetricCard and TransactionList components should display their respective data in a readable format.

Acceptance criteria

  • The application renders without any console errors.
  • All tabs defined in DASHBOARD_CONFIG are displayed in the tab navigation.
  • Clicking on a tab correctly switches the active tab and updates its visual state.
  • Only widgets belonging to the currently active tab are rendered in the content area.
  • Widgets for inactive tabs are not rendered in the DOM.
  • A loading indicator is shown when a tab that hasn't been loaded before is activated, and disappears once its content is ready.
  • MetricCard widgets correctly display their title, value, label, and trend.
  • TransactionList widgets correctly display their title and a list of transactions with description, amount, and date.
  • The dynamic data fetching (fetchWidgetData) is properly integrated to simulate asynchronous content loading.

Constraints

Constraints & assumptions

  • Use React with TypeScript for the solution.
  • The DASHBOARD_CONFIG is provided as a static JavaScript object and defines the structure of the dashboard.
  • Widget data fetching is simulated using the provided fetchWidgetData utility, which returns mock data asynchronously.
  • Focus on functional components and React Hooks (useState, useEffect, useCallback).
  • No external UI component libraries (e.g., Material UI, Ant Design) are allowed; build components using native HTML elements and CSS.
  • The problem is scoped to rendering, state management, and lazy loading; data persistence, complex routing, or backend integration are out of scope.

Out of scope

  • Advanced accessibility features (beyond basic interactive elements).
  • Full responsiveness for all screen sizes.
  • Implementing actual charting libraries for potential Chart widget types (only MetricCard and TransactionList are required).
  • Robust error handling beyond logging to the console.

What interviewers evaluate

  • Code Structure & Modularity: Clear separation of concerns, reusable components, and adherence to React best practices.
  • State Management: Effective use of React Hooks to manage UI state, active tab, and loaded data efficiently.
  • Dynamic Rendering & Lazy Loading: Correct implementation of conditional rendering based on configuration and the lazy loading mechanism for tab content.
  • TypeScript Usage: Proper type definitions for data structures and components, ensuring type safety throughout the application.
  • Performance Considerations: Avoiding unnecessary re-renders and optimizing data fetching for a smooth user experience.

Loading editor...