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

refactor(lodash): remove fill #2454

Merged
merged 1 commit into from
May 16, 2019
Merged
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
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