Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
refactor(lodash): remove fill
Browse files Browse the repository at this point in the history
I replaced this by the `range` utility merged earlier, since it's basically what was needed here.

IFW-741
  • Loading branch information
Haroenv committed May 16, 2019
1 parent 1a9511c commit 0bc18b8
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/react-instantsearch-dom/src/components/RatingMenu.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { find, fill } from 'lodash';
import { find } from 'lodash';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { translatable } from 'react-instantsearch-core';
import { createClassNames } from '../core/utils';
import { createClassNames, range } from '../core/utils';

const cx = createClassNames('RatingMenu');

Expand Down Expand Up @@ -139,14 +139,13 @@ class RatingMenu extends Component {
const limitMin = min !== undefined && min >= 0 ? min : 1;
const limitMax = max !== undefined && max >= 0 ? max : 0;
const inclusiveLength = limitMax - limitMin + 1;
const safeInclusiveLength = Math.max(inclusiveLength, 0);

const values = count
.map(item => ({ ...item, value: parseFloat(item.value) }))
.filter(item => item.value >= limitMin && item.value <= limitMax);

const range = fill(new Array(safeInclusiveLength), null)
.map((_, index) => {
const items = range({ start: 0, end: Math.max(inclusiveLength, 0) })
.map(index => {
const element = find(values, item => item.value === limitMax - index);
const placeholder = { value: limitMax - index, count: 0, total: 0 };

Expand All @@ -159,19 +158,18 @@ class RatingMenu extends Component {
total: index === 0 ? item.count : acc[index - 1].total + item.count,
}),
[]
)
.map((item, index, arr) =>
this.buildItem({
lowerBound: item.value,
count: item.total,
isLastSelectableItem: arr.length - 1 === index,
max: limitMax,
translate,
createURL,
})
);

const items = range.map((item, index) =>
this.buildItem({
lowerBound: item.value,
count: item.total,
isLastSelectableItem: range.length - 1 === index,
max: limitMax,
translate,
createURL,
})
);

return (
<div
className={classNames(cx('', !canRefine && '-noRefinement'), className)}
Expand Down

0 comments on commit 0bc18b8

Please sign in to comment.