Skip to content

Comments

Add category badges to product tiles#1236

Open
maxkosty wants to merge 2 commits intomasterfrom
add-category-badges-2
Open

Add category badges to product tiles#1236
maxkosty wants to merge 2 commits intomasterfrom
add-category-badges-2

Conversation

@maxkosty
Copy link
Collaborator

Display category badges next to each product in the list on /products page

Testing

tested locally works for me

@maxkosty maxkosty requested a review from ndmanvar as a code owner January 28, 2026 00:53
).toFixed(1);

// Add category badge to product tiles
const categoryBadge = product.category.name.toUpperCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The code accesses product.category.name, but the product object from the API lacks a category property. This will cause a runtime error and crash the page.
Severity: CRITICAL

Suggested Fix

The product object does not contain a category property. Either remove the line that accesses product.category.name or update the backend API and database schema to include category information for each product. If categories are not yet implemented, conditionally render the badge only if product.category exists.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: react/src/components/Products.jsx#L142

Potential issue: The code at `react/src/components/Products.jsx:142` attempts to access
`product.category.name`. However, the product data is sourced directly from the
`products` table via the `/products` API endpoint. The database schema for the
`products` table does not contain a `category` column, and the backend API does not join
or add this data. Consequently, `product.category` will be `undefined`, leading to a
`TypeError: Cannot read property 'name' of undefined`. This will crash the product
listing page, preventing users from viewing any products.

Did we get this right? 👍 / 👎 to inform future reviews.

@sentry-demos sentry-demos deleted a comment from codecov bot Jan 28, 2026
@sentry-demos sentry-demos deleted a comment from vercel bot Jan 28, 2026
@maxkosty maxkosty added the example This is a flagship PR to demo a feature. Please do not close it. label Jan 28, 2026
@sentry-demos sentry-demos deleted a comment from codecov bot Jan 28, 2026
@maxkosty maxkosty closed this Jan 28, 2026
@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 22.11%. Comparing base (9c8b2c4) to head (4206029).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
react/src/components/Products.jsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1236      +/-   ##
==========================================
+ Coverage   22.01%   22.11%   +0.09%     
==========================================
  Files          42       42              
  Lines        1349     1352       +3     
  Branches      174      174              
==========================================
+ Hits          297      299       +2     
- Misses       1026     1027       +1     
  Partials       26       26              
Flag Coverage Δ
api 5.83% <ø> (ø)
frontend 32.64% <66.66%> (+0.12%) ⬆️
Components Coverage Δ
checkout_module 5.83% <ø> (ø)
product_component 26.35% <66.66%> (+0.21%) ⬆️
Files with missing lines Coverage Δ
react/src/components/ProductCard.jsx 73.91% <100.00%> (+2.48%) ⬆️
react/src/components/Products.jsx 31.88% <0.00%> (-0.47%) ⬇️

@maxkosty maxkosty reopened this Jan 28, 2026
<div
className="product-card"
onClick={(event) => {
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The code accesses product.category.name and product.category.id, but the API response for products does not include a category object, which will cause a runtime error.
Severity: CRITICAL

Suggested Fix

The backend API for products should be updated to include the category object for each product. This involves adding a categories table, defining the relationship in the Product model, and joining the data in the ProductController. Alternatively, add a conditional check in the frontend (e.g., product.category?.name) to handle cases where the category is not present and prevent the runtime crash.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: react/src/components/ProductCard.jsx#L26

Potential issue: The frontend code in `ProductCard.jsx` and `Products.jsx` attempts to
access properties on `product.category`, such as `product.category.name`. However, the
backend API at `/products` does not return a `category` object for each product. The
database schema for the `products` table lacks a category field, and the `Product` model
in Laravel has no defined relationship for categories. This discrepancy will cause a
"Cannot read property 'name' of undefined" runtime error when rendering the product
list, likely crashing the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example This is a flagship PR to demo a feature. Please do not close it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant