Frontend School

Product Inventory Manager: Editable Data Grid

Machine Coding
medium

Product Inventory Manager: Editable Data Grid

Medium
React
Data Grid
Editable Table
UI
State Management
Forms

Overview

In many enterprise applications, users frequently need to view and modify data directly within a tabular format. This problem simulates building a core component for a product inventory management system, where an administrative user can quickly update product details like name, category, price, and stock levels. This exercise tests your ability to manage component state, handle user input, and implement basic data validation in a dynamic UI.

What you need to do / Task

Your primary task is to develop an interactive and editable data grid for managing a list of products. Specifically, you need to:

  1. Display Products: Render a table that displays the provided product data with columns for ID, Name, Category, Price, and Stock.
  2. In-place Editing: Enable in-place editing for the Name, Category, Price, and Stock columns. When a user clicks on a cell in these columns, it should transform into an editable input field.
  3. Save Changes: When an input field loses focus (on blur) or the Enter key is pressed, the edited value should be saved to the component's internal state. The cell should then revert to displaying the static text.
  4. Data Validation: Implement basic validation for the editable fields:
    • Price: Must be a positive number (greater than 0).
    • Stock: Must be a non-negative integer (greater than or equal to 0). If validation fails, the change should not be saved, and the cell should revert to its previous valid state. (No explicit error message UI is required, simply prevent invalid saves).
  5. Global Save: Add a "Save All Changes" button below the table. When clicked, this button should log the entire current state of the product data (the array of products with all applied edits) to the console.

UI/UX expectations

  • The product data should be presented in a clear HTML <table> structure.
  • Table headers should be distinct and descriptive.
  • When an editable cell is clicked, it should visually transform into an <input> element. The input should be pre-filled with the current cell's value and receive focus immediately.
  • After editing and saving, the cell should revert to displaying the text value.
  • A "Save All Changes" button should be present below the table.

Acceptance criteria

  • The initial mock product data is correctly displayed in a table format.
  • Clicking on an editable cell (Name, Category, Price, Stock) correctly converts it into an input field.
  • Editing a cell and then blurring the input or pressing Enter updates the corresponding product's data in the component's state.
  • The Price field only accepts and saves positive numerical values.
  • The Stock field only accepts and saves non-negative integer values.
  • Invalid inputs for Price or Stock are ignored, and the cell reverts to its last valid state.
  • The "Save All Changes" button, when clicked, outputs the complete, current product data array to the browser console.

Constraints

Constraints & assumptions

  • You should use React for this implementation.
  • The provided mock data is static; there is no need to make API calls or persist data beyond the component's state.
  • Focus on functional components and React hooks for state management.
  • No pagination, sorting, or filtering functionality is required.
  • The visual styling can be minimal, focusing on functionality.

Out of scope

  • Backend integration or data persistence.
  • Complex error feedback UI (e.g., red borders on invalid input).
  • Advanced accessibility features beyond basic focus management.
  • Performance optimization for large datasets (assume small, manageable data).

What interviewers evaluate

  • React Fundamentals: Correct usage of React components, state management (useState, useRef, etc.), and event handling.
  • Component Design: Logical separation of concerns and a clear, maintainable component structure.
  • Interaction Handling: Effective implementation of in-place editing, input focus management, and saving logic.
  • Data Validation: Correct application of validation rules for Price and Stock fields.
  • Code Quality: Readability, organization, and adherence to best practices.

Loading editor...