Overview
Salesforce applications often require intuitive ways to visualize complex data structures. One common need is to display an organization's hierarchy, allowing users to quickly understand team structures and reporting lines. In this problem, you will build a dynamic Org Chart component that visualizes employee relationships in a tree-like structure, enabling users to explore the hierarchy by expanding and collapsing teams.
What you need to do / Task
Your primary goal is to create a React component that displays an interactive organizational chart based on a flat list of employee data.
- Render the Org Chart Root: Display the top-level employee (CEO/President) as the root of the chart.
- Display Employee Details: For each employee, render their
name and title.
- Implement Expand/Collapse:
- If an employee has direct reports, render a toggle (e.g.,
+ / - icon or an arrow) next to their name.
- Clicking this toggle should expand or collapse their direct reports.
- Visualize Hierarchy: Direct reports should be visually nested (e.g., indented) under their manager to clearly indicate the reporting structure.
- Initial State: The chart should initially render with only the top-level manager's direct reports expanded. All other subsequent levels should be collapsed by default.
UI/UX expectations
- Clear Visual Hierarchy: Use indentation or similar visual cues to distinguish managers from their direct reports.
- Intuitive Toggles: The expand/collapse mechanism should be clear and easy to interact with (e.g., a clickable icon). Consider using
aria-expanded for accessibility.
- Minimalist Design: Focus on functionality and clarity. Basic styling is sufficient.
Acceptance criteria
- The component renders without errors and displays the top-level employee.
- Each employee's name and title are displayed correctly.
- Employees with direct reports show an expand/collapse toggle.
- Clicking an expand toggle reveals the direct reports, nested correctly.
- Clicking a collapse toggle hides the direct reports.
- The initial render correctly shows only the top-level manager's direct reports expanded, with all other branches collapsed.
- All employees from the provided mock data can be reached by expanding their respective managers.