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

[PWA-178] Gift options support in cart page #2114

Merged
merged 42 commits into from
Feb 10, 2020

Conversation

revanth0212
Copy link
Contributor

@revanth0212 revanth0212 commented Jan 24, 2020

Description

Gift Options Support in Venia Cart Page

Related Issue

Closes PWA-178

Verification Stakeholders

@soumya-ashok
@jimbo

Verification Steps

  1. Add an item to the cart and go to the cart page.
  2. Expand the See Gift Options section.
  3. You should see the Gift Options.

Screenshots / Screen Captures

image

image

Checklist

  • GQL does not support Gift Options yet. Make sure a rest call is made to save the options.

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jan 24, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-178.

Generated by 🚫 dangerJS against 89641b3

@revanth0212 revanth0212 added enhancement New feature or request version: Minor This changeset includes functionality added in a backwards compatible manner. labels Jan 27, 2020
@revanth0212 revanth0212 changed the title Revanth/cart/gift options [PWA-178] Gift options support in cart page Jan 27, 2020
@revanth0212 revanth0212 marked this pull request as ready for review January 27, 2020 21:02
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

I left a bunch of feedback, and we can discuss in person if you'd like.

I also noticed that the cache state is incorrect (and over-cached?) Look at the nested gift_options object which seems to be a copy of the parent but flips a flag?

Image from Gyazo

packages/venia-ui/lib/drivers/adapter.js Outdated Show resolved Hide resolved

const resolvers = {
Query: {
gift_options: (_, __, { cache }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if these can be async but you may consider moving the REST calls here to the resolvers. Basically you would only interact with graphql in the component/talon but the resolvers would actually handle doing the rest call and update the cache accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolvers are temporary. I went with the easiest temporary option here. Making a network call from the hook gives me more control over when to make the call, for instance in case of gift message only send the request every 10 seconds. Yes, I can do this from the resolver as well, but the resolver can not differentiate between the checkbox and gift message.

Copy link
Contributor

@sirugh sirugh Jan 28, 2020

Choose a reason for hiding this comment

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

The flow I imagined was similar to how we used actions.

User input > call mutation (or invoke action) > call rest > augment cache (or redux store) with rest results

Right now we're doing both sort of simultaneously, which isn't necessarily wrong I guess, but it puts all the logic of doing the fetch within the component in a manner that we're trying to move away from in the long run.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tjwiebell @jimbo lemme know if I'm trying to scope creep here.

Copy link
Contributor

@sirugh sirugh Feb 4, 2020

Choose a reason for hiding this comment

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

This isn't relevant anymore since as of now we are only storing gift option choices and text to local storage through Apollo. When we work on Checkout we will need to make sure to add some step that pulls this data from the cache and submits it via REST when you click the checkout button.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would normally have done the API call on submit of the "step", which is Proceed to Checkout or some variation of Continue. With the way the forms are broken out, though, it may be easier to wait until Place Order.

@revanth0212 revanth0212 dismissed stale reviews from schensley and sirugh via 1359249 February 5, 2020 16:39
sirugh
sirugh previously approved these changes Feb 5, 2020
Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

Code looks good to me. Only a couple of very minor things to change. 👍

Remember to look at other components in the codebase for guidance; some patterns not enforced by the linter are pretty consistent here nonetheless.

I'll test it out while you're fixing it up, then return to approve.


const classes = useMemo(() => mergeClasses(defaultClasses, props.classes), [
props.classes
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't bother memoizing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Any particular reason?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just consistency. We don't memoize mergeClasses() in any of the existing components (afaik), and I have minor concerns about things slipping through the cracks when we get to refactoring classify one day.

sirugh
sirugh previously approved these changes Feb 5, 2020
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the validator! Sucks we had to do a one-off but hopefully we can figure out a long term solution for client-side schema at a later time :)

sirugh
sirugh previously approved these changes Feb 6, 2020
@dpatil-magento
Copy link
Contributor

@revanth0212 I can see gift options even after disabling this setting in Admin UI. Is this expected?

@sirugh
Copy link
Contributor

sirugh commented Feb 7, 2020

@revanth0212 I can see gift options even after disabling this setting in Admin UI. Is this expected?

Oh man I didn't even realize this was a thing. I think that we should create a fast-follow that goes back and enables/disables cart features based on their admin toggles. This will probably require either some build or runtime GQL check.

@dpatil-magento dpatil-magento merged commit 39ba60f into develop Feb 10, 2020
@dpatil-magento dpatil-magento deleted the revanth/cart/giftOptions branch February 10, 2020 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:graphql-cli-validate-magento-pwa-queries pkg:peregrine pkg:venia-concept pkg:venia-ui version: Minor This changeset includes functionality added in a backwards compatible manner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants