diff --git a/manifest.json b/manifest.json index 6f2947c5..727d05c4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "search-result", "vendor": "vtex", - "version": "3.135.0-beta.2", + "version": "3.135.0-beta.4", "title": "VTEX Search Result", "description": "A search result wrapper component", "mustUpdateAt": "2019-04-25", diff --git a/react/SearchResultFlexible.js b/react/SearchResultFlexible.js index 49b6526b..7ffc03c2 100644 --- a/react/SearchResultFlexible.js +++ b/react/SearchResultFlexible.js @@ -86,6 +86,8 @@ const SearchResultFlexible = ({ deliveries, } = facets + const { query: runtimeQuery, production } = useRuntime() + const filters = useMemo( () => getFilters({ @@ -96,6 +98,7 @@ const SearchResultFlexible = ({ hiddenFacets, deliveries, showShippingFacet, + production, }), [ brands, @@ -105,6 +108,7 @@ const SearchResultFlexible = ({ brandsQuantity, deliveries, showShippingFacet, + production, ] ) @@ -118,7 +122,6 @@ const SearchResultFlexible = ({ categoriesTrees.length > 0 const showFacets = showCategories || (!hideFacets && !isEmpty(filters)) - const { query: runtimeQuery } = useRuntime() const [state, dispatch] = useSearchPageStateReducer({ mobileLayout: mobileLayout.mode1, showContentLoader: searchQuery.loading, diff --git a/react/components/SearchQuery.js b/react/components/SearchQuery.js index bf383ff8..7022f68f 100644 --- a/react/components/SearchQuery.js +++ b/react/components/SearchQuery.js @@ -1,4 +1,3 @@ -import { canUseDOM } from 'exenv' import { equals } from 'ramda' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useQuery } from 'react-apollo' @@ -15,30 +14,7 @@ import { buildSelectedFacetsAndFullText, detachFiltersByType, } from '../utils/compatibilityLayer' - -function getCookie(cname) { - if (!canUseDOM) { - return undefined - } - - const name = `${cname}=` - const decodedCookie = decodeURIComponent(document.cookie) - const ca = decodedCookie.split(';') - - for (let i = 0; i < ca.length; i++) { - let c = ca[i] - - while (c.charAt(0) === ' ') { - c = c.substring(1) - } - - if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length) - } - } - - return undefined -} +import getCookie from '../utils/getCookie' const DEFAULT_PAGE = 1 diff --git a/react/utils/getCookie.js b/react/utils/getCookie.js new file mode 100644 index 00000000..552c8297 --- /dev/null +++ b/react/utils/getCookie.js @@ -0,0 +1,27 @@ +import { canUseDOM } from 'exenv' + +function getCookie(cname) { + if (!canUseDOM) { + return undefined + } + + const name = `${cname}=` + const decodedCookie = decodeURIComponent(document.cookie) + const ca = decodedCookie.split(';') + + for (let i = 0; i < ca.length; i++) { + let c = ca[i] + + while (c.charAt(0) === ' ') { + c = c.substring(1) + } + + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length) + } + } + + return undefined +} + +export default getCookie diff --git a/react/utils/getFilters.js b/react/utils/getFilters.js index 8f420866..24eace2c 100644 --- a/react/utils/getFilters.js +++ b/react/utils/getFilters.js @@ -1,6 +1,8 @@ import { path, contains, isEmpty } from 'ramda' import { useIntl } from 'react-intl' +import getCookie from './getCookie' + export const SHIPPING_TITLE = 'store/search.filter.title.shipping' export const CATEGORIES_TITLE = 'store/search.filter.title.categories' export const BRANDS_TITLE = 'store/search.filter.title.brands' @@ -27,6 +29,7 @@ const getFilters = ({ brandsQuantity = 0, hiddenFacets = {}, showShippingFacet = false, + production = true, }) => { // eslint-disable-next-line react-hooks/rules-of-hooks const intl = useIntl() @@ -50,7 +53,12 @@ const getFilters = ({ ) } - if (!showShippingFacet) { + const variant = getCookie('sp-variant') + + if ( + !showShippingFacet || + (production && variant && variant.indexOf('delivery_promises') === -1) + ) { deliveriesFormatted = deliveriesFormatted.filter( d => d.name !== SHIPPING_KEY )