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

Variant selector refactor #2099

Merged
merged 6 commits into from May 10, 2024

Conversation

NabeelAhmed1721
Copy link
Contributor

WHY are these changes introduced?

Improve VariantSelector to return variant object in option values:

<VariantSelector handle={product.handle} options={product.options} variants={product.variants}>
    {({option}) => (
        <>
          <div>{option.name}</div>
          <div>
            /*                          [now accessible as such]     vvvvvvv     */
            {option.values.map(({value, isAvailable, path, isActive, variant}) => (
              <Link
                to={path}
                prefetch="intent"
                className={
                  isActive ? 'active' : isAvailable ? '' : 'opacity-80'
                }
              >
                {value}
                <br />
                {variant && `SKU: ${variant.sku}`}
              </Link>
            ))}
          </div>
        </>
      )}
</VariantSelector>

There has been some small discussion around this issue for a while now and there hasn't been any clear solution. Thus, like others, I had to write a work-around to get the expected results.

HOW to test your changes?

I've also created a new test in VariantSelector.test.ts which now tests for variant objects returned by option values.

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@NabeelAhmed1721
Copy link
Contributor Author

I have signed the CLA!

Copy link
Contributor

@blittle blittle left a comment

Choose a reason for hiding this comment

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

Thank you for this!

Copy link
Contributor

shopify bot commented May 10, 2024

Oxygen deployed a preview of your VariantSelector-Refactor branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment May 10, 2024 1:40 PM
vite ✅ Successful (Logs) Preview deployment Inspect deployment May 10, 2024 1:40 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment May 10, 2024 1:40 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment May 10, 2024 1:40 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment May 10, 2024 1:40 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment May 10, 2024 1:40 PM

Learn more about Hydrogen's GitHub integration.

@blittle blittle merged commit f3a7967 into Shopify:main May 10, 2024
5 of 7 checks passed
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.

None yet

2 participants