Skip to content

Commit

Permalink
fix(commerce): forward required display name (#3490)
Browse files Browse the repository at this point in the history
forward required display name
  • Loading branch information
Spuffynism authored Dec 15, 2023
1 parent 1ec9ff8 commit fdc2c60
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CommerceFacetSetSection,
CommerceSearchSection,
ProductListingV2Section,
} from '../../../../state/state-sections';
import {AnyFacetResponse} from './interfaces/response';
Expand All @@ -12,7 +13,7 @@ function isFacetResponse(
}

function baseCommerceFacetResponseSelector(
state: ProductListingV2Section,
state: ProductListingV2Section | CommerceSearchSection,
facetId: string
) {
const findById = (response: {facetId: string}) =>
Expand All @@ -22,11 +23,16 @@ function baseCommerceFacetResponseSelector(
return state.productListing.facets.find(findById);
}

if ('commerceSearch' in state) {
return state.commerceSearch.facets.find(findById);
}

return undefined;
}

export const commerceFacetResponseSelector = (
state: ProductListingV2Section & CommerceFacetSetSection,
state: (ProductListingV2Section | CommerceSearchSection) &
CommerceFacetSetSection,
facetId: string
) => {
const response = baseCommerceFacetResponseSelector(state, facetId);
Expand All @@ -38,11 +44,15 @@ export const commerceFacetResponseSelector = (
};

export const isCommerceFacetLoadingResponseSelector = (
state: ProductListingV2Section
state: ProductListingV2Section | CommerceSearchSection
) => {
if ('productListing' in state) {
return state.productListing.isLoading;
}

if ('commerceSearch' in state) {
return state.commerceSearch.isLoading;
}

return undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function updateStateFromFacetResponse(
}

facetRequest.facetId = facetId;
facetRequest.displayName = facetResponse.displayName;
facetRequest.numberOfValues = facetResponse.values.length;
facetRequest.field = facetResponse.field;
facetRequest.type = facetResponse.type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type CommerceFacetRequest = Pick<
| 'isFieldExpanded'
| 'preventAutoSelect'
> & {
displayName: string;
type: FacetType;
values: AnyFacetValueRequest[];
initialNumberOfValues: number;
Expand Down
1 change: 1 addition & 0 deletions packages/headless/src/test/mock-commerce-facet-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function buildMockCommerceFacetRequest(
): CommerceFacetRequest {
return {
facetId: '',
displayName: '',
field: '',
type: 'regular',
numberOfValues: 8,
Expand Down

0 comments on commit fdc2c60

Please sign in to comment.