Frontend School

Interactive Organizational Chart Viewer

Machine Coding
medium

Interactive Organizational Chart Viewer

Medium
React
Frontend
Tree
Data Structures
UI

Overview

At PhonePe, understanding our organizational structure is crucial for collaboration and growth. We need an intuitive tool that allows employees to visualize reporting lines and navigate through the company hierarchy. This problem focuses on building a front-end component to display an interactive organizational chart, making it easy to see who reports to whom and access employee details.

What you need to do / Task

Your task is to build a React component that displays an organizational chart based on a given flat list of employee data. The component should be interactive and meet the following requirements:

  1. Render Hierarchy: Display employees in a hierarchical structure, visually representing their reporting lines.
  2. Employee Cards: Each employee should be represented by a clickable 'card' displaying their name and designation.
  3. Expand/Collapse Functionality: For any employee who is a manager (i.e., has direct reports), provide a toggle to expand or collapse their direct reports. Initially, only the top-level employee(s) and their direct reports should be visible.
  4. Employee Details View: When an employee card is clicked, their full details (e.g., ID, name, designation, manager ID) should be displayed in a dedicated section of the UI.

UI/UX expectations

  • The organizational structure should be clearly visible, possibly using indentation or visual connectors to denote hierarchy.
  • Expand/collapse toggles should be intuitive (e.g., +/- icons or arrow icons).
  • The currently selected employee's card should be visually distinct (e.g., different background color, border).
  • A dedicated, clearly labeled area should display the detailed information of the selected employee.
  • The overall layout should be clean and easy to understand.

Acceptance criteria

  • The root employee(s) and their immediate direct reports are visible on initial load.
  • Clicking a manager's expand/collapse toggle correctly shows/hides their direct reports and all subsequent subordinates.
  • The full hierarchy renders correctly when all nodes are expanded.
  • Clicking any employee card updates the details panel with accurate information for that employee.
  • The UI remains responsive and free of console errors during interactions.
  • The solution is implemented using functional React components and hooks.

Constraints

Constraints & assumptions

  • Employee data will be provided as a flat array of objects, each containing id, name, designation, and managerId. An employee with managerId: null is considered a top-level employee.
  • You can assume there will be a single root employee in the provided data.
  • The maximum depth of the organizational tree will not exceed 7 levels.
  • The total number of employees will be less than 100.
  • No external UI component libraries (e.g., Material UI, Ant Design) are allowed; basic CSS for styling is expected.
  • Focus on functional React components and modern React practices.

Out of scope

  • Backend integration or API calls.
  • Advanced features like search, filtering, or drag-and-drop reordering.
  • Complex routing or deep linking.
  • Full accessibility compliance beyond basic interactive elements.

What interviewers evaluate

  • Ability to parse and render hierarchical data structures effectively in React.
  • Correct implementation of interactive UI elements using React state management.
  • Modular and reusable component design, demonstrating a good understanding of React principles.
  • Clarity, readability, and maintainability of the codebase.

Loading editor...