diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2dc9228..68acbea11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- Enable the choice of shipping facets that appear in the filter + ## [3.135.0] - 2025-01-08 ### Fixed diff --git a/react/SearchResultFlexible.js b/react/SearchResultFlexible.js index 7ffc03c25..13904adc3 100644 --- a/react/SearchResultFlexible.js +++ b/react/SearchResultFlexible.js @@ -51,6 +51,7 @@ const SearchResultFlexible = ({ showFacetQuantity = false, showFacetTitle = false, showShippingFacet = false, + availableShippingValues = [], // Below are set by SearchContext searchQuery, maxItemsPerPage, @@ -98,6 +99,7 @@ const SearchResultFlexible = ({ hiddenFacets, deliveries, showShippingFacet, + availableShippingValues, production, }), [ @@ -108,6 +110,7 @@ const SearchResultFlexible = ({ brandsQuantity, deliveries, showShippingFacet, + availableShippingValues, production, ] ) diff --git a/react/__mocks__/exenv.js b/react/__mocks__/exenv.js new file mode 100644 index 000000000..657f69042 --- /dev/null +++ b/react/__mocks__/exenv.js @@ -0,0 +1 @@ +export const exenv = { canUseDOM: true } diff --git a/react/utils/getFilters.js b/react/utils/getFilters.js index 24eace2cd..8f33262c7 100644 --- a/react/utils/getFilters.js +++ b/react/utils/getFilters.js @@ -29,6 +29,7 @@ const getFilters = ({ brandsQuantity = 0, hiddenFacets = {}, showShippingFacet = false, + availableShippingValues = [], production = true, }) => { // eslint-disable-next-line react-hooks/rules-of-hooks @@ -36,10 +37,19 @@ const getFilters = ({ let deliveriesFormatted = deliveries - const shipping = deliveries.find(d => d.name === SHIPPING_KEY) + let shipping = deliveries.find(d => d.name === SHIPPING_KEY) + + if (shipping && availableShippingValues.length !== 0) { + shipping = { + ...shipping, + facets: shipping.facets.filter(facet => + availableShippingValues.includes(facet.name) + ), + } + } if (shipping) { - const shippingFacet = { + const shippingFormattedFacetsName = { ...shipping, title: SHIPPING_TITLE, facets: shipping.facets.map(facet => ({ @@ -49,7 +59,7 @@ const getFilters = ({ } deliveriesFormatted = deliveries.map(facet => - facet.name === SHIPPING_KEY ? shippingFacet : facet + facet.name === SHIPPING_KEY ? shippingFormattedFacetsName : facet ) }