Skip to content

Commit fbf4022

Browse files
committed
fix(priceRanges): plug the URL computation. Fix #354
1 parent a6266e8 commit fbf4022

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

components/PriceRanges.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ class PriceRange extends React.Component {
1919
<div>
2020
{this.props.facetValues.map(facetValue => {
2121
var key = facetValue.from + '_' + facetValue.to;
22+
var url;
23+
if (this.props.createURL) {
24+
url = this.props.createURL(facetValue.from, facetValue.to, facetValue.isRefined);
25+
} else {
26+
url = '#';
27+
}
2228
return (
2329
<a
2430
className={cx(this.props.cssClasses.range, {[this.props.cssClasses.active]: facetValue.isRefined})}
25-
href="#"
31+
href={url}
2632
key={key}
2733
onClick={this.refine.bind(this, facetValue.from, facetValue.to)}
2834
>

widgets/price-ranges/price-ranges.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function priceRanges({
9999
helper.search();
100100
},
101101

102-
render: function({results, helper, templatesConfig}) {
102+
render: function({results, helper, templatesConfig, state, createURL}) {
103103
var PriceRanges = autoHideContainer(headerFooter(require('../../components/PriceRanges')));
104104
var facetValues;
105105

@@ -133,6 +133,18 @@ function priceRanges({
133133

134134
ReactDOM.render(
135135
<PriceRanges
136+
createURL={(from, to, isRefined) => {
137+
var newState = state.clearRefinements(facetName);
138+
if (!isRefined) {
139+
if (typeof from !== 'undefined') {
140+
newState = newState.addNumericRefinement(facetName, '>', from - 1);
141+
}
142+
if (typeof to !== 'undefined') {
143+
newState = newState.addNumericRefinement(facetName, '<', to + 1);
144+
}
145+
}
146+
return createURL(newState);
147+
}}
136148
cssClasses={cssClasses}
137149
facetValues={facetValues}
138150
hasResults={results.hits.length > 0}

0 commit comments

Comments
 (0)