Change SelectSingleFilterMobile props

Pass initialValue instead of all query params.
This commit is contained in:
Hannu Lyytikainen 2018-02-06 15:43:25 +02:00
parent 31e85eab46
commit 01c8136d65
2 changed files with 9 additions and 9 deletions

View file

@ -131,13 +131,15 @@ class SearchFiltersMobileComponent extends Component {
const categoryLabel = intl.formatMessage({
id: 'SearchFiltersMobile.categoryLabel',
});
const initialCategory = urlQueryParams[CATEGORY_URL_PARAM];
const categoryFilter = categories ? (
<SelectSingleFilterMobile
urlQueryParams={urlQueryParams}
urlParam={CATEGORY_URL_PARAM}
paramLabel={categoryLabel}
onSelect={this.onSelectSingle}
options={categories}
initialValue={initialCategory}
intl={intl}
/>
) : null;

View file

@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { object, string, func, arrayOf, shape } from 'prop-types';
import { string, func, arrayOf, shape } from 'prop-types';
import classNames from 'classnames';
import { FormattedMessage } from 'react-intl';
@ -28,12 +28,9 @@ class SelectSingleFilterMobile extends Component {
}
render() {
const { rootClassName, className, urlQueryParams, urlParam, paramLabel, options } = this.props;
const { rootClassName, className, paramLabel, options, initialValue } = this.props;
// current value of this custom attribute filter
const currentValue = urlQueryParams[urlParam];
const labelClass = currentValue ? css.filterLabelSelected : css.filterLabel;
const labelClass = initialValue ? css.filterLabelSelected : css.filterLabel;
const optionsContainerClass = this.state.isOpen
? css.optionsContainerOpen
@ -54,7 +51,7 @@ class SelectSingleFilterMobile extends Component {
<div className={optionsContainerClass}>
{options.map(option => {
// check if this option is selected
const selected = currentValue === option.key;
const selected = initialValue === option.key;
// menu item border class
const optionBorderClass = selected ? css.optionBorderSelected : css.optionBorder;
return (
@ -77,12 +74,12 @@ class SelectSingleFilterMobile extends Component {
SelectSingleFilterMobile.defaultProps = {
rootClassName: null,
className: null,
initialValue: null,
};
SelectSingleFilterMobile.propTypes = {
rootClassName: string,
className: string,
urlQueryParams: object.isRequired,
urlParam: string.isRequired,
paramLabel: string.isRequired,
onSelect: func.isRequired,
@ -93,6 +90,7 @@ SelectSingleFilterMobile.propTypes = {
label: string.isRequired,
})
).isRequired,
initialValue: string,
};
export default SelectSingleFilterMobile;