Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: use settings to determine whether or not to fetch ads #646

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

const isCurrentDifferent = (ref, currentVal) => ref.current !== currentVal

const useShouldResetPage = (query, map, orderBy, priceRange) => {

Check warning on line 128 in react/components/SearchQuery.js

View workflow job for this annotation

GitHub Actions / Lint

Arrow function has too many parameters (4). Maximum allowed is 3
const queryRef = useRef(query)
const mapRef = useRef(map)
const orderByRef = useRef(orderBy)
Expand Down Expand Up @@ -154,7 +154,7 @@
operator,
searchState,
fullText
) => {

Check warning on line 157 in react/components/SearchQuery.js

View workflow job for this annotation

GitHub Actions / Lint

Arrow function has too many parameters (4). Maximum allowed is 3
const fullTextRef = useRef(fullText)
const shouldReset = isCurrentDifferent(fullTextRef, fullText)

Expand All @@ -169,6 +169,12 @@
return result
}

const skipSponsoredProducts = ({ sponsoredProductsBehavior, settings }) => {
const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch

return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip'
hcaula marked this conversation as resolved.
Show resolved Hide resolved
}

const sponsoredProductsResult = (
sponsoredProductsLoading,
sponsoredProductsError,
Expand All @@ -189,10 +195,11 @@
facetsArgs,
price,
sponsoredProductsBehavior = 'skip'
) => {

Check warning on line 198 in react/components/SearchQuery.js

View workflow job for this annotation

GitHub Actions / Lint

Arrow function has too many parameters (4). Maximum allowed is 3
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,
Expand All @@ -209,7 +216,7 @@
error: sponsoredProductsError,
} = useQuery(sponsoredProductsQuery, {
variables,
skip: sponsoredProductsBehavior === 'skip',
skip: skipSponsoredProducts({ sponsoredProductsBehavior, settings }),
})

const sponsoredProductsReturn = sponsoredProductsResult(
Expand Down
Loading