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

Add data attributes to FacetItem component #694

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
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]

### Changed

- Add attributes to the checkbox component to be able to collect data through activity flow

## [3.136.0] - 2025-01-16

### Added
Expand Down
18 changes: 18 additions & 0 deletions react/components/FacetCheckboxListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { applyModifiers } from 'vtex.css-handles'
import { Checkbox } from 'vtex.styleguide'
import { usePixel } from 'vtex.pixel-manager'
import { useIntl } from 'react-intl'
import { useRuntime } from 'vtex.render-runtime'

import styles from '../searchResult.css'
import { pushFilterManipulationPixelEvent } from '../utils/filterManipulationPixelEvents'
Expand Down Expand Up @@ -60,6 +61,17 @@ const FacetCheckboxListItem = ({
intl,
])

const runtimeQuery = useRuntime()?.query

let initialmap
let initialquery

if (searchQuery?.variables?.fullText === undefined) {
initialquery = runtimeQuery?.initialQuery ?? searchQuery?.facets?.queryArgs.query

initialmap = runtimeQuery?.initialMap ?? searchQuery?.facets?.queryArgs?.map
}

return (
<div
className={classNames(
Expand All @@ -86,6 +98,12 @@ const FacetCheckboxListItem = ({
onFilterCheck({ ...facet, title: facetTitle })
}}
value={name}
isClicked={facet.selected.toString()}
facetKey={facet.key}
facetValue={facet.value}
fullText={searchQuery?.variables?.fullText}
initialMap={initialmap}
initialQuery={initialquery}
/>
</div>
)
Expand Down
20 changes: 19 additions & 1 deletion react/components/FacetItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import classNames from 'classnames'
import { useSearchPage } from 'vtex.search-page-context/SearchPageContext'
import { usePixel } from 'vtex.pixel-manager'
import { useIntl } from 'react-intl'
import { useRuntime } from 'vtex.render-runtime'

import { pushFilterManipulationPixelEvent } from '../utils/filterManipulationPixelEvents'
import SettingsContext from './SettingsContext'
Expand Down Expand Up @@ -125,6 +126,17 @@ const FacetItem = ({
intl,
])

const runtimeQuery = useRuntime()?.query

let initialmap
let initialquery

if (searchQuery?.variables?.fullText === undefined) {
initialquery = runtimeQuery?.initialQuery ?? searchQuery?.facets?.queryArgs.query

initialmap = runtimeQuery?.initialMap ?? searchQuery?.facets?.queryArgs?.map
}

return (
<div
className={classes}
Expand All @@ -148,8 +160,14 @@ const FacetItem = ({
setSelected(!selected)
navigateToFacet({ ...facet, title: facetTitle }, preventRouteChange)
}}
value={facet.name}
disabled={shouldDisable}
value={facet.name}
facetKey={facet.key}
facetValue={facet.value}
isClicked={selected.toString()}
fullText={searchQuery?.variables?.fullText}
initialMap={initialmap}
initialQuery={initialquery}
/>
</div>
)
Expand Down