mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 03:43:28 +10:00
Add urlParam param to SelectMultipleFilter
Also rename amenities url param.
This commit is contained in:
parent
8c362b6dca
commit
528b6b593d
5 changed files with 18 additions and 14 deletions
|
|
@ -12,7 +12,7 @@ import { createResourceLocatorString } from '../../util/routes';
|
|||
import css from './SearchFilters.css';
|
||||
|
||||
const CATEGORY_URL_PARAM = 'pub_category';
|
||||
const FEATURES_URL_PARAM = 'pub_features';
|
||||
const FEATURES_URL_PARAM = 'pub_amenities';
|
||||
|
||||
const FILTER_OFFSET = -14;
|
||||
|
||||
|
|
@ -47,9 +47,7 @@ const SearchFiltersComponent = props => {
|
|||
const initialFeatures =
|
||||
urlQueryParams[FEATURES_URL_PARAM] && urlQueryParams[FEATURES_URL_PARAM].split(',');
|
||||
|
||||
const handleSelectOptions = options => {
|
||||
console.log('Select features', options);
|
||||
|
||||
const handleSelectOptions = (urlParam, options) => {
|
||||
const queryParams = options
|
||||
? { ...urlQueryParams, [FEATURES_URL_PARAM]: options.join(',') }
|
||||
: omit(urlQueryParams, FEATURES_URL_PARAM);
|
||||
|
|
@ -80,6 +78,7 @@ const SearchFiltersComponent = props => {
|
|||
|
||||
const featuresFilter = features ? (
|
||||
<SelectMultipleFilter
|
||||
urlParam={FEATURES_URL_PARAM}
|
||||
onSubmit={handleSelectOptions}
|
||||
options={features}
|
||||
initialValues={initialFeatures}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import { withRouter } from 'react-router-dom';
|
|||
import SelectMultipleFilter from './SelectMultipleFilter';
|
||||
import { stringify, parse } from '../../util/urlHelpers';
|
||||
|
||||
const URL_PARAM = 'pub_amenities';
|
||||
|
||||
const options = [
|
||||
{
|
||||
key: 'towels',
|
||||
|
|
@ -38,8 +40,8 @@ const options = [
|
|||
},
|
||||
];
|
||||
|
||||
const handleSubmit = (values, history) => {
|
||||
const queryParams = values ? `?${stringify({ pub_amenities: values.join(',') })}` : '';
|
||||
const handleSubmit = (urlParam, values, history) => {
|
||||
const queryParams = values ? `?${stringify({ [urlParam]: values.join(',') })}` : '';
|
||||
history.push(`${window.location.pathname}${queryParams}`);
|
||||
};
|
||||
|
||||
|
|
@ -47,12 +49,13 @@ const AmenitiesFilterComponent = withRouter(props => {
|
|||
const { history, location } = props;
|
||||
|
||||
const params = parse(location.search);
|
||||
const amenities = params.pub_amenities;
|
||||
const amenities = params[URL_PARAM];
|
||||
const initialValues = !!amenities ? amenities.split(',') : [];
|
||||
|
||||
return (
|
||||
<SelectMultipleFilter
|
||||
onSubmit={values => handleSubmit(values, history)}
|
||||
urlParam={URL_PARAM}
|
||||
onSubmit={(urlParam, values) => handleSubmit(urlParam, values, history)}
|
||||
options={options}
|
||||
initialValues={initialValues}
|
||||
contentPlacementOffset={-14}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,10 @@ class SelectMultipleFilter extends Component {
|
|||
}
|
||||
|
||||
handleSubmit(values) {
|
||||
const { onSubmit, urlParam } = this.props;
|
||||
const selectedKeys = valuesToKeys(values);
|
||||
this.setState({ isOpen: false });
|
||||
this.props.onSubmit(selectedKeys);
|
||||
onSubmit(urlParam, selectedKeys);
|
||||
}
|
||||
|
||||
handleClear() {
|
||||
|
|
@ -59,9 +60,9 @@ class SelectMultipleFilter extends Component {
|
|||
}
|
||||
|
||||
handleCancel() {
|
||||
const { onSubmit, initialValues } = this.props;
|
||||
const { onSubmit, initialValues, urlParam } = this.props;
|
||||
this.setState({ isOpen: false });
|
||||
onSubmit(initialValues);
|
||||
onSubmit(urlParam, initialValues);
|
||||
}
|
||||
|
||||
handleBlur(event) {
|
||||
|
|
@ -166,6 +167,7 @@ SelectMultipleFilter.defaultProps = {
|
|||
SelectMultipleFilter.propTypes = {
|
||||
rootClassName: string,
|
||||
className: string,
|
||||
urlParam: string.isRequired,
|
||||
onSubmit: func.isRequired,
|
||||
options: array.isRequired,
|
||||
initialValues: arrayOf(string),
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const SEARCH_WITH_MAP_DEBOUNCE = 300; // Little bit of debounce before search is
|
|||
const BOUNDS_FIXED_PRECISION = 8;
|
||||
|
||||
const CATEGORY_URL_PARAM = 'pub_category';
|
||||
const FEATURES_URL_PARAM = 'pub_features';
|
||||
const FEATURES_URL_PARAM = 'pub_amenities';
|
||||
|
||||
// extract search parameters, including a custom attribute named category
|
||||
const pickSearchParamsOnly = params => {
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ exports[`SearchPageComponent matches snapshot 1`] = `
|
|||
"address": undefined,
|
||||
"bounds": undefined,
|
||||
"origin": undefined,
|
||||
"pub_amenities": undefined,
|
||||
"pub_category": undefined,
|
||||
"pub_features": undefined,
|
||||
}
|
||||
}
|
||||
/>
|
||||
|
|
@ -112,8 +112,8 @@ exports[`SearchPageComponent matches snapshot 1`] = `
|
|||
"address": undefined,
|
||||
"bounds": undefined,
|
||||
"origin": undefined,
|
||||
"pub_amenities": undefined,
|
||||
"pub_category": undefined,
|
||||
"pub_features": undefined,
|
||||
}
|
||||
}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue