Skip to content

Commit d71f56a

Browse files
committed
Review fixes
1 parent 2c2f1e6 commit d71f56a

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/components/core/filters/filter-checkboxes.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import type { FilterValue, FilterTypeProps } from './types';
55
import styles from './filter-checkboxes.css';
66

77
const FilterCheckboxes = (props: FilterTypeProps): Element<*> => {
8+
89
const term = (props.term || '').toUpperCase();
910
const {
1011
onSelectFacet = (a, b, c) => {},
1112
values = [],
12-
omitParenthesesOnCounts,
13+
renderCount,
1314
} = props;
1415

1516
const controls = values.map((facetValue) => {
1617
const { count, label, selected, value } = facetValue;
1718
const onSelect = () => onSelectFacet(term, value, !selected);
18-
const countText = omitParenthesesOnCounts ? count : `(${count})`;
1919

2020
return (
2121
<div styleName="filter-value" key={label}>
@@ -30,7 +30,7 @@ const FilterCheckboxes = (props: FilterTypeProps): Element<*> => {
3030
/>
3131
<div styleName="filter-label">
3232
{label}
33-
<span styleName="count">&nbsp;{countText}</span>
33+
<span styleName="count">&nbsp;{renderCount(count)}</span>
3434
</div>
3535
</label>
3636
</div>

src/components/core/filters/filter-group.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ type State = {
1111
expanded: boolean,
1212
};
1313

14+
type DefaultProps = {
15+
renderCount: Function,
16+
};
17+
1418
export default class FilterGroup extends Component {
1519
props: FilterGroupProps;
1620
state: State = { expanded: this.props.initiallyExpanded };
1721

22+
static defaultProps: DefaultProps = {
23+
renderCount: (count: number): string => `(${count})`,
24+
}
25+
1826
selectedCount = () => {
1927
const { values = [] } = this.props;
2028
return values.reduce((acc, val) => {
@@ -26,21 +34,21 @@ export default class FilterGroup extends Component {
2634
toggleExpansion = () => this.setState({ expanded: !this.state.expanded });
2735

2836
render() {
29-
const { children, label, term, values, omitParenthesesOnCounts } = this.props;
37+
const { children, label, term, values, renderCount } = this.props;
3038
const {
3139
onClearFacet = () => {},
3240
onSelectFacet = () => {},
3341
} = this.props;
3442
const { expanded } = this.state;
3543

3644
const updatedChildren = React.Children.map(children, (child) => {
37-
return React.cloneElement(child, { onSelectFacet, term, values, omitParenthesesOnCounts });
45+
return React.cloneElement(child, { onSelectFacet, term, values, renderCount });
3846
});
3947

4048
return (
4149
<div styleName="group">
4250
<FilterHeader
43-
omitParenthesesOnCounts={omitParenthesesOnCounts}
51+
renderCount={renderCount}
4452
count={this.selectedCount()}
4553
expanded={expanded}
4654
onClear={onClearFacet}

src/components/core/filters/filter-header.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ type Props = {
99
expanded: boolean,
1010
onClear: Function,
1111
onClick: Function,
12-
omitParenthesesOnCounts?: boolean,
12+
renderCount: Function,
1313
};
1414

1515
const FilterHeader = (props: Props): Element<*> => {
16-
const { children, count, expanded, onClear, onClick, omitParenthesesOnCounts } = props;
16+
17+
const { children, count, expanded, onClear, onClick, renderCount } = props;
1718
const iconStyle = expanded ? 'icon-minus' : 'icon-plus';
18-
const countText = omitParenthesesOnCounts ? count : `(${count})`;
1919

2020
return (
2121
<div styleName="header">
@@ -28,7 +28,7 @@ const FilterHeader = (props: Props): Element<*> => {
2828
>
2929
{children}
3030
{count > 0 && (
31-
<span styleName="count">&nbsp;{countText}</span>
31+
<span styleName="count">&nbsp;{renderCount(count)}</span>
3232
)}
3333
</a>
3434
</span>

src/components/core/filters/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type FilterTypeProps = {
1616
onSelectFacet?: Function,
1717
term?: string,
1818
values?: Array<FilterValue>,
19-
omitParenthesesOnCounts?: boolean,
19+
renderCount: Function,
2020
};
2121

2222

@@ -28,5 +28,5 @@ export type FilterGroupProps = {
2828
onClearFacet?: Function,
2929
onSelectFacet?: Function,
3030
initiallyExpanded?: boolean,
31-
omitParenthesesOnCounts?: boolean,
31+
renderCount?: Function,
3232
};

0 commit comments

Comments
 (0)