Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Switch to correct view if parent block is selected #5427

Closed
nielslange opened this issue Dec 21, 2021 · 4 comments
Closed

Switch to correct view if parent block is selected #5427

nielslange opened this issue Dec 21, 2021 · 4 comments
Assignees
Labels
block: cart Issues related to the cart block. type: bug The issue/PR concerns a confirmed bug.

Comments

@nielslange
Copy link
Member

Describe the bug

When adding the cart block to a page and opening the list view, the view between the Filled Cart and the Empty Cart can only be switched by clicking on an inner block within these blocks, e.g. the Cart Items block or the Image block. When clicking on the parent blocks itself (Filled Cart or Empty Cart) within the list view, the view does not change.

To reproduce

  1. Create a test page.
  2. Add the cart block.
  3. Open the list view.
  4. Click alternating and Filled Cart and Empty Cart.
  5. See that the view stays on the initial view and does not change.

Expected behavior

The view should not only change when clicking on one of the inner blocks, but also when clicking on one of the parent blocks.

Screenshots

Filled cart

Filled cart

Empty Cart

Empty Cart

Additional context

In #5358, we fixed the view switch for inner blocks. This issue aims to fix the view switch for the parent blocks as well.

@nielslange nielslange added type: bug The issue/PR concerns a confirmed bug. block: cart Issues related to the cart block. labels Dec 21, 2021
@tarhi-saad tarhi-saad self-assigned this Jan 11, 2022
@tarhi-saad
Copy link
Contributor

Thank you for reporting the bug @nielslange.

I followed the described steps above to reproduce the bug, but the view did change after clicking on the parent blocks. I made the tests using the latest trunk (Version 6.8.0-dev) both locally and using Pressable (i.e. Created a plugin package in ZIP format for this one).

Screenshots

Filled cart

Filled cart

Empty Cart

Empty Cart

On the other hand, the current version that can be installed from the plugins menu (i.e. Version: 6.7.1) does indeed have this bug. The view changes only when clicking on the inner blocks.

If you did use the latest trunk for your tests maybe testing on a fresh WordPress install can give us more insight.

@nielslange
Copy link
Member Author

I still see this problem, @tarhi-saad. When selecting the inner blocks, the view switches as expected. However, when selecting the parent blocks Filled Cart or Empty Cart, the view does not switch:

ezgif-7-7c962f9a0a

@tarhi-saad
Copy link
Contributor

Hi @nielslange! I've dug deeper into this issue:

TL;DR: This bug was fixed in #5446. It was merged into the trunk branch 11 days ago.

In #5358, we fixed the view switch for inner blocks. This issue aims to fix the view switch for the parent blocks as well.

As to why the view switch for the parent blocks wasn't working in the PR you've provided (i.e. #5358):
The logic was to compare the parent name of the selected block in the list view, with the currently displayed view name (see line #46 in this PR). This means if the selected element is Empty Cart, then we will check the name of its parent (i.e. cart). And this will not trigger a change of the Cart view.

On the other hand, it was fixed in #5446 by comparing the selected block name with the currently displayed view name (see line #51). This means if the element is Empty Cart, then it'll be compared with the current view name (Empty Cart / Filled Cart). And in case of the child element is selected then we are checking the parent block name instead (see lines #72-75).

This last fix (#5446) is only available in the last release (6.8.0). That's why the bug is still occurring on the public version of the Woo Block plugin (i.e. v6.7.1).

A simple test I've done to make sure that this last PR #5446 is indeed fixing this bug:

  1. Checkout to the trunk branch or the release/6.8.0
  2. Copy the code in the file: assets/js/blocks/cart-checkout/shared/use-view-switcher.tsx
  3. Checkout to the previous release (e.g. 6.7.2 or 6.7.1)
  4. Test if the bug is occurring on this release
  5. Then replace the code in the file assets/js/blocks/cart-checkout/shared/use-view-switcher.tsx by the previously copied code
  6. Test again and try changing the view. The bug should be fixed!

@nielslange
Copy link
Member Author

Great investigation, @tarhi-saad! 👏 Thank you so much for investigate the cause of this problem. I can confirm that the problem is solved with 6.8.0, based on the PR you mentioned.

As this issue is solved, I'll close this PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants