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

[Hooks] Fix the traversal of wishlist data #1045

Merged
merged 4 commits into from
Mar 8, 2023

Conversation

vmarta
Copy link
Contributor

@vmarta vmarta commented Mar 8, 2023

A small bug fix, which is extracted from #1042.

FYI @alexvuong since you're working on wishlist-related stuffs too.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • (change1)

How to Test-Drive This PR

  • (step1)

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@vmarta vmarta requested a review from alexvuong March 8, 2023 18:04
@vmarta vmarta requested a review from a team as a code owner March 8, 2023 18:04
@@ -31,7 +31,7 @@ export const useWishList = ({listId = ''} = {}) => {
}
)
const wishLists = productLists?.data?.filter((list) => list.type === 'wish_list') || []
const currentWishlist = wishLists?.data?.find((list) => list.id === listId) || wishLists[0]
const currentWishlist = wishLists.find((list) => list.id === listId) || wishLists[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

We do we use wishLists[0] as a fallback, when we know that it doesn't have the correct ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, that's a good point.. we wanted to use the first wishlist only when the caller does not pass in the list id. Let me fix that.

Copy link
Collaborator

@kevinxh kevinxh Mar 8, 2023

Choose a reason for hiding this comment

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

TBH, in the context of retail react app, you never need to pass in list id. The template always use the first wishlist that has type wish_list. We should remove that listId argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. We can either mimic the existing logic (of using a name and a type):

const useWishlist = () =>
useCustomerProductList(PWA_DEFAULT_WISHLIST_NAME, PWA_DEFAULT_WISHLIST_TYPE)

Or use the "first wishlist that has type wish_list". Whichever we decide to do, let's do it in a separate PR.

@vmarta vmarta merged commit ec76a55 into feature/integrate-commerce-sdk-react Mar 8, 2023
@vmarta vmarta deleted the fix-wishlist-traversal branch March 8, 2023 23:11
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