From f8c83aacaacd607e13f2a953e067561dc80acad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Wed, 22 Nov 2023 10:03:02 -0300 Subject: [PATCH 1/7] feat: use settings to know if ads should be fetched --- react/components/SearchQuery.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/react/components/SearchQuery.js b/react/components/SearchQuery.js index 06eb57aae..8505f508e 100644 --- a/react/components/SearchQuery.js +++ b/react/components/SearchQuery.js @@ -169,6 +169,12 @@ const useCorrectSearchStateVariables = ( return result } +const skipSponsoredProducts = ({ sponsoredProductsBehavior, settings }) => { + const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch + + return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip' +} + const sponsoredProductsResult = ( sponsoredProductsLoading, sponsoredProductsError, @@ -191,8 +197,9 @@ const useQueries = ( sponsoredProductsBehavior = 'skip' ) => { const { getSettings, query: runtimeQuery } = useRuntime() - const isLazyFacetsFetchEnabled = - getSettings('vtex.store')?.enableFiltersFetchOptimization + const settings = getSettings('vtex.store') + + const isLazyFacetsFetchEnabled = settings?.enableFiltersFetchOptimization const productSearchResult = useQuery(productSearchQuery, { ssr: false, @@ -209,7 +216,7 @@ const useQueries = ( error: sponsoredProductsError, } = useQuery(sponsoredProductsQuery, { variables, - skip: sponsoredProductsBehavior === 'skip', + skip: skipSponsoredProducts({ sponsoredProductsBehavior, settings }), }) const sponsoredProductsReturn = sponsoredProductsResult( From 776407c2d81107c301ced8f7dcb61bf0afdecd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Wed, 22 Nov 2023 15:01:07 -0300 Subject: [PATCH 2/7] docs: CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e03758641..c7a3a5725 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 + +- Use the advanced setting `fetchSponsoredProductsOnSearch` to determine whether or not to fetch sponsored products. + ## [3.127.1] - 2023-10-24 ### Changed From f5da1d45c77ee45a2890c0641f854c4494a5ff2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Wed, 22 Nov 2023 15:05:38 -0300 Subject: [PATCH 3/7] Release v3.128.0-beta.0 --- manifest.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index f568877d9..af95919a8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,13 +1,11 @@ { "name": "search-result", "vendor": "vtex", - "version": "3.127.1", + "version": "3.128.0-beta.0", "title": "VTEX Search Result", "description": "A search result wrapper component", "mustUpdateAt": "2019-04-25", - "registries": [ - "smartcheckout" - ], + "registries": ["smartcheckout"], "scripts": { "postreleasy": "vtex publish --verbose" }, From b00fffee1cbaad88a9ae5021a3d9212d847e7108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Wed, 22 Nov 2023 15:06:14 -0300 Subject: [PATCH 4/7] Release v3.128.0-beta.1 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index af95919a8..d4d7c775d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "search-result", "vendor": "vtex", - "version": "3.128.0-beta.0", + "version": "3.128.0-beta.1", "title": "VTEX Search Result", "description": "A search result wrapper component", "mustUpdateAt": "2019-04-25", From 3dd6ff5eae4e19e3e26e5cb210094ef48cc8d854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Wed, 22 Nov 2023 17:15:39 -0300 Subject: [PATCH 5/7] chore: return to previous version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index d4d7c775d..e0d9cde5a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "search-result", "vendor": "vtex", - "version": "3.128.0-beta.1", + "version": "3.127.1", "title": "VTEX Search Result", "description": "A search result wrapper component", "mustUpdateAt": "2019-04-25", From 1b126d992bb41fbdb2dda699f94d639d628d8c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Wed, 22 Nov 2023 17:23:10 -0300 Subject: [PATCH 6/7] style: formatting on manifest.json --- manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index e0d9cde5a..f568877d9 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,9 @@ "title": "VTEX Search Result", "description": "A search result wrapper component", "mustUpdateAt": "2019-04-25", - "registries": ["smartcheckout"], + "registries": [ + "smartcheckout" + ], "scripts": { "postreleasy": "vtex publish --verbose" }, From 5558b04e424e8bb4b0a637695134be8682d75f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Ca=C3=BAla?= Date: Mon, 27 Nov 2023 16:07:33 -0300 Subject: [PATCH 7/7] feat: extract skipSponsoredProducts function --- react/components/SearchQuery.js | 9 ++------- react/utils/shouldSkipSponsoredProducts.ts | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 react/utils/shouldSkipSponsoredProducts.ts diff --git a/react/components/SearchQuery.js b/react/components/SearchQuery.js index 8505f508e..22ac2834f 100644 --- a/react/components/SearchQuery.js +++ b/react/components/SearchQuery.js @@ -13,6 +13,7 @@ import { detachFiltersByType, buildQueryArgsFromSelectedFacets, } from '../utils/compatibilityLayer' +import shouldSkipSponsoredProducts from '../utils/shouldSkipSponsoredProducts' import { FACETS_RENDER_THRESHOLD } from '../constants/filterConstants' import useRedirect from '../hooks/useRedirect' import useSession from '../hooks/useSession' @@ -169,12 +170,6 @@ const useCorrectSearchStateVariables = ( return result } -const skipSponsoredProducts = ({ sponsoredProductsBehavior, settings }) => { - const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch - - return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip' -} - const sponsoredProductsResult = ( sponsoredProductsLoading, sponsoredProductsError, @@ -216,7 +211,7 @@ const useQueries = ( error: sponsoredProductsError, } = useQuery(sponsoredProductsQuery, { variables, - skip: skipSponsoredProducts({ sponsoredProductsBehavior, settings }), + skip: shouldSkipSponsoredProducts(sponsoredProductsBehavior, settings), }) const sponsoredProductsReturn = sponsoredProductsResult( diff --git a/react/utils/shouldSkipSponsoredProducts.ts b/react/utils/shouldSkipSponsoredProducts.ts new file mode 100644 index 000000000..5f496ed70 --- /dev/null +++ b/react/utils/shouldSkipSponsoredProducts.ts @@ -0,0 +1,23 @@ +type SponsoredProductsBehavior = 'skip' | string + +type Settings = { + fetchSponsoredProductsOnSearch: boolean +} & Record + +/** + * This function checks the store's settings, as well as the passed value of + * `sponsoredProductsBehavior` passed in the store-theme, to determine if the + * sponsored products request should be skipped or not. + * Some accounts may not have configured the store's settings, so we need to check if the + * `sponsoredProductsBehavior` parameter for compatibility. + */ +const shouldSkipSponsoredProducts = ( + sponsoredProductsBehavior: SponsoredProductsBehavior, + settings: Settings +) => { + const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch + + return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip' +} + +export default shouldSkipSponsoredProducts