Skip to content

Commit

Permalink
feat(starRating): indicate when any refinement has no effect
Browse files Browse the repository at this point in the history
When min and max used on the starRating widget, we will no indicate on every line if it has any impact. Thus you can decide to hide/disable it.
  • Loading branch information
mthuret authored and vvo committed Jan 31, 2017
1 parent 80b6450 commit c547ae5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/react-instantsearch/src/components/StarRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class StarRating extends Component {

render() {
const {translate, refine, min, max, count, createURL, canRefine} = this.props;

const items = [];
for (let i = max; i >= min; i--) {
const itemCount = count.reduce((acc, item) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-instantsearch/src/connectors/connectRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ export default createConnector({
min: valueMin = min,
max: valueMax = max,
} = getCurrentRefinement(props, searchState);

return {
min,
max,
currentRefinement: {min: valueMin, max: valueMax},
count,
canRefine: true,
canRefine: count.length > 0,
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('connectRange', () => {
max: 10,
currentRefinement: {min: 5, max: 10},
count: [],
canRefine: true,
canRefine: false,
});

const results = {
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('connectRange', () => {
max: 10,
currentRefinement: {min: 6, max: 9},
count: [],
canRefine: true,
canRefine: false,
});

props = getProvidedProps({
Expand All @@ -71,7 +71,7 @@ describe('connectRange', () => {
max: 10,
currentRefinement: {min: 6, max: 9},
count: [],
canRefine: true,
canRefine: false,
});

props = getProvidedProps({
Expand All @@ -85,7 +85,7 @@ describe('connectRange', () => {
max: 10,
currentRefinement: {min: 6, max: 9},
count: [],
canRefine: true,
canRefine: false,
});
});

Expand Down
6 changes: 3 additions & 3 deletions stories/StarRating.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ stories.addDecorator(withKnobs);

stories.add('default', () =>
<WrapWithHits hasPlayground={true} linkedStoryGroup="StarRating">
<StarRating attributeName="rating" max={6}/>
<StarRating attributeName="rating" max={6} min={1}/>
</WrapWithHits>
).add('with panel', () =>
<WrapWithHits>
<Panel title="Ratings">
<StarRating attributeName="rating" max={6}/>
<StarRating attributeName="rating" max={6} min={1}/>
</Panel>
</WrapWithHits>
).add('with panel but no refinement', () =>
<WrapWithHits searchBox={false}>
<Panel title="Ratings">
<StarRating attributeName="rating" max={6}/>
<StarRating attributeName="rating" max={6} min={1}/>
<div style={{display: 'none'}}>
<SearchBox defaultRefinement="ds" />
</div>
Expand Down

0 comments on commit c547ae5

Please sign in to comment.