Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor product list path helper #2117

Merged
merged 2 commits into from
Nov 21, 2023
Merged

Conversation

masonmcelvain
Copy link
Contributor

Noticed in my CR here #2112 (comment)

QA

Make sure the product list links throughout the Next.js app still work normally.

In particular, make sure that item type canonical urls in the <head> are still correct, and check the new variant syntax too (DeviceTitle:Variant)

Now that this function accepts two string arguments, it would be easy to accidentally mix them up. Converting the arguments to an object will clear up this confusion.
The productListPath helper already handles itemType, so let it do it's job instead of computing it ourselves.
Copy link

vercel bot commented Nov 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-commerce ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2023 0:08am
react-commerce-prod ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2023 0:08am

@ghost
Copy link

ghost commented Nov 21, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Copy link
Contributor

📦 Next.js Bundle Analysis for @ifixit/commerce-frontend

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link
Contributor

@jarstelfox jarstelfox left a comment

Choose a reason for hiding this comment

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

CR 🌵

@kthaler kthaler self-assigned this Nov 21, 2023
@kthaler kthaler added the QAing Under QA team review label Nov 21, 2023
@kthaler
Copy link
Contributor

kthaler commented Nov 21, 2023

QA 💠 - It seems like the product list links are still working normally and the item type canonical urls in the <head> are correct.

deploy_block 🦖 -
For URLs that use the variant syntax, should the canonicals point to the specific variant URL, or should they refer to the main device URL instead? Currently, the canonicals seem to point to the main device URL. EX: For https://react-commerce-git-refactor-product-list-path-ifixit.vercel.app/Parts/PlayStation_4:CUH-11XXA, this is the canonical:
Screenshot 2023-11-20 at 4 44 43 PM

@kthaler kthaler removed the QAing Under QA team review label Nov 21, 2023
@masonmcelvain
Copy link
Contributor Author

For URLs that use the variant syntax, should the canonicals point to the specific variant URL, or should they refer to the main device URL instead?

According to this issue, they should canonical to the device handle by default, and the variant handles if indexVariantsInsteadOfDevice is set in Strapi.

Currently, the canonicals seem to point to the main device URL

That sounds like the right behavior, since this setting is new and most/all product lists in Strapi have it set to false by default.

@masonmcelvain
Copy link
Contributor Author

un_deploy_block 👍🏻

@masonmcelvain masonmcelvain merged commit 2211da5 into main Nov 21, 2023
15 checks passed
@masonmcelvain masonmcelvain deleted the refactor-product-list-path branch November 21, 2023 14:30
Copy link
Contributor

@dhmacs dhmacs left a comment

Choose a reason for hiding this comment

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

Added a few non-blocking suggestions

Comment on lines +122 to +124
itemType: itemType ?? undefined,
variant: productList.indexVariantsInsteadOfDevice ? variant : undefined,
})}${page > 1 ? `?${PRODUCT_LIST_PAGE_PARAM}=${page}` : ''}`;
Copy link
Contributor

@dhmacs dhmacs Nov 21, 2023

Choose a reason for hiding this comment

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

I suspect that the increased complexity of productListPath function can (at least in part) be pushed into the product list model

itemType: itemType ?? undefined,

itemType could be integrated into the product list model as an optional/nullable attribute. We already have useItemTypeProductList taking care of integrating item type override directly into the model (note that this happens to be a hook just because using Algolia hooks forces us to model it this way, otherwise that logic could be moved in the model).

variant: productList.indexVariantsInsteadOfDevice ? variant : undefined

It looks like this ternary could be implemented directly inside productListPath.
Looking at the implementation though, it looks like this kind of path that includes the variant is going to be used only in meta tags (btw, what's the reason for this behaviour?). If that's the case, we can create a specific function to compute the path and colocate it within this file, so that this logic is not made general purpose if it belongs only to a specific use case

Comment on lines +22 to +26
type ProductListPathProps = {
productList: ProductListPathAttributes;
itemType?: string;
variant?: string | undefined;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding to my previous comment, it seems to me that this helper is becoming increasingly complex, and some of that complexity could be simplified if pushed into the model.
Ideally one should be able to call productListPath(productList) and get back the product list path.
itemType is just a specific type of product list, not an additional attribute I need to think about when I'm trying to get the product list path.
Maybe we can conceive a similar simplification for variant? When should I pass this param to productListPath? Can we make it so when using productListPath we don't have to think about this?

@masonmcelvain
Copy link
Contributor Author

I just missed your comments @dhmacs! We will address them here: #2119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants