From a176df415457cb501505482f563e78e9fec33b08 Mon Sep 17 00:00:00 2001 From: Hannu Lyytikainen Date: Thu, 8 Feb 2018 13:49:14 +0200 Subject: [PATCH] Add features filtering to mobile search --- .../SearchFiltersMobile.js | 51 +++++++++++++++++-- src/containers/SearchPage/SearchPage.js | 1 + .../__snapshots__/SearchPage.test.js.snap | 36 +++++++++++++ src/translations/en.json | 1 + 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/components/SearchFiltersMobile/SearchFiltersMobile.js b/src/components/SearchFiltersMobile/SearchFiltersMobile.js index 7e2d3cca..d224302a 100644 --- a/src/components/SearchFiltersMobile/SearchFiltersMobile.js +++ b/src/components/SearchFiltersMobile/SearchFiltersMobile.js @@ -7,11 +7,18 @@ import { omit, toPairs } from 'lodash'; import routeConfiguration from '../../routeConfiguration'; import { createResourceLocatorString } from '../../util/routes'; -import { SecondaryButton, ModalInMobile, Button, SelectSingleFilterMobile } from '../../components'; +import { + SecondaryButton, + ModalInMobile, + Button, + SelectSingleFilterMobile, + SelectMultipleFilterMobile, +} from '../../components'; import css from './SearchFiltersMobile.css'; const CATEGORY_URL_PARAM = 'pub_category'; -const allowedCategories = [CATEGORY_URL_PARAM]; +const FEATURES_URL_PARAM = 'pub_amenities'; +const allowedCategories = [CATEGORY_URL_PARAM, FEATURES_URL_PARAM]; const validateParamValue = value => value !== null && value !== undefined && value.length > 0; const validateParamKey = key => allowedCategories.includes(key); @@ -33,7 +40,8 @@ class SearchFiltersMobileComponent extends Component { this.cancelFilters = this.cancelFilters.bind(this); this.closeFilters = this.closeFilters.bind(this); this.resetAll = this.resetAll.bind(this); - this.onSelectSingle = this.onSelectSingle.bind(this); + this.handleSelectSingle = this.handleSelectSingle.bind(this); + this.handleSelectMultiple = this.handleSelectMultiple.bind(this); } // Open filters modal, set the initial parameters to current ones @@ -65,7 +73,7 @@ class SearchFiltersMobileComponent extends Component { this.setState({ isFiltersOpenOnMobile: false }); } - onSelectSingle(urlParam, option) { + handleSelectSingle(urlParam, option) { const { urlQueryParams, history } = this.props; // query parameters after selecting the option @@ -77,6 +85,17 @@ class SearchFiltersMobileComponent extends Component { history.push(createResourceLocatorString('SearchPage', routeConfiguration(), {}, queryParams)); } + handleSelectMultiple(urlParam, options) { + const { urlQueryParams, history } = this.props; + + const queryParams = + options && options.length > 0 + ? { ...urlQueryParams, [FEATURES_URL_PARAM]: options.join(',') } + : omit(urlQueryParams, FEATURES_URL_PARAM); + + history.push(createResourceLocatorString('SearchPage', routeConfiguration(), {}, queryParams)); + } + // Reset all filter query parameters resetAll(e) { const { urlQueryParams, history } = this.props; @@ -102,6 +121,7 @@ class SearchFiltersMobileComponent extends Component { onMapIconClick, onManageDisableScrolling, categories, + features, intl, } = this.props; @@ -139,13 +159,30 @@ class SearchFiltersMobileComponent extends Component { ) : null; + const featuresLabel = intl.formatMessage({ id: 'SearchFiltersMobile.featuresLabel' }); + + const initialFeatures = !!urlQueryParams[FEATURES_URL_PARAM] + ? urlQueryParams[FEATURES_URL_PARAM].split(',') + : []; + + const featuresFilter = features ? ( + + ) : null; + return (
@@ -175,6 +212,7 @@ class SearchFiltersMobileComponent extends Component {
{categoryFilter} + {featuresFilter}