Skip to content

Commit

Permalink
fix(#1323391): [Example App] Price slider blinking and add range value
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-goupil committed Feb 11, 2025
1 parent ab52563 commit 3dab1ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions front/example-app/src/components/Facets/FacetSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IGraphqlAggregation } from '@elastic-suite/gally-admin-shared'
import { IFilterChange } from '../../types'

import { Container } from './Facet.styled'
import { useState } from 'react'

interface IProps {
activeOptions: string[]
Expand All @@ -16,20 +17,24 @@ function FacetSlider(props: IProps): JSX.Element {
const { activeOptions, filter, id, onChange } = props
const min = Number(filter.options.at(0).value)
const max = Number(filter.options.at(-1).value)
const [value, setValue] = useState<number[]>([min, max])

const marks = [
{
value: min,
label: min,
},
]

if (min !== max) {
marks.push({
value: max,
label: max,
})
}
function handleChange(_: Event, value: number | number[]): void {
onChange(filter, String(value))()

function handleChange(_: Event, value: number[]): void {
onChange(filter, value.join(' - '))()
}

return (
Expand All @@ -39,8 +44,9 @@ function FacetSlider(props: IProps): JSX.Element {
marks={marks}
max={max}
min={min}
onChange={handleChange}
value={Number(activeOptions[0] ?? max)}
onChange={(_e, v: number[]): void => setValue(v)}
onChangeCommitted={(e): void => handleChange(e as Event, value)}
value={activeOptions[0] ? value : [min, max]}
valueLabelDisplay="auto"
/>
</Container>
Expand Down
4 changes: 3 additions & 1 deletion front/example-app/src/services/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export function getProductFilters(
eq: true,
} as IStockTypeDefaultFilterInputType
} else if (activeFilter.filter.type === AggregationType.SLIDER) {
const [min, max] = activeFilter.value.split(' - ')
acc[activeFilter.filter.field as keyof IProductFieldFilterInput] = {
lte: Number(activeFilter.value),
lte: Number(max),
gte: Number(min),
} as IEntityIntegerTypeFilterInput
} else if (
activeFilter.filter.type === AggregationType.CHECKBOX ||
Expand Down

0 comments on commit 3dab1ca

Please sign in to comment.