Product Inventory Manager: Editable Data Grid
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.
Your primary task is to develop an interactive and editable data grid for managing a list of products. Specifically, you need to:
ID, Name, Category, Price, and Stock.Name, Category, Price, and Stock columns. When a user clicks on a cell in these columns, it should transform into an editable input field.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.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).<table> structure.<input> element. The input should be pre-filled with the current cell's value and receive focus immediately.Name, Category, Price, Stock) correctly converts it into an input field.Enter updates the corresponding product's data in the component's state.Price field only accepts and saves positive numerical values.Stock field only accepts and saves non-negative integer values.Price or Stock are ignored, and the cell reverts to its last valid state.Constraints
useState, useRef, etc.), and event handling.Price and Stock fields.Loading editor...