Frontend School

Editable Product Inventory Grid

Machine Coding
medium

Editable Product Inventory Grid

Medium
React
Frontend
UI
Data Grid
Editable
State Management

Overview

In many business applications, users need a dynamic and intuitive way to manage data. For an e-commerce platform, efficient inventory management is crucial. This problem focuses on building a core component for such a system: an editable data grid that allows users to update product stock quantities directly within the table.

This exercise will evaluate your ability to design and implement interactive UI components, manage complex component state, and handle user input with appropriate validation, all within a reasonable time budget.

What you need to do / Task

Your primary task is to develop a React component that displays a list of products in a table format, allowing users to edit the 'Stock' quantity for each product.

  1. Render Product Data: Display the provided mock product data in a clean, readable table. Each row should show Product Name, SKU, Stock, and Price.
  2. Enable In-Place Editing: Make the 'Stock' column editable. When a user interacts with a 'Stock' cell (e.g., clicks on it or focuses it), it should transform into an input field displaying the current stock value.
  3. Row-Specific Actions: When a row is in edit mode for its 'Stock' field, two action buttons, 'Save' and 'Cancel', should appear for that specific row. These buttons should only be visible when the row is being edited.
  4. Input Validation: Implement basic validation for the 'Stock' input field. It must accept only non-negative integer values. Invalid input should prevent saving and optionally provide visual feedback.
  5. Persist Changes: Clicking 'Save' should update the product's stock quantity in the component's state and revert the row to view mode.
  6. Discard Changes: Clicking 'Cancel' should discard any unsaved changes for that row and revert it to view mode, restoring the original stock value.
  7. Visual Feedback for Unsaved Changes: Any row where the 'Stock' value has been changed in the input field but not yet 'Saved' (i.e., the 'Save' button is visible) should have a distinct visual indicator (e.g., a different background color or border) to highlight that it has pending modifications.

UI/UX expectations

  • Layout: A clear, well-structured HTML <table> with distinct headers and rows.
  • Interaction: Clicking a 'Stock' cell or an 'Edit' button (if you choose to add one, though not strictly required) should seamlessly transition the cell into an <input type="number"> field.
  • State Visibility: Clearly differentiate between the view state (displaying static text) and the edit state (displaying an input field and action buttons).
  • Buttons: 'Save' and 'Cancel' buttons should be clearly labeled and functional.
  • Accessibility (Basic): Ensure the input field is focusable and allows keyboard input.

Acceptance criteria

  • [ ] The initial product data is correctly displayed in a table.
  • [ ] Clicking on a 'Stock' cell makes it editable, showing an input field.
  • [ ] The input field is pre-populated with the current stock value.
  • [ ] 'Save' and 'Cancel' buttons appear only when a row is in edit mode.
  • [ ] Entering a non-integer or negative value into the 'Stock' input prevents saving.
  • [ ] Clicking 'Save' updates the displayed stock value and removes edit controls.
  • [ ] Clicking 'Cancel' discards changes and reverts the row to its original state, removing edit controls.
  • [ ] Rows with pending, unsaved changes are visually highlighted.

Constraints

Constraints & assumptions

  • Data Source: Use the provided initialProducts mock data. There is no backend API to interact with.
  • Persistence: All data updates should be handled in the client-side React component state only. No actual persistence to a database or local storage is required.
  • Technology: React.js for the UI framework.
  • Styling: Basic CSS for layout and visual cues is sufficient. Focus on functionality over pixel-perfect design.
  • Environment: Modern evergreen browsers.

Out of scope

  • Server-side persistence or API integration.
  • Advanced table features like pagination, sorting, or filtering.
  • Complex form validation libraries or comprehensive error messaging beyond preventing save.
  • Full accessibility features (e.g., ARIA attributes) beyond basic input focus and keyboard interaction.
  • Adding new products or deleting existing ones.

What interviewers evaluate

  • Component Design & State Management: How effectively you manage the UI state (e.g., which row is being edited, pending changes) and structure your React components.
  • Interaction Design: The fluidity and intuitiveness of the user experience for editing, saving, and canceling changes within the grid.
  • Data Handling & Validation: Correct implementation of local state updates and basic input validation logic for the 'Stock' field.
  • Code Quality: Readability, modularity, and maintainability of the React codebase, including appropriate use of hooks and component patterns.

Loading editor...