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/dp #676

Closed
wants to merge 13 commits into from
Closed
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 messages/context.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
"store/search.filter.placeholder": "Search by {filterName}",
"store/search.filter.title.brands": "Brands",
"store/search.filter.title.price-ranges": "Price Ranges",
"store/search.filter.title.shipping": "Shipping",
"store/search.filter.shipping.name.delivery": "Deliver to",
"store/search.filter.shipping.name.pickup-in-point": "Pickup at",
"store/search.filter.shipping.name.pickup-nearby": "Pickup nearby",
"store/search.filter.shipping.name.pickup-all": "Pickup",
"store/search.text": "Showing {from}-{to} from {recordsFiltered} records",
"store/search.selected-filters": "Filtered by:",
"store/search.total-products": "{recordsFiltered} <span class=\"c-muted-2\">{recordsFiltered, plural, one {Product} other {Products}}</span>",
Expand Down
5 changes: 5 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"store/search.filter.placeholder": "Search by {filterName}",
"store/search.filter.title.brands": "Brands",
"store/search.filter.title.price-ranges": "Price Ranges",
"store/search.filter.title.shipping": "Shipping",
"store/search.filter.shipping.name.delivery": "Deliver to",
"store/search.filter.shipping.name.pickup-in-point": "Pickup at",
"store/search.filter.shipping.name.pickup-nearby": "Pickup nearby",
"store/search.filter.shipping.name.pickup-all": "Pickup",
"store/search.text": "Showing {from}-{to} from {recordsFiltered} records",
"store/search.selected-filters": "Filtered by:",
"store/search.total-products": "{recordsFiltered} <span class=\"c-muted-2\">{recordsFiltered, plural, one {Product} other {Products}}</span>",
Expand Down
18 changes: 14 additions & 4 deletions react/FilterNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { useSearchPage } from 'vtex.search-page-context/SearchPageContext'
// eslint-disable-next-line no-restricted-imports
import { flatten } from 'ramda'
import { FormattedMessage } from 'react-intl'
import { FormattedMessage, useIntl } from 'react-intl'
import { Button } from 'vtex.styleguide'

import FilterSidebar from './components/FilterSidebar'
Expand All @@ -23,7 +23,7 @@
import useFacetNavigation from './hooks/useFacetNavigation'
import FilterNavigatorTitleTag from './components/FilterNavigatorTitleTag'
import styles from './searchResult.css'
import { CATEGORIES_TITLE } from './utils/getFilters'
import { CATEGORIES_TITLE, SHIPPING_OPTIONS } from './utils/getFilters'
import { newFacetPathName } from './utils/slug'
import { FACETS_RENDER_THRESHOLD } from './constants/filterConstants'

Expand Down Expand Up @@ -73,6 +73,7 @@
priceRange,
tree = [],
specificationFilters = [],
deliveries = [],
priceRanges = [],
brands = [],
loading = false,
Expand Down Expand Up @@ -101,6 +102,7 @@
priceRangeLayout = 'slider',
showQuantityBadgeOnMobile = false,
}) => {
const intl = useIntl()
const { isMobile } = useDevice()
const handles = useCssHandles(CSS_HANDLES)
const [truncatedFacetsFetched, setTruncatedFacetsFetched] = useState(false)
Expand Down Expand Up @@ -158,9 +160,17 @@
}
}, [filters, filtersFetchMore, truncatedFacetsFetched, loading])

const shipping = deliveries.map((delivery) => ({

Check failure on line 163 in react/FilterNavigator.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `(delivery)` with `delivery`
...delivery,
facets: delivery.facets.map((facet) => ({

Check failure on line 165 in react/FilterNavigator.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `(facet)` with `facet`
...facet,
name: intl.formatMessage({ id: SHIPPING_OPTIONS[facet.name] }) ,

Check failure on line 167 in react/FilterNavigator.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `·`
}))

Check failure on line 168 in react/FilterNavigator.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
}))

