-
Notifications
You must be signed in to change notification settings - Fork 63
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
Feat/product comparison packages core #2595
Open
HiagoMoreiraCubos
wants to merge
32
commits into
vtex:main
Choose a base branch
from
cubos-vtex:feat/product-comparison-packages-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/product comparison packages core #2595
HiagoMoreiraCubos
wants to merge
32
commits into
vtex:main
from
cubos-vtex:feat/product-comparison-packages-core
+1,025
−221
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit e283c08.
HiagoMoreiraCubos
requested review from
renatamottam and
lucasfp13
and removed request for
a team
December 13, 2024 12:42
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…uct-comparison-packages-core
HiagoMoreiraCubos
added
enhancement
New feature or request
contributing
Pull request submitted by the community
labels
Jan 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's the purpose of this pull request?
Implements the Product Comparison feature and the respective controls on Product List Page section of Headless CMS in order to facilitate the comparison of product simultaneously (such as color, size and others) through an intuitive interface.
How it works?
Initially, we developed 4 components:
ProductComparison
,ProductComparisonTrigger
andProductComparisonToolbar
,ProductComparisonSidebar
.ProductComparison
: this component serves as a wrapper (component that will wrapProductComparisonToolbar
,ProductComparisonSidebar
). It contains theProductComparisonProvider
. This provider will control all the internal state of Product Comparion (open and close the slider, control products the state products, if the toolbar appear). For the Product Comparison feature to work correctly, this wrapper must be present. To preventProductComparisonSidebar
orProductComparisonToolbar
from being used in isolation, a treatment was made in theuseProductComparison
hook.ProductComparisonTrigger
: This component is responsible for choosing the products that can be compared.ProductComparisonToolbar
: This component is responsible for delivering visual feedback to the user, making it easier to see selected products.ProductComparisonSidebar
: The feature main component. It is responsible for displaying the table containing the products and specifications. For the component to work correctly, the context created and exposed byProductComparison
must be consumed, as mentioned previously, all the logic and state management ofProductComparisonSidebar
is contained in the context. This component is composed of:SlideOver
,Table
,Price
,Button
,Badge
,Toggle
,Select
.As mentioned in the description of the created components, a context was created to manage states of Product Comparison feature. There is a hook called
useProductComparison
, which is responsible for consuming theProductComparisonProvider
and returning all the properties so that the components in the chain can use it. A validation was implemented so that the components in the chain can only be used through theProductComparison
wrapper.Continuing the implementation within
@faststore/core
in the ui folder, an abstraction ofProductComparisonSidebar
was created. All the logic for capturing and formatting the data is done in this abstraction.To request the data, a new query was created. To use it, simply call the
useProductsSelected
hook. To consume this hook, it is necessary to pass some properties, of which we can highlightproductsIds
,enable
,processResponse
.productsIds
: is an Array of string, the items in the array are pre-selected product idsenabled
: is aboolean
(true/false). It will inform the query whether theProductComparisonSidebar
is open or not. The request will only be made if the slider is open, otherwise it will not be, avoiding unnecessary requests.processRepsonse
: is a function that will be executed only when the request is successful and will return all the data. This method will return the data fully formatted following the format pre-established in theProductComparisonSidebar
component.Within this
ProductComparison
abstraction, theProductComparison
context must be consumed. As mentioned previously, the context will control all states, such as informing the context of the list of product selected. Since this abstraction will be responsible for making the request and informing the context of the data, theprocessReponse
that is passed inuseProductComparison
will be the method to add the items that will be displayed in theProductComparisonSidebar
table. Therefore, thehandleProductComparison
method present in theProductComparison
context must be assigned. This way, the formatted data that will be returned will be informed to the context and later, theProductComparisonSidebar
will be able to consume this data and display it on the screen.The hook
useBuyButton
, this hook is responsible for adding the selected items to the cart. Since the hook must consume some information to then inform thebuyButtonProps
(responsible for preparing the data to be inserted in the cart), it needs to observe the data of the products to be added to the cart. This data is returned from theProductComparison
context, so whenever there is any type of modification in the context state (for example, a one click event insideProductComparisonSidebar
), it will be reflected in theuseBuyButton
hook, and the properties will be generated correctly.Therefore, we performed:
Construction of 4 new components:
ProductComparison
,ProductComparisonTrigger
andProductComparisonToolbar
,ProductComparisonSidebar
.Provider to manage the entire Product Comparison context
Hook for consumption of the context:
useProductComparison
Exclusive query to access only the important data for the construction of Product Comparison:
useProductsSelected
How to test it?
Check the "Enable Product Comparison" checkbox field on Product Gallery section of Product List Page at Headless CMS and publish changes. Then access a product list page at store.
The comparison checkbox is above the product list. Enabling it shows checkboxes to select products. Select at least two products to enable a toolbar with actions like "Clear Selection" and "Compare." Clicking "Compare" opens a SlideOver displaying the selected products, where you can filter or view only differences.
References
RFC:
B2B Faststore - B2B Faststore - Product Comparison
Printscreens
Headless CMS
Dependencies:
This PR depends from two other PRs #2594, #2627
Preview link : https://starter-72f6tioda-vtex.vercel.app/