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

[framework] [frontend-api] universal product list #2901

Merged
merged 25 commits into from
Dec 1, 2023

Conversation

vitek-rostislav
Copy link
Contributor

@vitek-rostislav vitek-rostislav commented Oct 24, 2023

Q A
Description, reason for the PR At the moment, there are two product list functionalities - wishlist and comparison. Both are implemented slightly differently but basically, they do the same thing. We want to unify the implementation and make it general so it is easier to add new product lists in the future. Also, having one common codebase for the product lists makes it easier to maintain.
New feature Kind of 🙂
BC breaks Yes
Fixes issues ...
Have you read and signed our License Agreement for contributions? Yes

🌐 Live Preview:

@vitek-rostislav vitek-rostislav changed the title WIP: universal product list [framework] [frontend-api] universal product list Nov 16, 2023
@vitek-rostislav vitek-rostislav changed the base branch from 14.0 to tv-FW-1896-add-additional-skeletons November 16, 2023 09:07
@vitek-rostislav vitek-rostislav added the DX & Refactoring Requests for DX improvements and refactorings label Nov 16, 2023
@vitek-rostislav vitek-rostislav force-pushed the rv-fw-1880-product-list branch 2 times, most recently from 63dfc80 to 60fa05c Compare November 16, 2023 16:32
vitek-rostislav and others added 25 commits December 1, 2023 13:55
- ProductListTypeEnum defines the available types of the list
- at the moment, there are two types of the product lists - a wishlist and a comparison
- MultipleSearchQuery + Factory moved to the FE API package
- ProductBatchLoader:load*ByIds moved to the FE API package (the new class is now a parent of ProductBatchLoader from project-base)
- ProductBatchLoader::getTotalByBatchLoadDataId moved to the FE API package (the new class is now a parent of ProductBatchLoader from project-base)
- ProductElasticsearchProvider::getBatched*ByProductIds moved to a new class "ProductElasticsearchBatchProvider" in FE API package
- ProductElasticsearchRepository::getBatchedProductsAndTotalsByFilterQueries moved to a new class "ProductElasticsearchBatchRepository" in FE API package
- ProductElasticsearchRepository::PRODUCTS_KEY and TOTALS_KEY constants moved to a new class "ProductElasticsearchBatchRepository" in FE API package
- for not logged customer, product list type and uuid must be provided
- for logged customer, product list type must be provided, and uuid optionally
- user error is thrown when uuid is not provided by not logged user
- products of the product list are fetched using data loader
- this is available for logged customer users only
- when the list does not exist, new one is created
- when the removed product is the last one in the list, the list is removed
- thanks to that, it is now possible to easily modify validation for a particular product list type
- eg. if the input for WISHLIST should be validated in a custom way (eg. a customer user must be logged in), developer just needs to override WishlistInputValidator::validateInput
- they are already replaced by the general product lists
- added migration for migrating data from the old wishlists and comparisons to the new product lists
- useGetAllProductListUuids was added as a wrapper to easily
access all product list UUIDs which are necessary when registering
/logging in
- product-list-related queries were moved to a common folder
called productLists
- added cache updates for cleaning of product lists (manual clean
or removal of the last product)
- added optimistic update for cleaning of product lists
- new useProductList hook was added which now contains all shared logic
for working with product lists
- this hook was used inside useComparison and useWishlist to extract
common logic
- comparison and wishlist hooks were moved to hooks/productList so they
are near the file containing the shared logic
- handleClear<ProductList> was renamed to clear<ProductList>
…dded

- useGetAllProductListUuids was renamed to useProductListUuids and
extended to contain removeAllProductListUuids
as well, which simplifies cleaning of product list UUIDs during various
operations
- getAllProductListUuids is now only used inside useAuth and
useRegistration and is not needed in places where login or register are
called
- all product list UUIDs are cleared both on login (registration) and
logout, as we want to merge them with current user's lists and use their
UUIDs
- so the list UUIDs are updated at all times, both useComparison and
useWishlist contain a useEffect hook to update the UUID on any change
… fetches

- with this change, the list is not fetch right after first adding to it
- the cache is updated and the unnecessary fetch is skipped
- optimistic updates and manual updates are now in separate files
- generic cache helpers are in a separate file
- all lists now use the same mutations, queries, and fragments
- useProductList now includes essentially all the logic needed for a
product list, and only requires a provided type and callbacks
- zustand store now stores a dictionary (object) of product list UUIDs
which simplified the code and made it more generic
- useProductListUuids was removed as it was unnecessary
- useUpdateProductListUuid was introduced as a helper to generically
update a product list UUID given its type
- additionally renamed productsCompare to comparedProducts as it is
a more suitable and overall better name
@vitek-rostislav vitek-rostislav merged commit 09cef4b into 14.0 Dec 1, 2023
18 checks passed
@vitek-rostislav vitek-rostislav deleted the rv-fw-1880-product-list branch December 1, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX & Refactoring Requests for DX improvements and refactorings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants