From 19c6363614cfac3ba7b6880ec8e9c4ea40186606 Mon Sep 17 00:00:00 2001 From: Nicholas Labarre Date: Wed, 12 Jun 2024 15:10:05 -0400 Subject: [PATCH] feat(commerce): mark v2 listings as non-v2 and non-v2 listings as old (#4087) This is somewhat of an overdue rename. Generally, I've renamed "ProductListingV2" to "ProductListing", and the v1 listings from "ProductListing" to "OldProductListing". The renamed classes or file names do not affect the API surface of neither the product-listing sub-package, or the commerce sub-package. I've however deleted the v2 facet analytics actions, and removed them from the `product-listing-actions-loader.ts` action loader, which is a breaking change. I don't expect anyone to have been using these though. [CAPI-763] [CAPI-763]: https://coveord.atlassian.net/browse/CAPI-763?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- .../api/analytics/commerce-analytics.test.ts | 32 --- .../src/api/analytics/commerce-analytics.ts | 116 ---------- .../analytics/product-listing-analytics.ts | 6 +- .../app/commerce-engine/commerce-engine.ts | 4 +- .../headless-product-listing-facet-options.ts | 9 +- .../headless-product-listing.test.ts | 4 +- .../headless-product-listing.ts | 2 +- .../utils/load-product-listing-reducers.ts | 6 +- .../core/facets/facet/headless-core-facet.ts | 4 +- ...headless-product-listing-category-facet.ts | 4 +- .../headless-product-listing-facet-manager.ts | 4 +- .../src/features/analytics/analytics-utils.ts | 19 -- .../facets/facet-set/facet-set-slice.test.ts | 6 +- .../pagination/pagination-slice.test.ts | 4 +- .../product-listing-actions-loader.ts | 97 +-------- .../product-listing-actions.ts | 4 +- .../product-listing-selectors.ts | 10 +- .../product-listing-slice.test.ts | 62 +++--- .../product-listing/product-listing-slice.ts | 14 +- .../product-listing/product-listing-state.ts | 4 +- .../features/commerce/sort/sort-slice.test.ts | 4 +- .../facet-order/facet-order-slice.test.ts | 4 +- .../specific-facet-search-set-slice.test.ts | 4 +- ...et-product-listing-v2-analytics-actions.ts | 198 ------------------ .../facets/facet-set/facet-set-selectors.ts | 4 +- .../facets/facet-set/facet-set-slice.test.ts | 2 +- .../date-facet-set-slice.test.ts | 2 +- .../numeric-facet-set-slice.test.ts | 2 +- .../pagination/pagination-slice.test.ts | 2 +- ...-state.ts => old-product-listing-state.ts} | 4 +- .../product-listing-actions.ts | 8 +- .../product-listing-slice.test.ts | 12 +- .../product-listing/product-listing-slice.ts | 2 +- .../headless/src/state/commerce-app-state.ts | 4 +- .../src/state/product-listing-app-state.ts | 4 +- packages/headless/src/state/state-sections.ts | 12 +- .../headless/src/test/mock-commerce-search.ts | 2 +- .../headless/src/test/mock-commerce-state.ts | 4 +- .../src/test/mock-old-product-listing.ts | 24 +++ .../src/test/mock-product-listing-state.ts | 2 +- .../src/test/mock-product-listing-v2.ts | 26 --- .../headless/src/test/mock-product-listing.ts | 32 +-- 42 files changed, 154 insertions(+), 615 deletions(-) delete mode 100644 packages/headless/src/api/analytics/commerce-analytics.test.ts delete mode 100644 packages/headless/src/api/analytics/commerce-analytics.ts delete mode 100644 packages/headless/src/features/facets/facet-set/facet-set-product-listing-v2-analytics-actions.ts rename packages/headless/src/features/product-listing/{product-listing-state.ts => old-product-listing-state.ts} (86%) create mode 100644 packages/headless/src/test/mock-old-product-listing.ts delete mode 100644 packages/headless/src/test/mock-product-listing-v2.ts diff --git a/packages/headless/src/api/analytics/commerce-analytics.test.ts b/packages/headless/src/api/analytics/commerce-analytics.test.ts deleted file mode 100644 index 0af59b5a02a..00000000000 --- a/packages/headless/src/api/analytics/commerce-analytics.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import {buildMockCommerceState} from '../../test/mock-commerce-state'; -import {buildMockProduct} from '../../test/mock-product'; -import { - CommerceAnalyticsProvider, - StateNeededByCommerceAnalyticsProvider, -} from './commerce-analytics'; - -describe('commerce analytics', () => { - const getBaseState = (): StateNeededByCommerceAnalyticsProvider => - buildMockCommerceState(); - - it('should properly return getSearchEventRequestPayload', () => { - const state = getBaseState(); - state.productListing!.products = [buildMockProduct(), buildMockProduct()]; - expect( - new CommerceAnalyticsProvider(() => state).getSearchEventRequestPayload() - ).toMatchObject({ - queryText: '', - responseTime: 0, - results: expect.any(Array), - numberOfResults: 2, - }); - }); - - it('should properly return getSearchUID from recommendation.responseId', () => { - const state = getBaseState(); - state.productListing!.responseId = 'the_id'; - expect(new CommerceAnalyticsProvider(() => state).getSearchUID()).toEqual( - 'the_id' - ); - }); -}); diff --git a/packages/headless/src/api/analytics/commerce-analytics.ts b/packages/headless/src/api/analytics/commerce-analytics.ts deleted file mode 100644 index 9b4157ce35d..00000000000 --- a/packages/headless/src/api/analytics/commerce-analytics.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { - AnalyticsClientSendEventHook, - CoveoSearchPageClient, - SearchPageClientProvider, -} from 'coveo.analytics'; -import {SearchEventRequest} from 'coveo.analytics/dist/definitions/events'; -import {Logger} from 'pino'; -import {SectionNeededForFacetMetadata} from '../../features/facets/facet-set/facet-set-analytics-actions-utils'; -import { - ConfigurationSection, - ProductListingV2Section, - SearchHubSection, -} from '../../state/state-sections'; -import {PreprocessRequest} from '../preprocess-request'; -import {getProductListingInitialState} from './../../features/product-listing/product-listing-state'; -import {BaseAnalyticsProvider} from './base-analytics'; -import { - wrapAnalyticsClientSendEventHook, - wrapPreprocessRequest, -} from './coveo-analytics-utils'; - -export type StateNeededByCommerceAnalyticsProvider = ConfigurationSection & - ProductListingV2Section & - Partial; - -export class CommerceAnalyticsProvider - extends BaseAnalyticsProvider - implements SearchPageClientProvider -{ - private initialState = getProductListingInitialState(); - - public getPipeline(): string { - return ''; - } - - public getSearchEventRequestPayload(): Omit< - SearchEventRequest, - 'actionCause' | 'searchQueryUid' - > { - return { - queryText: '', - responseTime: 0, - results: this.mapResultsToAnalyticsDocument(), - numberOfResults: this.numberOfResults, - }; - } - - public getSearchUID() { - const newState = this.getState(); - return newState.productListing?.responseId || this.initialState.responseId; - } - - private mapResultsToAnalyticsDocument() { - return this.state.productListing?.products.map((p) => ({ - documentUri: p.clickUri, - documentUriHash: p.permanentid, - permanentid: p.permanentid, - })); - } - - private get numberOfResults() { - return this.state.productListing.products.length; - } -} - -interface ConfigureCommerceAnalyticsOptions { - logger: Logger; - analyticsClientMiddleware?: AnalyticsClientSendEventHook; - preprocessRequest?: PreprocessRequest; - provider?: SearchPageClientProvider; - getState(): StateNeededByCommerceAnalyticsProvider; -} - -export const configureCommerceAnalytics = ({ - logger, - getState, - analyticsClientMiddleware = (_, p) => p, - preprocessRequest, - provider = new CommerceAnalyticsProvider(getState), -}: ConfigureCommerceAnalyticsOptions) => { - const state = getState(); - const token = state.configuration.accessToken; - const endpoint = state.configuration.analytics.apiBaseUrl; - const runtimeEnvironment = state.configuration.analytics.runtimeEnvironment; - const enabled = state.configuration.analytics.enabled; - const client = new CoveoSearchPageClient( - { - token, - endpoint, - runtimeEnvironment, - preprocessRequest: wrapPreprocessRequest(logger, preprocessRequest), - beforeSendHooks: [ - wrapAnalyticsClientSendEventHook(logger, analyticsClientMiddleware), - (type, payload) => { - logger.info( - { - ...payload, - type, - endpoint, - token, - }, - 'Analytics request' - ); - return payload; - }, - ], - }, - provider - ); - - if (!enabled) { - client.disable(); - } - - return client; -}; diff --git a/packages/headless/src/api/analytics/product-listing-analytics.ts b/packages/headless/src/api/analytics/product-listing-analytics.ts index 4b72faca490..d089584535b 100644 --- a/packages/headless/src/api/analytics/product-listing-analytics.ts +++ b/packages/headless/src/api/analytics/product-listing-analytics.ts @@ -6,13 +6,13 @@ import { import {SearchEventRequest} from 'coveo.analytics/dist/definitions/events'; import {Logger} from 'pino'; import {SectionNeededForFacetMetadata} from '../../features/facets/facet-set/facet-set-analytics-actions-utils'; +import {getProductListingInitialState} from '../../features/product-listing/old-product-listing-state'; import { ConfigurationSection, - ProductListingSection, + OldProductListingSection, SearchHubSection, } from '../../state/state-sections'; import {PreprocessRequest} from '../preprocess-request'; -import {getProductListingInitialState} from './../../features/product-listing/product-listing-state'; import {BaseAnalyticsProvider} from './base-analytics'; import { wrapAnalyticsClientSendEventHook, @@ -21,7 +21,7 @@ import { export type StateNeededByProductListingAnalyticsProvider = ConfigurationSection & - ProductListingSection & + OldProductListingSection & Partial; export class ProductListingAnalyticsProvider diff --git a/packages/headless/src/app/commerce-engine/commerce-engine.ts b/packages/headless/src/app/commerce-engine/commerce-engine.ts index c3a8aea174c..28b493356d2 100644 --- a/packages/headless/src/app/commerce-engine/commerce-engine.ts +++ b/packages/headless/src/app/commerce-engine/commerce-engine.ts @@ -10,7 +10,7 @@ import {contextReducer} from '../../features/commerce/context/context-slice'; import {didYouMeanReducer} from '../../features/commerce/did-you-mean/did-you-mean-slice'; import {commerceFacetSetReducer} from '../../features/commerce/facets/facet-set/facet-set-slice'; import {paginationReducer} from '../../features/commerce/pagination/pagination-slice'; -import {productListingV2Reducer} from '../../features/commerce/product-listing/product-listing-slice'; +import {productListingReducer} from '../../features/commerce/product-listing/product-listing-slice'; import {queryReducer} from '../../features/commerce/query/query-slice'; import {recommendationsReducer} from '../../features/commerce/recommendations/recommendations-slice'; import {executeSearch} from '../../features/commerce/search/search-actions'; @@ -39,7 +39,7 @@ import { export type {CommerceEngineConfiguration}; const commerceEngineReducers = { - productListing: productListingV2Reducer, + productListing: productListingReducer, recommendations: recommendationsReducer, commerceSearch: commerceSearchReducer, commercePagination: paginationReducer, diff --git a/packages/headless/src/controllers/commerce/product-listing/facets/headless-product-listing-facet-options.ts b/packages/headless/src/controllers/commerce/product-listing/facets/headless-product-listing-facet-options.ts index 045ecaaf7a1..37ae49df5fc 100644 --- a/packages/headless/src/controllers/commerce/product-listing/facets/headless-product-listing-facet-options.ts +++ b/packages/headless/src/controllers/commerce/product-listing/facets/headless-product-listing-facet-options.ts @@ -1,11 +1,11 @@ import {isFacetResponse} from '../../../../features/commerce/facets/facet-set/facet-set-selector'; import { CommerceFacetSetSection, - ProductListingV2Section, + ProductListingSection, } from '../../../../state/state-sections'; export const facetResponseSelector = ( - state: ProductListingV2Section & CommerceFacetSetSection, + state: ProductListingSection & CommerceFacetSetSection, facetId: string ) => { const response = state.productListing.facets.find( @@ -18,6 +18,5 @@ export const facetResponseSelector = ( return undefined; }; -export const isFacetLoadingResponseSelector = ( - state: ProductListingV2Section -) => state.productListing.isLoading; +export const isFacetLoadingResponseSelector = (state: ProductListingSection) => + state.productListing.isLoading; diff --git a/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.test.ts b/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.test.ts index cd41a67b571..50ca7a07bbb 100644 --- a/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.test.ts +++ b/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.test.ts @@ -12,7 +12,7 @@ import { requestIdSelector, responseIdSelector, } from '../../../features/commerce/product-listing/product-listing-selectors'; -import {productListingV2Reducer} from '../../../features/commerce/product-listing/product-listing-slice'; +import {productListingReducer} from '../../../features/commerce/product-listing/product-listing-slice'; import {buildMockCommerceState} from '../../../test/mock-commerce-state'; import { MockedCommerceEngine, @@ -63,7 +63,7 @@ describe('headless product-listing', () => { it('adds the correct reducers to engine', () => { expect(engine.addReducers).toHaveBeenCalledWith({ - productListing: productListingV2Reducer, + productListing: productListingReducer, commerceContext: contextReducer, configuration, }); diff --git a/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.ts b/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.ts index 477f6aa62a0..2d36cfee2f8 100644 --- a/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.ts +++ b/packages/headless/src/controllers/commerce/product-listing/headless-product-listing.ts @@ -21,7 +21,7 @@ import { requestIdSelector, responseIdSelector, } from '../../../features/commerce/product-listing/product-listing-selectors'; -import {productListingV2Reducer as productListing} from '../../../features/commerce/product-listing/product-listing-slice'; +import {productListingReducer as productListing} from '../../../features/commerce/product-listing/product-listing-slice'; import {loadReducerError} from '../../../utils/errors'; import { buildController, diff --git a/packages/headless/src/controllers/commerce/product-listing/utils/load-product-listing-reducers.ts b/packages/headless/src/controllers/commerce/product-listing/utils/load-product-listing-reducers.ts index 3b91decece6..a873f69d842 100644 --- a/packages/headless/src/controllers/commerce/product-listing/utils/load-product-listing-reducers.ts +++ b/packages/headless/src/controllers/commerce/product-listing/utils/load-product-listing-reducers.ts @@ -1,10 +1,10 @@ import {CommerceEngine} from '../../../../app/commerce-engine/commerce-engine'; -import {productListingV2Reducer as productListing} from '../../../../features/commerce/product-listing/product-listing-slice'; -import {ProductListingV2Section} from '../../../../state/state-sections'; +import {productListingReducer as productListing} from '../../../../features/commerce/product-listing/product-listing-slice'; +import {ProductListingSection} from '../../../../state/state-sections'; export function loadProductListingReducer( engine: CommerceEngine -): engine is CommerceEngine { +): engine is CommerceEngine { engine.addReducers({productListing}); return true; } diff --git a/packages/headless/src/controllers/core/facets/facet/headless-core-facet.ts b/packages/headless/src/controllers/core/facets/facet/headless-core-facet.ts index 601e7ab42d0..faa861c4a9f 100644 --- a/packages/headless/src/controllers/core/facets/facet/headless-core-facet.ts +++ b/packages/headless/src/controllers/core/facets/facet/headless-core-facet.ts @@ -39,7 +39,7 @@ import { FacetOptionsSection, FacetSearchSection, FacetSection, - ProductListingSection, + OldProductListingSection, SearchSection, } from '../../../../state/state-sections'; import {loadReducerError} from '../../../../utils/errors'; @@ -511,7 +511,7 @@ function loadFacetReducers( FacetOptionsSection & ConfigurationSection & FacetSearchSection & - (SearchSection | ProductListingSection), + (SearchSection | OldProductListingSection), SearchThunkExtraArguments > { engine.addReducers({facetSet, facetOptions, configuration, facetSearchSet}); diff --git a/packages/headless/src/controllers/product-listing/category-facet/headless-product-listing-category-facet.ts b/packages/headless/src/controllers/product-listing/category-facet/headless-product-listing-category-facet.ts index bbc7d5a6bbb..1f8f34cee3f 100644 --- a/packages/headless/src/controllers/product-listing/category-facet/headless-product-listing-category-facet.ts +++ b/packages/headless/src/controllers/product-listing/category-facet/headless-product-listing-category-facet.ts @@ -24,7 +24,7 @@ import { CategoryFacetSearchSection, CategoryFacetSection, ConfigurationSection, - ProductListingSection, + OldProductListingSection, } from '../../../state/state-sections'; import {loadReducerError} from '../../../utils/errors'; import { @@ -145,7 +145,7 @@ function loadCategoryFacetReducers( CategoryFacetSection & CategoryFacetSearchSection & ConfigurationSection & - ProductListingSection + OldProductListingSection > { engine.addReducers({ categoryFacetSet, diff --git a/packages/headless/src/controllers/product-listing/facet/headless-product-listing-facet-manager.ts b/packages/headless/src/controllers/product-listing/facet/headless-product-listing-facet-manager.ts index 4743d6bd092..126b631cf69 100644 --- a/packages/headless/src/controllers/product-listing/facet/headless-product-listing-facet-manager.ts +++ b/packages/headless/src/controllers/product-listing/facet/headless-product-listing-facet-manager.ts @@ -1,7 +1,7 @@ import {ProductListingEngine} from '../../../app/product-listing-engine/product-listing-engine'; import {facetOptionsReducer as facetOptions} from '../../../features/facet-options/facet-options-slice'; import {productListingReducer as productListing} from '../../../features/product-listing/product-listing-slice'; -import {ProductListingSection} from '../../../state/state-sections'; +import {OldProductListingSection} from '../../../state/state-sections'; import {loadReducerError} from '../../../utils/errors'; import {sortFacets} from '../../../utils/facet-utils'; import {buildController} from '../../controller/headless-controller'; @@ -46,7 +46,7 @@ export function buildFacetManager( function loadFacetManagerReducers( productListingEngine: ProductListingEngine -): productListingEngine is ProductListingEngine { +): productListingEngine is ProductListingEngine { productListingEngine.addReducers({productListing, facetOptions}); return true; } diff --git a/packages/headless/src/features/analytics/analytics-utils.ts b/packages/headless/src/features/analytics/analytics-utils.ts index 8330e2f3b75..1764d84e47a 100644 --- a/packages/headless/src/features/analytics/analytics-utils.ts +++ b/packages/headless/src/features/analytics/analytics-utils.ts @@ -33,11 +33,6 @@ import { configureCaseAssistAnalytics, StateNeededByCaseAssistAnalytics, } from '../../api/analytics/case-assist-analytics'; -import { - StateNeededByCommerceAnalyticsProvider, - CommerceAnalyticsProvider, - configureCommerceAnalytics, -} from '../../api/analytics/commerce-analytics'; import { configureInsightAnalytics, InsightAnalyticsProvider, @@ -145,9 +140,6 @@ export type ProductRecommendationAction = export type ProductListingAction = PreparableAnalyticsAction; -export type ProductListingV2Action = - PreparableAnalyticsAction; - export interface AsyncThunkAnalyticsOptions< T extends StateNeededBySearchAnalyticsProvider, > { @@ -600,17 +592,6 @@ export const makeInsightAnalyticsActionFactory = (actionCause: string) => { return makeInsightAnalyticsAction; }; -export const makeCommerceAnalyticsAction = makeAnalyticsActionFactory< - StateNeededByCommerceAnalyticsProvider, - StateNeededByCommerceAnalyticsProvider, - CoveoSearchPageClient, - CommerceAnalyticsProvider ->( - configureCommerceAnalytics, - (original) => original, - CommerceAnalyticsProvider -); - export const makeProductListingAnalyticsAction = makeAnalyticsActionFactory< StateNeededByProductListingAnalyticsProvider, StateNeededByProductListingAnalyticsProvider, diff --git a/packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.test.ts b/packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.test.ts index 903bd14fd12..85f9dc7db5d 100644 --- a/packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.test.ts +++ b/packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.test.ts @@ -22,7 +22,7 @@ import { import {buildSearchResponse} from '../../../../test/mock-commerce-search'; import {buildMockDateFacetValue} from '../../../../test/mock-date-facet-value'; import {buildMockFacetSearchResult} from '../../../../test/mock-facet-search-result'; -import {buildFetchProductListingV2Response} from '../../../../test/mock-product-listing-v2'; +import {buildFetchProductListingResponse} from '../../../../test/mock-product-listing'; import {deselectAllBreadcrumbs} from '../../../breadcrumb/breadcrumb-actions'; import { defaultNumberOfValuesIncrement, @@ -99,7 +99,7 @@ describe('commerceFacetSetReducer', () => { { actionName: '#fetchProductListing.fulfilled', action: fetchProductListing.fulfilled, - responseBuilder: buildFetchProductListingV2Response, + responseBuilder: buildFetchProductListingResponse, }, { actionName: '#executeSearch.fulfilled', @@ -116,7 +116,7 @@ describe('commerceFacetSetReducer', () => { | typeof fetchProductListing.fulfilled | typeof executeSearch.fulfilled; responseBuilder: () => ReturnType< - typeof buildSearchResponse | typeof buildFetchProductListingV2Response + typeof buildSearchResponse | typeof buildFetchProductListingResponse >; }) => { const facetId = '1'; diff --git a/packages/headless/src/features/commerce/pagination/pagination-slice.test.ts b/packages/headless/src/features/commerce/pagination/pagination-slice.test.ts index 05f1fa8ad60..4171f358202 100644 --- a/packages/headless/src/features/commerce/pagination/pagination-slice.test.ts +++ b/packages/headless/src/features/commerce/pagination/pagination-slice.test.ts @@ -1,5 +1,5 @@ import {buildSearchResponse} from '../../../test/mock-commerce-search'; -import {buildFetchProductListingV2Response} from '../../../test/mock-product-listing-v2'; +import {buildFetchProductListingResponse} from '../../../test/mock-product-listing'; import {buildMockRecommendationsResponse} from '../../../test/mock-recommendations'; import {deselectAllBreadcrumbs} from '../../breadcrumb/breadcrumb-actions'; import { @@ -176,7 +176,7 @@ describe('pagination slice', () => { ); it('sets the principal pagination on #fetchProductListing.fulfilled', () => { - const response = buildFetchProductListingV2Response({ + const response = buildFetchProductListingResponse({ pagination, }); diff --git a/packages/headless/src/features/commerce/product-listing/product-listing-actions-loader.ts b/packages/headless/src/features/commerce/product-listing/product-listing-actions-loader.ts index 35eae03d0b4..3d080f33232 100644 --- a/packages/headless/src/features/commerce/product-listing/product-listing-actions-loader.ts +++ b/packages/headless/src/features/commerce/product-listing/product-listing-actions-loader.ts @@ -1,19 +1,7 @@ import {AsyncThunkAction} from '@reduxjs/toolkit'; import {AsyncThunkCommerceOptions} from '../../../api/commerce/commerce-api-client'; import {CommerceEngine} from '../../../app/commerce-engine/commerce-engine'; -import {productListingV2Reducer as productListing} from '../../../features/commerce/product-listing/product-listing-slice'; -import {ProductListingV2Action} from '../../analytics/analytics-utils'; -import { - logFacetClearAll, - logFacetDeselect, - logFacetSelect, - logFacetShowLess, - logFacetShowMore, - logFacetUpdateSort, - LogFacetDeselectActionCreatorPayload, - LogFacetSelectActionCreatorPayload, - LogFacetUpdateSortActionCreatorPayload, -} from '../../facets/facet-set/facet-set-product-listing-v2-analytics-actions'; +import {productListingReducer as productListing} from '../../../features/commerce/product-listing/product-listing-slice'; import { QueryCommerceAPIThunkReturn, StateNeededByQueryCommerceAPI, @@ -55,86 +43,3 @@ export function loadProductListingActions( fetchProductListing, }; } - -/** - * The product listing analytics action creators. - * - * In Open Beta. Reach out to your Coveo team for support in adopting this. - */ -export interface ProductListingAnalyticsActionCreators { - /** - * The event to log when all selected values in a facet are deselected. - * - * @param facetId - The facet ID. - * @returns A dispatchable action. - */ - logFacetClearAll(facetId: string): ProductListingV2Action; - - /** - * The event to log when a selected facet value is deselected. - * - * @param payload - The action creator payload. - * @returns A dispatchable action. - */ - logFacetDeselect( - payload: LogFacetDeselectActionCreatorPayload - ): ProductListingV2Action; - - /** - * The event to log when an idle facet value is selected. - * - * @param payload - The action creator payload. - * @returns A dispatchable action. - */ - logFacetSelect( - payload: LogFacetSelectActionCreatorPayload - ): ProductListingV2Action; - - /** - * The event to log when collapsing a facet to show fewer values. - * - * @param facetId - The facet id. - * @returns A dispatchable action. - */ - logFacetShowLess(facetId: string): ProductListingV2Action; - - /** - * The event to log when expanding a facet to show more values. - * - * @param facetId - The facet id. - * @returns A dispatchable action. - */ - logFacetShowMore(facetId: string): ProductListingV2Action; - - /** - * The event to log when the facet sort criterion is changed. - * - * @param payload - The action creator payload. - * @returns A dispatchable action. - */ - logFacetUpdateSort( - payload: LogFacetUpdateSortActionCreatorPayload - ): ProductListingV2Action; -} - -/** - * Returns the possible product listing analytics action creators. - * - * @param engine - The product listing engine. - * @returns An object holding the action creators. - * In Open Beta. Reach out to your Coveo team for support in adopting this. - */ -export function loadProductListingAnalyticsActions( - engine: CommerceEngine -): ProductListingAnalyticsActionCreators { - engine.addReducers({}); - - return { - logFacetClearAll, - logFacetDeselect, - logFacetSelect, - logFacetShowLess, - logFacetShowMore, - logFacetUpdateSort, - }; -} diff --git a/packages/headless/src/features/commerce/product-listing/product-listing-actions.ts b/packages/headless/src/features/commerce/product-listing/product-listing-actions.ts index 5188af4cbcb..77497a25190 100644 --- a/packages/headless/src/features/commerce/product-listing/product-listing-actions.ts +++ b/packages/headless/src/features/commerce/product-listing/product-listing-actions.ts @@ -4,7 +4,7 @@ import { AsyncThunkCommerceOptions, isErrorResponse, } from '../../../api/commerce/commerce-api-client'; -import {ProductListingV2Section} from '../../../state/state-sections'; +import {ProductListingSection} from '../../../state/state-sections'; import {validatePayload} from '../../../utils/validate-payload'; import {logQueryError} from '../../search/search-analytics-actions'; import { @@ -19,7 +19,7 @@ import { } from './product-listing-selectors'; export type StateNeededByFetchProductListing = - ListingAndSearchStateNeededByQueryCommerceAPI & ProductListingV2Section; + ListingAndSearchStateNeededByQueryCommerceAPI & ProductListingSection; export const fetchProductListing = createAsyncThunk< QueryCommerceAPIThunkReturn, diff --git a/packages/headless/src/features/commerce/product-listing/product-listing-selectors.ts b/packages/headless/src/features/commerce/product-listing/product-listing-selectors.ts index 7460f0cef1f..f5f90d79238 100644 --- a/packages/headless/src/features/commerce/product-listing/product-listing-selectors.ts +++ b/packages/headless/src/features/commerce/product-listing/product-listing-selectors.ts @@ -7,7 +7,7 @@ import { import {stateKey} from '../../../app/state-key'; import { CommercePaginationSection, - ProductListingV2Section, + ProductListingSection, } from '../../../state/state-sections'; import {totalEntriesPrincipalSelector} from '../pagination/pagination-selectors'; @@ -31,13 +31,13 @@ export const requestIdSelector = createSelector( ); export const numberOfProductsSelector = createSelector( - (state: Partial) => + (state: Partial) => state.productListing?.products.length || 0, (len) => len ); export const moreProductsAvailableSelector = createSelector( - (state: Partial) => ({ + (state: Partial) => ({ total: totalEntriesPrincipalSelector(state), current: numberOfProductsSelector(state), }), @@ -45,11 +45,11 @@ export const moreProductsAvailableSelector = createSelector( ); export const isLoadingSelector = createSelector( - (state: Partial) => state.productListing?.isLoading, + (state: Partial) => state.productListing?.isLoading, (isLoading) => (isNullOrUndefined(isLoading) ? false : isLoading) ); export const errorSelector = createSelector( - (state: Partial) => state.productListing?.error, + (state: Partial) => state.productListing?.error, (error) => error ); diff --git a/packages/headless/src/features/commerce/product-listing/product-listing-slice.test.ts b/packages/headless/src/features/commerce/product-listing/product-listing-slice.test.ts index 41f4f5e4b73..c97633dea2b 100644 --- a/packages/headless/src/features/commerce/product-listing/product-listing-slice.test.ts +++ b/packages/headless/src/features/commerce/product-listing/product-listing-slice.test.ts @@ -4,26 +4,26 @@ import { buildMockProduct, buildMockBaseProduct, } from '../../../test/mock-product'; -import {buildFetchProductListingV2Response} from '../../../test/mock-product-listing-v2'; +import {buildFetchProductListingResponse} from '../../../test/mock-product-listing'; import { fetchMoreProducts, fetchProductListing, promoteChildToParent, } from './product-listing-actions'; -import {productListingV2Reducer} from './product-listing-slice'; +import {productListingReducer} from './product-listing-slice'; import { - getProductListingV2InitialState, - ProductListingV2State, + getProductListingInitialState, + ProductListingState, } from './product-listing-state'; describe('product-listing-slice', () => { - let state: ProductListingV2State; + let state: ProductListingState; beforeEach(() => { - state = getProductListingV2InitialState(); + state = getProductListingInitialState(); }); it('should have an initial state', () => { - expect(productListingV2Reducer(undefined, {type: 'foo'})).toEqual( - getProductListingV2InitialState() + expect(productListingReducer(undefined, {type: 'foo'})).toEqual( + getProductListingInitialState() ); }); @@ -32,14 +32,14 @@ describe('product-listing-slice', () => { const result = buildMockBaseProduct({ec_name: 'product1'}); const facet = buildMockCommerceRegularFacetResponse(); const responseId = 'some-response-id'; - const response = buildFetchProductListingV2Response({ + const response = buildFetchProductListingResponse({ products: [result], facets: [facet], responseId, }); const action = fetchProductListing.fulfilled(response, ''); - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.products).toEqual( response.response.products.map((p) => @@ -52,7 +52,7 @@ describe('product-listing-slice', () => { }); it('sets the #position of each product to its 1-based position in the unpaginated list', () => { - const response = buildFetchProductListingV2Response({ + const response = buildFetchProductListingResponse({ products: [ buildMockBaseProduct({ec_name: 'product1'}), buildMockBaseProduct({ec_name: 'product2'}), @@ -66,7 +66,7 @@ describe('product-listing-slice', () => { }); const action = fetchProductListing.fulfilled(response, ''); - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.products[0].position).toBe(21); expect(finalState.products[1].position).toBe(22); @@ -76,10 +76,10 @@ describe('product-listing-slice', () => { const err = {message: 'message', statusCode: 500, type: 'type'}; state.error = err; - const response = buildFetchProductListingV2Response(); + const response = buildFetchProductListingResponse(); const action = fetchProductListing.fulfilled(response, ''); - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.error).toBeNull(); }); }); @@ -93,14 +93,14 @@ describe('product-listing-slice', () => { const result = buildMockBaseProduct({ec_name: 'product3'}); const facet = buildMockCommerceRegularFacetResponse(); const responseId = 'some-response-id'; - const response = buildFetchProductListingV2Response({ + const response = buildFetchProductListingResponse({ products: [result], facets: [facet], responseId, }); const action = fetchMoreProducts.fulfilled(response, ''); - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.products.map((p) => p.ec_name)).toEqual([ 'product1', @@ -123,7 +123,7 @@ describe('product-listing-slice', () => { position: 2, }), ]; - const response = buildFetchProductListingV2Response({ + const response = buildFetchProductListingResponse({ products: [buildMockBaseProduct({ec_name: 'product3'})], pagination: { page: 1, @@ -134,7 +134,7 @@ describe('product-listing-slice', () => { }); const action = fetchMoreProducts.fulfilled(response, ''); - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.products[0].position).toBe(1); expect(finalState.products[1].position).toBe(2); @@ -145,9 +145,9 @@ describe('product-listing-slice', () => { const err = {message: 'message', statusCode: 500, type: 'type'}; state.error = err; - const response = buildFetchProductListingV2Response(); + const response = buildFetchProductListingResponse(); const action = fetchMoreProducts.fulfilled(response, ''); - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.error).toBeNull(); }); }); @@ -163,7 +163,7 @@ describe('product-listing-slice', () => { type: 'commerce/productListing/fetch/rejected', payload: err, }; - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.error).toEqual(err); expect(finalState.isLoading).toBe(false); }); @@ -179,7 +179,7 @@ describe('product-listing-slice', () => { type: 'commerce/productListing/fetch/rejected', payload: err, }; - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.isLoading).toBe(false); }); }); @@ -195,7 +195,7 @@ describe('product-listing-slice', () => { type: 'commerce/productListing/fetchMoreProducts/rejected', payload: err, }; - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.error).toEqual(err); expect(finalState.isLoading).toBe(false); }); @@ -211,7 +211,7 @@ describe('product-listing-slice', () => { type: 'commerce/productListing/fetchMoreProducts/rejected', payload: err, }; - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.isLoading).toBe(false); }); }); @@ -219,13 +219,13 @@ describe('product-listing-slice', () => { describe('on #fetchProductListing.pending', () => { it('sets #isLoading to true', () => { const pendingAction = fetchProductListing.pending(''); - const finalState = productListingV2Reducer(state, pendingAction); + const finalState = productListingReducer(state, pendingAction); expect(finalState.isLoading).toBe(true); }); it('sets #requestId', () => { const pendingAction = fetchProductListing.pending('request-id'); - const finalState = productListingV2Reducer(state, pendingAction); + const finalState = productListingReducer(state, pendingAction); expect(finalState.requestId).toBe('request-id'); }); }); @@ -233,13 +233,13 @@ describe('product-listing-slice', () => { describe('on #fetchMoreProducts.pending', () => { it('sets #isLoading to true', () => { const pendingAction = fetchMoreProducts.pending(''); - const finalState = productListingV2Reducer(state, pendingAction); + const finalState = productListingReducer(state, pendingAction); expect(finalState.isLoading).toBe(true); }); it('sets #requestId', () => { const pendingAction = fetchMoreProducts.pending('request-id'); - const finalState = productListingV2Reducer(state, pendingAction); + const finalState = productListingReducer(state, pendingAction); expect(finalState.requestId).toBe('request-id'); }); }); @@ -257,7 +257,7 @@ describe('product-listing-slice', () => { }); it('when parent does not exist, it does not change the state', () => { - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState).toEqual(state); }); @@ -267,7 +267,7 @@ describe('product-listing-slice', () => { buildMockProduct({permanentid: parentPermanentId, children: []}), ]; - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState).toEqual(state); }); @@ -302,7 +302,7 @@ describe('product-listing-slice', () => { state.products = [parentProduct]; - const finalState = productListingV2Reducer(state, action); + const finalState = productListingReducer(state, action); expect(finalState.products).toEqual([ buildMockProduct({ diff --git a/packages/headless/src/features/commerce/product-listing/product-listing-slice.ts b/packages/headless/src/features/commerce/product-listing/product-listing-slice.ts index 306e11b3c2f..9e0b635a1cd 100644 --- a/packages/headless/src/features/commerce/product-listing/product-listing-slice.ts +++ b/packages/headless/src/features/commerce/product-listing/product-listing-slice.ts @@ -9,12 +9,12 @@ import { promoteChildToParent, } from './product-listing-actions'; import { - ProductListingV2State, - getProductListingV2InitialState, + ProductListingState, + getProductListingInitialState, } from './product-listing-state'; -export const productListingV2Reducer = createReducer( - getProductListingV2InitialState(), +export const productListingReducer = createReducer( + getProductListingInitialState(), (builder) => { builder @@ -85,7 +85,7 @@ export const productListingV2Reducer = createReducer( ); function handleError( - state: ProductListingV2State, + state: ProductListingState, error?: CommerceAPIErrorStatusResponse ) { state.error = error || null; @@ -93,7 +93,7 @@ function handleError( } function handleFullfilled( - state: ProductListingV2State, + state: ProductListingState, response: CommerceSuccessResponse ) { state.error = null; @@ -102,7 +102,7 @@ function handleFullfilled( state.isLoading = false; } -function handlePending(state: ProductListingV2State, requestId: string) { +function handlePending(state: ProductListingState, requestId: string) { state.isLoading = true; state.requestId = requestId; } diff --git a/packages/headless/src/features/commerce/product-listing/product-listing-state.ts b/packages/headless/src/features/commerce/product-listing/product-listing-state.ts index d161a77ffdf..65c5229165b 100644 --- a/packages/headless/src/features/commerce/product-listing/product-listing-state.ts +++ b/packages/headless/src/features/commerce/product-listing/product-listing-state.ts @@ -2,7 +2,7 @@ import {CommerceAPIErrorStatusResponse} from '../../../api/commerce/commerce-api import {Product} from '../../../api/commerce/common/product'; import {AnyFacetResponse} from '../facets/facet-set/interfaces/response'; -export interface ProductListingV2State { +export interface ProductListingState { error: CommerceAPIErrorStatusResponse | null; isLoading: boolean; requestId: string; @@ -11,7 +11,7 @@ export interface ProductListingV2State { products: Product[]; } -export const getProductListingV2InitialState = (): ProductListingV2State => ({ +export const getProductListingInitialState = (): ProductListingState => ({ error: null, isLoading: false, requestId: '', diff --git a/packages/headless/src/features/commerce/sort/sort-slice.test.ts b/packages/headless/src/features/commerce/sort/sort-slice.test.ts index e91ccf36ea9..0251f9ce410 100644 --- a/packages/headless/src/features/commerce/sort/sort-slice.test.ts +++ b/packages/headless/src/features/commerce/sort/sort-slice.test.ts @@ -1,5 +1,5 @@ import {buildSearchResponse} from '../../../test/mock-commerce-search'; -import {buildFetchProductListingV2Response} from '../../../test/mock-product-listing-v2'; +import {buildFetchProductListingResponse} from '../../../test/mock-product-listing'; import {SortBy, SortDirection} from '../../sort/sort'; import {setContext, setUser, setView} from '../context/context-actions'; import {restoreProductListingParameters} from '../product-listing-parameters/product-listing-parameters-actions'; @@ -56,7 +56,7 @@ describe('product-listing-sort-slice', () => { }; it('on #fetchProductListing.fulfilled', () => { - const response = buildFetchProductListingV2Response(sortResponse); + const response = buildFetchProductListingResponse(sortResponse); expect( sortReducer(state, fetchProductListing.fulfilled(response, '')) diff --git a/packages/headless/src/features/facets/facet-order/facet-order-slice.test.ts b/packages/headless/src/features/facets/facet-order/facet-order-slice.test.ts index a45d4845046..9c8b8b7c259 100644 --- a/packages/headless/src/features/facets/facet-order/facet-order-slice.test.ts +++ b/packages/headless/src/features/facets/facet-order/facet-order-slice.test.ts @@ -3,7 +3,7 @@ import {buildMockCommerceRegularFacetResponse} from '../../../test/mock-commerce import {buildMockCommerceRegularFacetValue} from '../../../test/mock-commerce-facet-value'; import {buildSearchResponse} from '../../../test/mock-commerce-search'; import {buildMockFacetResponse} from '../../../test/mock-facet-response'; -import {buildFetchProductListingV2Response} from '../../../test/mock-product-listing-v2'; +import {buildFetchProductListingResponse} from '../../../test/mock-product-listing'; import {buildMockSearch} from '../../../test/mock-search'; import {buildMockSearchResponse} from '../../../test/mock-search-response'; import {Parameters} from '../../commerce/parameters/parameters-actions'; @@ -74,7 +74,7 @@ describe('facet-order slice', () => { { actionName: '#fetchProductListing.fulfilled', action: fetchProductListing.fulfilled, - responseBuilder: buildFetchProductListingV2Response, + responseBuilder: buildFetchProductListingResponse, }, { actionName: '#executeCommerceSearch.fulfilled', diff --git a/packages/headless/src/features/facets/facet-search-set/specific/specific-facet-search-set-slice.test.ts b/packages/headless/src/features/facets/facet-search-set/specific/specific-facet-search-set-slice.test.ts index c54401b9b73..fb6c9aa1dcb 100644 --- a/packages/headless/src/features/facets/facet-search-set/specific/specific-facet-search-set-slice.test.ts +++ b/packages/headless/src/features/facets/facet-search-set/specific/specific-facet-search-set-slice.test.ts @@ -1,6 +1,6 @@ import {buildSearchResponse} from '../../../../test/mock-commerce-search'; import {buildMockFacetSearchResponse} from '../../../../test/mock-facet-search-response'; -import {buildFetchProductListingV2Response} from '../../../../test/mock-product-listing-v2'; +import {buildFetchProductListingResponse} from '../../../../test/mock-product-listing'; import {setView} from '../../../commerce/context/context-actions'; import {executeCommerceFacetSearch} from '../../../commerce/facets/facet-search-set/commerce-facet-search-actions'; import {fetchProductListing} from '../../../commerce/product-listing/product-listing-actions'; @@ -159,7 +159,7 @@ describe('FacetSearch slice', () => { it('on #fetchProductListing.fulfilled, calls #handleFacetSearchSetClear', () => { jest.spyOn(FacetSearchReducerHelpers, 'handleFacetSearchSetClear'); - const response = buildFetchProductListingV2Response(); + const response = buildFetchProductListingResponse(); facetSearchSetReducer(state, fetchProductListing.fulfilled(response, '')); expect( diff --git a/packages/headless/src/features/facets/facet-set/facet-set-product-listing-v2-analytics-actions.ts b/packages/headless/src/features/facets/facet-set/facet-set-product-listing-v2-analytics-actions.ts deleted file mode 100644 index 84ec7ef6211..00000000000 --- a/packages/headless/src/features/facets/facet-set/facet-set-product-listing-v2-analytics-actions.ts +++ /dev/null @@ -1,198 +0,0 @@ -import {Value} from '@coveo/bueno'; -import { - validatePayload, - requiredNonEmptyString, -} from '../../../utils/validate-payload'; -import { - ProductListingV2Action, - makeCommerceAnalyticsAction, -} from '../../analytics/analytics-utils'; -import {facetIdDefinition} from '../generic/facet-actions-validation'; -import {RangeFacetSortCriterion} from '../range-facets/generic/interfaces/request'; -import {LogFacetBreadcrumbActionCreatorPayload} from './facet-set-analytics-actions'; -import { - buildFacetBaseMetadata, - getStateNeededForFacetMetadata, - buildFacetSelectionChangeMetadata, -} from './facet-set-analytics-actions-utils'; -import {FacetSortCriterion} from './interfaces/request'; - -export const logFacetShowMore = (facetId: string): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/showMore', - (client, state) => { - validatePayload(facetId, facetIdDefinition); - const metadata = buildFacetBaseMetadata( - facetId, - getStateNeededForFacetMetadata(state) - ); - return client.makeFacetShowMore(metadata); - } - ); - -export const logFacetShowLess = (facetId: string): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/showLess', - (client, state) => { - validatePayload(facetId, facetIdDefinition); - const metadata = buildFacetBaseMetadata( - facetId, - getStateNeededForFacetMetadata(state) - ); - - return client.makeFacetShowLess(metadata); - } - ); - -export interface LogFacetUpdateSortActionCreatorPayload { - /** - * The facet id. - */ - facetId: string; - - /** - * The updated sort criterion. - */ - criterion: FacetSortCriterion | RangeFacetSortCriterion; -} - -export const logFacetUpdateSort = ( - payload: LogFacetUpdateSortActionCreatorPayload -): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/sortChange', - (client, state) => { - validatePayload(payload, { - facetId: facetIdDefinition, - criterion: new Value({ - required: true, - }), - }); - - const {facetId, criterion} = payload; - const stateForAnalytics = getStateNeededForFacetMetadata(state); - - const base = buildFacetBaseMetadata(facetId, stateForAnalytics); - const metadata = {...base, criteria: criterion}; - - return client.makeFacetUpdateSort(metadata); - } - ); - -export const logFacetClearAll = (facetId: string): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/reset', - (client, state) => { - validatePayload(facetId, facetIdDefinition); - - const stateForAnalytics = getStateNeededForFacetMetadata(state); - const metadata = buildFacetBaseMetadata(facetId, stateForAnalytics); - - return client.makeFacetClearAll(metadata); - } - ); - -export interface LogFacetSelectActionCreatorPayload { - /** - * The facet id. - */ - facetId: string; - - /** - * The facet value that was selected. - */ - facetValue: string; -} - -export const logFacetSelect = ( - payload: LogFacetSelectActionCreatorPayload -): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/select', - (client, state) => { - validatePayload(payload, { - facetId: facetIdDefinition, - facetValue: requiredNonEmptyString, - }); - - const stateForAnalytics = getStateNeededForFacetMetadata(state); - const metadata = buildFacetSelectionChangeMetadata( - payload, - stateForAnalytics - ); - - return client.makeFacetSelect(metadata); - } - ); - -export const logFacetExclude = ( - payload: LogFacetSelectActionCreatorPayload -): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/exclude', - (client, state) => { - validatePayload(payload, { - facetId: facetIdDefinition, - facetValue: requiredNonEmptyString, - }); - - const stateForAnalytics = getStateNeededForFacetMetadata(state); - const metadata = buildFacetSelectionChangeMetadata( - payload, - stateForAnalytics - ); - - return client.makeFacetExclude(metadata); - } - ); - -export interface LogFacetDeselectActionCreatorPayload { - /** - * The facet id. - */ - facetId: string; - - /** - * The facet value that was deselected. - */ - facetValue: string; -} - -export const logFacetDeselect = ( - payload: LogFacetDeselectActionCreatorPayload -): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/deselect', - (client, state) => { - validatePayload(payload, { - facetId: facetIdDefinition, - facetValue: requiredNonEmptyString, - }); - const stateForAnalytics = getStateNeededForFacetMetadata(state); - const metadata = buildFacetSelectionChangeMetadata( - payload, - stateForAnalytics - ); - - return client.makeFacetDeselect(metadata); - } - ); - -export const logFacetBreadcrumb = ( - payload: LogFacetBreadcrumbActionCreatorPayload -): ProductListingV2Action => - makeCommerceAnalyticsAction( - 'analytics/commerce/facet/breadcrumb', - (client, state) => { - validatePayload(payload, { - facetId: facetIdDefinition, - facetValue: requiredNonEmptyString, - }); - const metadata = buildFacetSelectionChangeMetadata( - payload, - getStateNeededForFacetMetadata(state) - ); - - return client.makeBreadcrumbFacet(metadata); - } - ); diff --git a/packages/headless/src/features/facets/facet-set/facet-set-selectors.ts b/packages/headless/src/features/facets/facet-set/facet-set-selectors.ts index 4cbf8a07ab9..1aa0ec0f627 100644 --- a/packages/headless/src/features/facets/facet-set/facet-set-selectors.ts +++ b/packages/headless/src/features/facets/facet-set/facet-set-selectors.ts @@ -1,12 +1,12 @@ import { - ProductListingSection, + OldProductListingSection, SearchSection, } from '../../../state/state-sections'; import {FacetSection} from '../../../state/state-sections'; import {AnyFacetResponse} from '../generic/interfaces/generic-facet-response'; import {FacetResponse, FacetValue} from './interfaces/response'; -export type FacetResponseSection = SearchSection | ProductListingSection; +export type FacetResponseSection = SearchSection | OldProductListingSection; export const baseFacetResponseSelector = ( state: Partial, diff --git a/packages/headless/src/features/facets/facet-set/facet-set-slice.test.ts b/packages/headless/src/features/facets/facet-set/facet-set-slice.test.ts index 2528d81e0be..3400b978a72 100644 --- a/packages/headless/src/features/facets/facet-set/facet-set-slice.test.ts +++ b/packages/headless/src/features/facets/facet-set/facet-set-slice.test.ts @@ -5,7 +5,7 @@ import {buildMockFacetSearchResult} from '../../../test/mock-facet-search-result import {buildMockFacetSlice} from '../../../test/mock-facet-slice'; import {buildMockFacetValue} from '../../../test/mock-facet-value'; import {buildMockFacetValueRequest} from '../../../test/mock-facet-value-request'; -import {buildFetchProductListingResponse} from '../../../test/mock-product-listing'; +import {buildFetchProductListingResponse} from '../../../test/mock-old-product-listing'; import {buildMockSearch} from '../../../test/mock-search'; import {logSearchEvent} from '../../analytics/analytics-actions'; import { diff --git a/packages/headless/src/features/facets/range-facets/date-facet-set/date-facet-set-slice.test.ts b/packages/headless/src/features/facets/range-facets/date-facet-set/date-facet-set-slice.test.ts index dbaddd4f1ad..fae8ca9da27 100644 --- a/packages/headless/src/features/facets/range-facets/date-facet-set/date-facet-set-slice.test.ts +++ b/packages/headless/src/features/facets/range-facets/date-facet-set/date-facet-set-slice.test.ts @@ -1,6 +1,6 @@ import {buildMockDateFacetSlice} from '../../../../test/mock-date-facet-slice'; import {buildMockDateFacetValue} from '../../../../test/mock-date-facet-value'; -import {buildFetchProductListingResponse} from '../../../../test/mock-product-listing'; +import {buildFetchProductListingResponse} from '../../../../test/mock-old-product-listing'; import {buildMockSearch} from '../../../../test/mock-search'; import {logSearchEvent} from '../../../analytics/analytics-actions'; import {deselectAllBreadcrumbs} from '../../../breadcrumb/breadcrumb-actions'; diff --git a/packages/headless/src/features/facets/range-facets/numeric-facet-set/numeric-facet-set-slice.test.ts b/packages/headless/src/features/facets/range-facets/numeric-facet-set/numeric-facet-set-slice.test.ts index ae32fd089e2..87a9dc63e70 100644 --- a/packages/headless/src/features/facets/range-facets/numeric-facet-set/numeric-facet-set-slice.test.ts +++ b/packages/headless/src/features/facets/range-facets/numeric-facet-set/numeric-facet-set-slice.test.ts @@ -1,6 +1,6 @@ import {buildMockNumericFacetSlice} from '../../../../test/mock-numeric-facet-slice'; import {buildMockNumericFacetValue} from '../../../../test/mock-numeric-facet-value'; -import {buildFetchProductListingResponse} from '../../../../test/mock-product-listing'; +import {buildFetchProductListingResponse} from '../../../../test/mock-old-product-listing'; import {buildMockSearch} from '../../../../test/mock-search'; import {logSearchEvent} from '../../../analytics/analytics-actions'; import {deselectAllBreadcrumbs} from '../../../breadcrumb/breadcrumb-actions'; diff --git a/packages/headless/src/features/pagination/pagination-slice.test.ts b/packages/headless/src/features/pagination/pagination-slice.test.ts index 25e2ab8a071..f26257b9688 100644 --- a/packages/headless/src/features/pagination/pagination-slice.test.ts +++ b/packages/headless/src/features/pagination/pagination-slice.test.ts @@ -1,5 +1,5 @@ import {Action} from '@reduxjs/toolkit'; -import {buildFetchProductListingResponse} from '../../test/mock-product-listing'; +import {buildFetchProductListingResponse} from '../../test/mock-old-product-listing'; import {buildMockSearch} from '../../test/mock-search'; import {deselectAllBreadcrumbs} from '../breadcrumb/breadcrumb-actions'; import {toggleSelectAutomaticFacetValue} from '../facets/automatic-facet-set/automatic-facet-set-actions'; diff --git a/packages/headless/src/features/product-listing/product-listing-state.ts b/packages/headless/src/features/product-listing/old-product-listing-state.ts similarity index 86% rename from packages/headless/src/features/product-listing/product-listing-state.ts rename to packages/headless/src/features/product-listing/old-product-listing-state.ts index 0ad2f421e41..d4c855608f9 100644 --- a/packages/headless/src/features/product-listing/product-listing-state.ts +++ b/packages/headless/src/features/product-listing/old-product-listing-state.ts @@ -2,7 +2,7 @@ import {ProductListingAPIErrorStatusResponse} from '../../api/commerce/product-l import {ProductRecommendation} from '../../api/search/search/product-recommendation'; import {AnyFacetResponse} from '../facets/generic/interfaces/generic-facet-response'; -export interface ProductListingState { +export interface OldProductListingState { url: string; clientId: string; additionalFields: string[]; @@ -18,7 +18,7 @@ export interface ProductListingState { responseId: string; } -export const getProductListingInitialState = (): ProductListingState => ({ +export const getProductListingInitialState = (): OldProductListingState => ({ url: '', clientId: '', additionalFields: [], diff --git a/packages/headless/src/features/product-listing/product-listing-actions.ts b/packages/headless/src/features/product-listing/product-listing-actions.ts index d907f043811..176c9888737 100644 --- a/packages/headless/src/features/product-listing/product-listing-actions.ts +++ b/packages/headless/src/features/product-listing/product-listing-actions.ts @@ -17,7 +17,7 @@ import { FacetSection, NumericFacetSection, PaginationSection, - ProductListingSection, + OldProductListingSection, StructuredSortSection, } from '../../state/state-sections'; import {sortFacets} from '../../utils/facet-utils'; @@ -26,8 +26,8 @@ import {PreparableAnalyticsAction} from '../analytics/analytics-utils'; import {getFacetRequests} from '../facets/generic/interfaces/generic-facet-request'; import {logQueryError} from '../search/search-analytics-actions'; import {SortBy} from '../sort/sort'; +import {OldProductListingState} from './old-product-listing-state'; import {logProductListing} from './product-listing-analytics'; -import {ProductListingState} from './product-listing-state'; export interface SetProductListingUrlPayload { /** @@ -69,7 +69,7 @@ export const setAdditionalFields = createAction( ); export type StateNeededByFetchProductListing = ConfigurationSection & - ProductListingSection & + OldProductListingSection & Partial< PaginationSection & StructuredSortSection & @@ -163,7 +163,7 @@ export const buildProductListingRequest = async ( }; function hasOneAdvancedParameterActive( - advanced: ProductListingState['advancedParameters'] + advanced: OldProductListingState['advancedParameters'] ): boolean { return advanced.debug; } diff --git a/packages/headless/src/features/product-listing/product-listing-slice.test.ts b/packages/headless/src/features/product-listing/product-listing-slice.test.ts index dc62dbd136e..b23626f6d86 100644 --- a/packages/headless/src/features/product-listing/product-listing-slice.test.ts +++ b/packages/headless/src/features/product-listing/product-listing-slice.test.ts @@ -1,19 +1,19 @@ import {buildMockFacetResponse} from '../../test/mock-facet-response'; -import {buildFetchProductListingResponse} from '../../test/mock-product-listing'; +import {buildFetchProductListingResponse} from '../../test/mock-old-product-listing'; import {buildMockProductRecommendation} from '../../test/mock-product-recommendation'; +import { + getProductListingInitialState, + OldProductListingState, +} from './old-product-listing-state'; import { fetchProductListing, setAdditionalFields, setProductListingUrl, } from './product-listing-actions'; import {productListingReducer} from './product-listing-slice'; -import { - getProductListingInitialState, - ProductListingState, -} from './product-listing-state'; describe('product-listing-slice', () => { - let state: ProductListingState; + let state: OldProductListingState; beforeEach(() => { state = getProductListingInitialState(); }); diff --git a/packages/headless/src/features/product-listing/product-listing-slice.ts b/packages/headless/src/features/product-listing/product-listing-slice.ts index 4a3bca9a447..8a9869d3676 100644 --- a/packages/headless/src/features/product-listing/product-listing-slice.ts +++ b/packages/headless/src/features/product-listing/product-listing-slice.ts @@ -1,10 +1,10 @@ import {createReducer} from '@reduxjs/toolkit'; +import {getProductListingInitialState} from './old-product-listing-state'; import { fetchProductListing, setAdditionalFields, setProductListingUrl, } from './product-listing-actions'; -import {getProductListingInitialState} from './product-listing-state'; export const productListingReducer = createReducer( getProductListingInitialState(), diff --git a/packages/headless/src/state/commerce-app-state.ts b/packages/headless/src/state/commerce-app-state.ts index 9a081f26cf5..5dde4c6ccb1 100644 --- a/packages/headless/src/state/commerce-app-state.ts +++ b/packages/headless/src/state/commerce-app-state.ts @@ -3,7 +3,7 @@ import { CartSection, CommerceContextSection, ConfigurationSection, - ProductListingV2Section, + ProductListingSection, RecommendationsSection, VersionSection, CommerceSortSection, @@ -31,7 +31,7 @@ export type CommerceSearchParametersState = export type CommerceAppState = ConfigurationSection & CommerceStandaloneSearchBoxSection & - ProductListingV2Section & + ProductListingSection & RecommendationsSection & CommerceSearchSection & CommerceQuerySection & diff --git a/packages/headless/src/state/product-listing-app-state.ts b/packages/headless/src/state/product-listing-app-state.ts index ae7da5216a6..ebe64dd40ea 100644 --- a/packages/headless/src/state/product-listing-app-state.ts +++ b/packages/headless/src/state/product-listing-app-state.ts @@ -10,13 +10,13 @@ import { FacetSection, NumericFacetSection, PaginationSection, - ProductListingSection, + OldProductListingSection, StructuredSortSection, VersionSection, } from './state-sections'; export type ProductListingAppState = ConfigurationSection & - ProductListingSection & + OldProductListingSection & FacetSearchSection & FacetSection & NumericFacetSection & diff --git a/packages/headless/src/state/state-sections.ts b/packages/headless/src/state/state-sections.ts index 18af0bb317f..079f2c38e27 100644 --- a/packages/headless/src/state/state-sections.ts +++ b/packages/headless/src/state/state-sections.ts @@ -12,7 +12,7 @@ import {CommerceFacetSetState} from '../features/commerce/facets/facet-set/facet import {FieldSuggestionsOrderState} from '../features/commerce/facets/field-suggestions-order/field-suggestions-order-state'; import {InstantProductsState} from '../features/commerce/instant-products/instant-products-state'; import {CommercePaginationState} from '../features/commerce/pagination/pagination-state'; -import {ProductListingV2State} from '../features/commerce/product-listing/product-listing-state'; +import {ProductListingState} from '../features/commerce/product-listing/product-listing-state'; import {CommerceQueryState} from '../features/commerce/query/query-state'; import {RecommendationsState as CommerceRecommendationsState} from '../features/commerce/recommendations/recommendations-state'; import {CommerceSearchState} from '../features/commerce/search/search-state'; @@ -41,7 +41,7 @@ import {InsightConfigurationState} from '../features/insight-configuration/insig import {InsightInterfaceState} from '../features/insight-interface/insight-interface-state'; import {InstantResultsState} from '../features/instant-results/instant-results-state'; import {PaginationState} from '../features/pagination/pagination-state'; -import {ProductListingState} from '../features/product-listing/product-listing-state'; +import {OldProductListingState} from '../features/product-listing/old-product-listing-state'; import {ProductRecommendationsState} from '../features/product-recommendations/product-recommendations-state'; import {QuerySetState} from '../features/query-set/query-set-state'; import {QuerySuggestSet} from '../features/query-suggest/query-suggest-state'; @@ -299,11 +299,11 @@ export interface ProductRecommendationsSection { productRecommendations: ProductRecommendationsState; } -export interface ProductListingSection { +export interface OldProductListingSection { /** * The information related to the product listing endpoint. */ - productListing: ProductListingState; + productListing: OldProductListingState; } export interface CommercePaginationSection { @@ -341,11 +341,11 @@ export interface CartSection { cart: CartState; } -export interface ProductListingV2Section { +export interface ProductListingSection { /** * The information related to the product listing endpoint. */ - productListing: ProductListingV2State; + productListing: ProductListingState; } export interface RecommendationsSection { diff --git a/packages/headless/src/test/mock-commerce-search.ts b/packages/headless/src/test/mock-commerce-search.ts index 49d79e6507d..fb704a4a0ed 100644 --- a/packages/headless/src/test/mock-commerce-search.ts +++ b/packages/headless/src/test/mock-commerce-search.ts @@ -1,6 +1,6 @@ import {SearchCommerceSuccessResponse} from '../api/commerce/search/response'; import {QuerySearchCommerceAPIThunkReturn} from '../features/commerce/search/search-actions'; -import {buildFetchProductListingV2Response as buildFetchProductsCoreResponse} from './mock-product-listing-v2'; +import {buildFetchProductListingResponse as buildFetchProductsCoreResponse} from './mock-product-listing'; export function buildSearchResponse( response: Partial = {}, diff --git a/packages/headless/src/test/mock-commerce-state.ts b/packages/headless/src/test/mock-commerce-state.ts index f3d01cb6c7b..7117863723e 100644 --- a/packages/headless/src/test/mock-commerce-state.ts +++ b/packages/headless/src/test/mock-commerce-state.ts @@ -4,7 +4,7 @@ import {getCommerceFacetSetInitialState} from '../features/commerce/facets/facet import {getFieldSuggestionsOrderInitialState} from '../features/commerce/facets/field-suggestions-order/field-suggestions-order-state'; import {getInstantProductsInitialState} from '../features/commerce/instant-products/instant-products-state'; import {getCommercePaginationInitialState} from '../features/commerce/pagination/pagination-state'; -import {getProductListingV2InitialState} from '../features/commerce/product-listing/product-listing-state'; +import {getProductListingInitialState} from '../features/commerce/product-listing/product-listing-state'; import {getCommerceQueryInitialState} from '../features/commerce/query/query-state'; import {getRecommendationsInitialState} from '../features/commerce/recommendations/recommendations-state'; import {getCommerceSearchInitialState} from '../features/commerce/search/search-state'; @@ -26,7 +26,7 @@ export function buildMockCommerceState( ): CommerceAppState { return { configuration: getConfigurationInitialState(), - productListing: getProductListingV2InitialState(), + productListing: getProductListingInitialState(), recommendations: getRecommendationsInitialState(), commerceSearch: getCommerceSearchInitialState(), commerceQuery: getCommerceQueryInitialState(), diff --git a/packages/headless/src/test/mock-old-product-listing.ts b/packages/headless/src/test/mock-old-product-listing.ts new file mode 100644 index 00000000000..33c55a39616 --- /dev/null +++ b/packages/headless/src/test/mock-old-product-listing.ts @@ -0,0 +1,24 @@ +import {ProductListingSuccessResponse} from '../api/commerce/product-listings/product-listing-request'; +import {logInterfaceLoad} from '../features/analytics/analytics-actions'; +import {FetchProductListingThunkReturn} from '../features/product-listing/product-listing-actions'; + +export function buildFetchProductListingResponse( + response: Partial = {} +): FetchProductListingThunkReturn { + return { + response: { + pagination: { + totalCount: 0, + ...(response?.pagination || {}), + }, + facets: { + results: [], + ...(response?.facets || {}), + }, + products: [], + responseId: '', + ...(response || {}), + }, + analyticsAction: logInterfaceLoad(), + }; +} diff --git a/packages/headless/src/test/mock-product-listing-state.ts b/packages/headless/src/test/mock-product-listing-state.ts index 891486d194e..fb61ba17ea5 100644 --- a/packages/headless/src/test/mock-product-listing-state.ts +++ b/packages/headless/src/test/mock-product-listing-state.ts @@ -9,7 +9,7 @@ import {getFacetSetInitialState} from '../features/facets/facet-set/facet-set-st import {getDateFacetSetInitialState} from '../features/facets/range-facets/date-facet-set/date-facet-set-state'; import {getNumericFacetSetInitialState} from '../features/facets/range-facets/numeric-facet-set/numeric-facet-set-state'; import {getPaginationInitialState} from '../features/pagination/pagination-state'; -import {getProductListingInitialState} from '../features/product-listing/product-listing-state'; +import {getProductListingInitialState} from '../features/product-listing/old-product-listing-state'; import {getSortInitialState} from '../features/sort/sort-state'; import {ProductListingAppState} from '../state/product-listing-app-state'; diff --git a/packages/headless/src/test/mock-product-listing-v2.ts b/packages/headless/src/test/mock-product-listing-v2.ts deleted file mode 100644 index 5ddf4495370..00000000000 --- a/packages/headless/src/test/mock-product-listing-v2.ts +++ /dev/null @@ -1,26 +0,0 @@ -import {CommerceSuccessResponse} from '../api/commerce/common/response'; -import {QueryCommerceAPIThunkReturn} from '../features/commerce/common/actions'; -import {SortBy} from '../features/sort/sort'; - -export function buildFetchProductListingV2Response( - response: Partial = {} -): QueryCommerceAPIThunkReturn { - return { - response: { - sort: response.sort ?? { - appliedSort: {sortCriteria: SortBy.Relevance}, - availableSorts: [{sortCriteria: SortBy.Relevance}], - }, - pagination: response.pagination ?? { - page: 0, - perPage: 0, - totalEntries: 0, - totalPages: 0, - }, - facets: response.facets ?? [], - products: response.products ?? [], - responseId: response.responseId ?? '', - triggers: response.triggers ?? [], - }, - }; -} diff --git a/packages/headless/src/test/mock-product-listing.ts b/packages/headless/src/test/mock-product-listing.ts index 33c55a39616..8c2117b19f8 100644 --- a/packages/headless/src/test/mock-product-listing.ts +++ b/packages/headless/src/test/mock-product-listing.ts @@ -1,24 +1,26 @@ -import {ProductListingSuccessResponse} from '../api/commerce/product-listings/product-listing-request'; -import {logInterfaceLoad} from '../features/analytics/analytics-actions'; -import {FetchProductListingThunkReturn} from '../features/product-listing/product-listing-actions'; +import {CommerceSuccessResponse} from '../api/commerce/common/response'; +import {QueryCommerceAPIThunkReturn} from '../features/commerce/common/actions'; +import {SortBy} from '../features/sort/sort'; export function buildFetchProductListingResponse( - response: Partial = {} -): FetchProductListingThunkReturn { + response: Partial = {} +): QueryCommerceAPIThunkReturn { return { response: { - pagination: { - totalCount: 0, - ...(response?.pagination || {}), + sort: response.sort ?? { + appliedSort: {sortCriteria: SortBy.Relevance}, + availableSorts: [{sortCriteria: SortBy.Relevance}], }, - facets: { - results: [], - ...(response?.facets || {}), + pagination: response.pagination ?? { + page: 0, + perPage: 0, + totalEntries: 0, + totalPages: 0, }, - products: [], - responseId: '', - ...(response || {}), + facets: response.facets ?? [], + products: response.products ?? [], + responseId: response.responseId ?? '', + triggers: response.triggers ?? [], }, - analyticsAction: logInterfaceLoad(), }; }