Frontend School

Interactive Organizational Chart Viewer

Machine Coding
medium

Interactive Organizational Chart Viewer

Medium
React
Tree
Data Visualization
State Management
Recursion
TypeScript

Overview

At Freshworks, understanding team structures and reporting lines is crucial for effective collaboration and management. Visualizing these hierarchies helps employees navigate the organization and understand their place within it. Your task is to build an interactive organizational chart viewer that can display employee relationships and allow users to explore different departments.

What you need to do / Task

  1. Data Transformation: Convert a flat list of Employee objects (each with an id and managerId) into a hierarchical tree structure suitable for rendering.
  2. Render Org Chart: Display the employee hierarchy, starting from the top-level managers (employees with no managerId or whose managerId is not found in the list).
  3. Expand/Collapse Functionality: Implement the ability to expand and collapse sub-teams. Initially, all root-level employees should be visible, and their direct reports should be collapsed.
  4. Employee Details: Each employee node should clearly display at least their name and title.

UI/UX expectations

  • Hierarchy Visualization: Use indentation or other visual cues (e.g., lines) to clearly represent the reporting structure.
  • Expand/Collapse Indicator: An intuitive indicator (e.g., an arrow or +/- icon) should be displayed next to employees who have direct reports. This indicator should visually change to reflect the current expanded/collapsed state.
  • Interactivity: Clicking the indicator should toggle the visibility of that employee's direct reports.
  • Readability: Nodes should be reasonably sized and spaced for good readability.

Acceptance criteria

  • The application renders without any console errors.
  • All employees from the provided dataset are correctly displayed within the hierarchy.
  • Employees without a managerId (or whose managerId does not correspond to an existing employee) are correctly identified and rendered as root nodes.
  • Each employee node clearly displays their name and title.
  • Clicking an expand/collapse indicator correctly toggles the visibility of immediate direct reports.
  • The initial state correctly displays all root nodes, with their direct reports and subsequent levels collapsed.

Constraints

Constraints & assumptions

  • The input data will be a flat array of Employee objects, where managerId links an employee to their manager.
  • An employee can only have one direct manager.
  • managerId will be null or undefined for top-level employees.
  • The dataset size will be relatively small (e.g., up to 50-100 employees), so performance optimization beyond typical React practices is not required.
  • Focus on functional correctness and clean code; extensive, pixel-perfect styling is secondary.
  • You are free to use any standard React hooks and patterns.

Out of scope

  • Drag-and-drop functionality for reorganizing the chart.
  • Advanced search, filtering, or sorting capabilities.
  • Real-time data updates or integration with a backend API.
  • Extensive accessibility features beyond basic semantic HTML elements.

What interviewers evaluate

  • Data Structure & Algorithms: Ability to transform flat data into a hierarchical tree and manage its state.
  • React Proficiency: Effective use of React components, props, state, and hooks (e.g., useState, useMemo).
  • Component Design: Creating reusable and well-structured components for the tree nodes.
  • Code Quality: Readability, maintainability, and adherence to TypeScript best practices.

Loading editor...