Frontend School

Editable Tweet Data Grid

Machine Coding
easy

Editable Tweet Data Grid

Easy
React
TypeScript
Data Grid
State Management
UI

Overview

As a product manager at Twitter, you're building a new internal tool for content moderators to quickly review and make minor edits to tweet data. This problem focuses on creating a simplified, interactive data grid where specific tweet attributes can be edited directly within the table interface. This functionality is crucial for maintaining data quality and enabling swift content adjustments.

What you need to do / Task

Your primary task is to build a React component that displays a list of tweets in a table format and allows users to edit certain fields directly within the grid.

  1. Render Tweet Data: Display the provided initial tweet data in a table. Each row should represent a tweet, and columns should display relevant attributes like id, text, author, and likes.
  2. Enable In-Place Editing:
    • The text and likes columns should be editable.
    • When a user clicks or focuses on a cell in these columns, it should transform into an input field (e.g., <input type="text"> for text, <input type="number"> for likes).
    • The id and author columns should remain non-editable.
  3. Save Changes:
    • For each row, provide a "Save" button.
    • When the "Save" button for a row is clicked, the changes made to that specific tweet's text and likes should be "persisted" (i.e., updated in the component's state and reflected in the display).
    • After saving, the input fields should revert to displaying the static text/number.
  4. Display Updated Data: Ensure that after a successful "save", the updated text and likes values are immediately visible in the grid.

UI/UX expectations

  • The data should be presented in a clear HTML <table> structure.
  • Editable cells should visually indicate their editable state (e.g., by transforming into an input field).
  • Non-editable cells should display their content as static text.
  • Each row should have a "Save" button at the end.
  • Basic styling for readability is expected (e.g., table borders, padding).

Acceptance criteria

  • The component renders a table displaying the initial tweet data.
  • The text and likes cells are interactive and can be switched to input fields for editing.
  • The id and author cells are displayed as static text and cannot be edited.
  • Users can modify the content of the text input field.
  • Users can modify the value of the likes number input field.
  • Clicking the "Save" button for a row updates that specific tweet's text and likes in the component's state.
  • After saving, the updated text and likes values are immediately displayed in the table, and the cells revert to a non-editing display mode.

Constraints

Constraints & assumptions

  • You must use React with TypeScript.
  • All state management should be handled client-side within the component (no external state management libraries or backend integration required).
  • The dataset is small (a few tens of rows at most). Performance optimizations for large datasets are not required.
  • Basic HTML semantic elements and CSS for layout are sufficient. No advanced UI frameworks are necessary.
  • No complex input validation (e.g., character limits, specific number ranges) is required beyond what HTML input types provide.

Out of scope

  • Backend API integration for data fetching or persistence.
  • Advanced table features like sorting, filtering, pagination, or column resizing.
  • Complex form validation or error handling.
  • Accessibility features beyond basic semantic HTML.
  • Extensive styling or pixel-perfect UI implementation.

What interviewers evaluate

  • Correct rendering of the data grid with initial and updated data.
  • Effective implementation of in-place editing functionality for specified cells.
  • Appropriate use of React state management to handle user input and save operations.
  • Clean, readable, and idiomatic React/TypeScript code structure.

Loading editor...