Skip to content

add data-attributes to the Facets checkbox #696

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
19 changes: 19 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,18 @@ 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 +99,12 @@ const FacetCheckboxListItem = ({
onFilterCheck({ ...facet, title: facetTitle })
}}
value={name}
data-full-text={searchQuery?.variables?.fullText}
data-initial-query={initialquery}
data-initial-map={initialmap}
data-is-clicked={facet.selected.toString()}
data-facet-key={facet.key}
data-facet-value={facet.value}
/>
</div>
)
Expand Down
26 changes: 25 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,18 @@ 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 +161,19 @@ const FacetItem = ({
setSelected(!selected)
navigateToFacet({ ...facet, title: facetTitle }, preventRouteChange)
}}
value={facet.name}
disabled={shouldDisable}
value={facet.value}
facetKey={facet.key}
isClicked={selected.toString()}
fullText={searchQuery?.variables?.fullText}
initialMap={initialmap}
initialQuery={initialquery}
data-full-text={searchQuery?.variables?.fullText}
data-initial-query={initialquery}
data-initial-map={initialmap}
data-is-clicked={selected.toString()}
data-facet-key={facet.key}
data-facet-value={facet.value}
/>
</div>
)
Expand Down