Frontend School

Interactive Flight Itinerary Tree View

Machine Coding
medium

Interactive Flight Itinerary Tree View

Medium
Tree View
Recursion
State Management
UI Components

Overview

Flight booking often involves complex multi-leg journeys, and presenting this information clearly and interactively is crucial for user experience. This problem challenges you to build a reusable component that displays a hierarchical flight itinerary in a collapsible tree-like structure, allowing users to easily navigate and understand their journey details.

What you need to do / Task

Your primary task is to implement the ItineraryTreeView component that visualizes a given hierarchical flight itinerary.

  1. Render Tree Structure: Display the provided itineraryData (an array of TreeNode objects) as a nested list, representing the hierarchical nature of the flight journey.
  2. Expand/Collapse Functionality: Implement interactivity such that clicking on a parent node's label or an associated icon toggles the visibility of its children.
  3. State Management: Maintain the expanded/collapsed state for each node independently.
  4. Visual Indicators: Provide clear visual cues (e.g., an arrow icon) to indicate whether a node is currently expanded or collapsed.
  5. Node Details Display: For each node, display its label. If details are provided, display them as secondary information.

UI/UX expectations

  • Hierarchy: Use indentation to clearly distinguish between parent and child nodes (e.g., Journey > Leg > Segment).
  • Toggle Control: A clickable area (e.g., an arrow icon or the node label itself) should toggle the visibility of children.
  • Icons: Use simple arrow icons (e.g., ▶ for collapsed, ▼ for expanded) or similar visual elements.
  • Readability: Ensure the text is readable and the layout is clean. Basic styling is expected to achieve this.

Acceptance criteria

  • The root Journey nodes are rendered at the top level.
  • Leg nodes are indented relative to their parent Journey node.
  • Segment nodes are indented relative to their parent Leg node.
  • Clicking on a node with children toggles their visibility (expands if collapsed, collapses if expanded).
  • Each node correctly displays its label.
  • If a node has details, they are displayed alongside the label.
  • A visual indicator (e.g., an arrow) correctly reflects the current expanded/collapsed state of each node.
  • The component should handle multiple root Journey nodes correctly.

Constraints

Constraints & assumptions

  • The input data structure will always conform to the TreeNode interface provided.
  • The tree depth will not exceed 3 levels (Journey -> Leg -> Segment).
  • Performance for very large trees is not a primary concern for this problem, given the typical size of a flight itinerary.
  • You are free to use functional components and React Hooks.
  • No external UI libraries (e.g., Ant Design, Material UI) are allowed; implement styling and interactivity from scratch.

Out of scope

  • Accessibility (ARIA attributes, keyboard navigation) beyond basic clickable elements.
  • Complex animations for expand/collapse.
  • Persistence of expanded states across component unmounts/remounts.
  • Dynamic loading of tree nodes.
  • Error handling for malformed data.

What interviewers evaluate

  • Component Design: How well the problem is broken down into reusable and manageable components.
  • State Management: Effective use of React state and props to manage the tree's interactive behavior.
  • Logical Correctness: Accurate rendering of the hierarchy and correct implementation of expand/collapse functionality.
  • Code Quality: Readability, maintainability, and adherence to good React practices.

Loading editor...