Skip to content

Commit

Permalink
feat(commerce): mark v2 listings as non-v2 and non-v2 listings as old (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
Spuffynism authored Jun 12, 2024
1 parent fe412e0 commit 19c6363
Show file tree
Hide file tree
Showing 42 changed files with 154 additions and 615 deletions.
32 changes: 0 additions & 32 deletions packages/headless/src/api/analytics/commerce-analytics.test.ts

This file was deleted.

116 changes: 0 additions & 116 deletions packages/headless/src/api/analytics/commerce-analytics.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +21,7 @@ import {

export type StateNeededByProductListingAnalyticsProvider =
ConfigurationSection &
ProductListingSection &
OldProductListingSection &
Partial<SearchHubSection & SectionNeededForFacetMetadata>;

export class ProductListingAnalyticsProvider
Expand Down
4 changes: 2 additions & 2 deletions packages/headless/src/app/commerce-engine/commerce-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -39,7 +39,7 @@ import {
export type {CommerceEngineConfiguration};

const commerceEngineReducers = {
productListing: productListingV2Reducer,
productListing: productListingReducer,
recommendations: recommendationsReducer,
commerceSearch: commerceSearchReducer,
commercePagination: paginationReducer,
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProductListingV2Section> {
): engine is CommerceEngine<ProductListingSection> {
engine.addReducers({productListing});
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
FacetOptionsSection,
FacetSearchSection,
FacetSection,
ProductListingSection,
OldProductListingSection,
SearchSection,
} from '../../../../state/state-sections';
import {loadReducerError} from '../../../../utils/errors';
Expand Down Expand Up @@ -511,7 +511,7 @@ function loadFacetReducers(
FacetOptionsSection &
ConfigurationSection &
FacetSearchSection &
(SearchSection | ProductListingSection),
(SearchSection | OldProductListingSection),
SearchThunkExtraArguments
> {
engine.addReducers({facetSet, facetOptions, configuration, facetSearchSet});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
CategoryFacetSearchSection,
CategoryFacetSection,
ConfigurationSection,
ProductListingSection,
OldProductListingSection,
} from '../../../state/state-sections';
import {loadReducerError} from '../../../utils/errors';
import {
Expand Down Expand Up @@ -145,7 +145,7 @@ function loadCategoryFacetReducers(
CategoryFacetSection &
CategoryFacetSearchSection &
ConfigurationSection &
ProductListingSection
OldProductListingSection
> {
engine.addReducers({
categoryFacetSet,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,7 +46,7 @@ export function buildFacetManager(

function loadFacetManagerReducers(
productListingEngine: ProductListingEngine
): productListingEngine is ProductListingEngine<ProductListingSection> {
): productListingEngine is ProductListingEngine<OldProductListingSection> {
productListingEngine.addReducers({productListing, facetOptions});
return true;
}
19 changes: 0 additions & 19 deletions packages/headless/src/features/analytics/analytics-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -145,9 +140,6 @@ export type ProductRecommendationAction =
export type ProductListingAction =
PreparableAnalyticsAction<StateNeededByProductListingAnalyticsProvider>;

export type ProductListingV2Action =
PreparableAnalyticsAction<StateNeededByCommerceAnalyticsProvider>;

export interface AsyncThunkAnalyticsOptions<
T extends StateNeededBySearchAnalyticsProvider,
> {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('commerceFacetSetReducer', () => {
{
actionName: '#fetchProductListing.fulfilled',
action: fetchProductListing.fulfilled,
responseBuilder: buildFetchProductListingV2Response,
responseBuilder: buildFetchProductListingResponse,
},
{
actionName: '#executeSearch.fulfilled',
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('pagination slice', () => {
);

it('sets the principal pagination on #fetchProductListing.fulfilled', () => {
const response = buildFetchProductListingV2Response({
const response = buildFetchProductListingResponse({
pagination,
});

Expand Down
Loading

0 comments on commit 19c6363

Please sign in to comment.