const selectedFilters = useMemo(() => {
const options = [
...specificationFilters.map(filter => {
...specificationFilters.concat(shipping).map(filter => {
return filter.facets.map(facet => {
return {
...newNamedFacet({ ...facet, title: filter.name }),
Expand All @@ -173,7 +183,7 @@
]

return flatten(options)
}, [brands, priceRanges, specificationFilters]).filter(
}, [brands, priceRanges, specificationFilters, shipping]).filter(
facet => facet.selected
)

Expand Down
2 changes: 2 additions & 0 deletions react/FilterNavigatorFlexible.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const withSearchPageContextProps =
specificationFilters,
categoriesTrees,
queryArgs,
deliveries,
} = facets

const sortedFilters = useMemo(
Expand Down Expand Up @@ -113,6 +114,7 @@ const withSearchPageContextProps =
priceRangeLayout={priceRangeLayout}
drawerDirectionMobile={drawerDirectionMobile}
showQuantityBadgeOnMobile={showQuantityBadgeOnMobile}
deliveries={deliveries}
/>
</FilterNavigatorContext.Provider>
</div>
Expand Down
13 changes: 12 additions & 1 deletion react/SearchResultFlexible.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
preventRouteChange = false,
showFacetQuantity = false,
showFacetTitle = false,
showShippingFacet = false,
// Below are set by SearchContext
searchQuery,
maxItemsPerPage,
Expand Down Expand Up @@ -82,6 +83,7 @@
priceRanges,
specificationFilters,
categoriesTrees,
deliveries,
} = facets

const filters = useMemo(
Expand All @@ -92,8 +94,17 @@
brands,
brandsQuantity,
hiddenFacets,
deliveries,
showShippingFacet

Check failure on line 98 in react/SearchResultFlexible.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
}),
[brands, hiddenFacets, priceRanges, specificationFilters, brandsQuantity]
[

Check failure on line 100 in react/SearchResultFlexible.js

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has a missing dependency: 'showShippingFacet'. Either include it or remove the dependency array
brands,
hiddenFacets,
priceRanges,
specificationFilters,
brandsQuantity,
deliveries,
]
)

const handles = useCssHandles(CSS_HANDLES)
Expand Down
2 changes: 1 addition & 1 deletion react/components/AccordionFilterContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const AccordionFilterContainer = ({
style={{ background: 'rgba(3, 4, 78, 0.4)' }}
className={classNames(
handles.filterLoadingOverlay,
'fixed dim top-0 w-100 vh-100 left-0 z-9999 justify-center items-center justify-center items-center flex'
'fixed dim top-0 w-100 vh-100 left-0 z-999 justify-center items-center justify-center items-center flex'
)}
>
<Spinner />
Expand Down
50 changes: 10 additions & 40 deletions react/components/FacetCheckboxList.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import classNames from 'classnames'
import React, { useContext, useState, useMemo } from 'react'
import { Checkbox } from 'vtex.styleguide'
import { applyModifiers } from 'vtex.css-handles'
import { useRuntime } from 'vtex.render-runtime'
import { usePixel } from 'vtex.pixel-manager'
import { useSearchPage } from 'vtex.search-page-context/SearchPageContext'

import { pushFilterManipulationPixelEvent } from '../utils/filterManipulationPixelEvents'
import styles from '../searchResult.css'
import SettingsContext from './SettingsContext'
import { SearchFilterBar } from './SearchFilterBar'
import { FACETS_RENDER_THRESHOLD } from '../constants/filterConstants'
import ShowMoreFilterButton from './ShowMoreFilterButton'
import FacetCheckboxListItem from './FacetCheckboxListItem'

const useSettings = () => useContext(SettingsContext)

Expand All @@ -25,7 +20,6 @@ const FacetCheckboxList = ({
truncatedFacetsFetched,
setTruncatedFacetsFetched,
}) => {
const { push } = usePixel()
const { searchQuery } = useSearchPage()
const { showFacetQuantity } = useContext(SettingsContext)
const { getSettings } = useRuntime()
Expand Down Expand Up @@ -76,40 +70,16 @@ const FacetCheckboxList = ({
<SearchFilterBar name={facetTitle} handleChange={setSearchTerm} />
) : null}
{filteredFacets.slice(0, endSlice).map(facet => {
const { name, value: slugifiedName } = facet

return (
<div
className={classNames(
applyModifiers(styles.filterAccordionItemBox, slugifiedName),
'pr4 pt3 items-center flex bb b--muted-5'
)}
key={name}
style={{ hyphens: 'auto', wordBreak: 'break-word' }}
>
<Checkbox
className="mb0"
checked={facet.selected}
id={name}
label={
showFacetQuantity && !sampling
? `${facet.name} (${facet.quantity})`
: facet.name
}
name={name}
onChange={() => {
pushFilterManipulationPixelEvent({
name: facetTitle,
value: name,
products: searchQuery?.products ?? [],
push,
})

onFilterCheck({ ...facet, title: facetTitle })
}}
value={name}
/>
</div>
<FacetCheckboxListItem
facet={facet}
facetTitle={facetTitle}
onFilterCheck={onFilterCheck}
sampling={sampling}
searchQuery={searchQuery}
showFacetQuantity={showFacetQuantity}
key={facet.name}
/>
)
})}
{shouldTruncate && (
Expand Down
87 changes: 87 additions & 0 deletions react/components/FacetCheckboxListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import classNames from 'classnames'
import React, { useMemo } from 'react'
import { applyModifiers } from 'vtex.css-handles'
import { Checkbox } from 'vtex.styleguide'
import { usePixel } from 'vtex.pixel-manager'

import styles from '../searchResult.css'
import { pushFilterManipulationPixelEvent } from '../utils/filterManipulationPixelEvents'
import useShippingActions from '../hooks/useShippingActions'
import ShippingActionButton from './ShippingActionButton'

const FacetCheckboxListItem = ({
facet,
showFacetQuantity,
sampling,
facetTitle,
searchQuery,
onFilterCheck,
}) => {
const { push } = usePixel()

const { actionLabel, actionType, openDrawer, shouldDisable } =
useShippingActions(facet)

const showActionButton = !!actionType

const { name, value: slugifiedName } = facet

const facetLabel = useMemo(() => {
let labelElement = facet.name

if (showFacetQuantity && !sampling) {
labelElement = `${labelElement} (${facet.quantity})`
}

if (showActionButton) {
labelElement = (
<div className="flex flex-column">
<span>{labelElement}</span>
<ShippingActionButton label={actionLabel} openDrawer={openDrawer} />
</div>
)
}

return labelElement
}, [
showFacetQuantity,
sampling,
facet.name,
facet.quantity,
showActionButton,
actionLabel,
openDrawer,
])

return (
<div
className={classNames(
applyModifiers(styles.filterAccordionItemBox, slugifiedName),
'pr4 pt3 items-center flex bb b--muted-5'
)}
style={{ hyphens: 'auto', wordBreak: 'break-word' }}
>
<Checkbox
disabled={shouldDisable}
className="mb0"
checked={facet.selected}
id={name}
label={facetLabel}
name={name}
onChange={() => {
pushFilterManipulationPixelEvent({
name: facetTitle,
value: name,
products: searchQuery?.products ?? [],
push,
})

onFilterCheck({ ...facet, title: facetTitle })
}}
value={name}
/>
</div>
)
}

export default FacetCheckboxListItem
Loading
Loading