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

Refactor: remove explicit sponsored product call #661

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Always send `showSponsored` as true to the backend.
- Remove explicit call for `sponsoredProduct`, always relying on the backend return value.

## [3.130.2] - 2024-03-08

## [3.130.1] - 2024-03-08
Expand Down
7 changes: 1 addition & 6 deletions react/SearchContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ const SearchContent = () => {
const { searchQuery, showFacets, lazyItemsRemaining } = useSearchPage()
const { mobileLayout, showContentLoader } = useSearchPageState()

const searchProducts =
const products =
path(['data', 'productSearch', 'products'], searchQuery) || []

const sponsoredProducts =
path(['data', 'sponsoredProducts'], searchQuery) || []

const products = sponsoredProducts.concat(searchProducts)

const redirect = path(['data', 'productSearch', 'redirect'], searchQuery)

/* No need to show the spinner if it is loading because
Expand Down
47 changes: 2 additions & 45 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import productSearchQuery from 'vtex.store-resources/QueryProductSearchV3'
import searchMetadataQuery from 'vtex.store-resources/QuerySearchMetadataV2'
import facetsQuery from 'vtex.store-resources/QueryFacetsV2'
import sponsoredProductsQuery from 'vtex.store-resources/QuerySponsoredProducts'
import { equals } from 'ramda'
import { canUseDOM } from 'exenv'

Expand All @@ -13,7 +12,6 @@
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'
Expand Down Expand Up @@ -126,7 +124,7 @@

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

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

Check warning on line 127 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 @@ -155,7 +153,7 @@
operator,
searchState,
fullText
) => {

Check warning on line 156 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 @@ -170,27 +168,7 @@
return result
}

const sponsoredProductsResult = (
sponsoredProductsLoading,
sponsoredProductsError,
sponsoredProducts
) => {
const showSponsoredProducts =
!sponsoredProductsLoading && !sponsoredProductsError

const sponsoredProductsResponse = showSponsoredProducts
? sponsoredProducts
: []

return sponsoredProductsResponse
}

const useQueries = (
variables,
facetsArgs,
price,
sponsoredProductsBehavior = 'sync'
) => {
const useQueries = (variables, facetsArgs, price) => {
const { getSettings, query: runtimeQuery } = useRuntime()
const settings = getSettings('vtex.store')

Expand All @@ -199,31 +177,11 @@
const productSearchResult = useQuery(productSearchQuery, {
variables: {
...variables,
showSponsored:
settings?.fetchSponsoredProductsOnSearch &&
sponsoredProductsBehavior === 'sync',
showSponsored: true,
variant: getCookie('sp-variant'),
},
})

const {
data: { sponsoredProducts } = [],
loading: sponsoredProductLoading,
error: sponsoredProductsError,
} = useQuery(sponsoredProductsQuery, {
variables: {
...variables,
anonymousId: getCookie('biggy-anonymous'),
},
skip: shouldSkipSponsoredProducts(sponsoredProductsBehavior, settings),
})

const sponsoredProductsReturn = sponsoredProductsResult(
sponsoredProductLoading,
sponsoredProductsError,
sponsoredProducts
)

const {
refetch: searchRefetch,
loading: searchLoading,
Expand Down Expand Up @@ -313,7 +271,6 @@
sampling: facets?.sampling,
},
searchMetadata,
sponsoredProducts: sponsoredProductsReturn,
},
productSearchResult,
refetch,
Expand Down
26 changes: 0 additions & 26 deletions react/utils/shouldSkipSponsoredProducts.ts

This file was deleted.

Loading