Commit 8524d128 authored by Denis Sedura's avatar Denis Sedura

[RNA-822] Fix filters

parent b4d7433e
......@@ -2,9 +2,9 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { createSelector } from 'reselect'
import { debounce, isEqual, union, without, snakeCase, capitalize } from 'lodash'
import { debounce, isEqual, union, without, snakeCase, capitalize, isEmpty } from 'lodash'
import { createSearchInventoryListSelector } from 'tipsi_api/selectors'
import { loadSmartFilters, clearPaginationCache } from 'tipsi_api/actions'
import { loadSmartFilters, clearPaginationCache, STORE_SEARCH_KEY } from 'tipsi_api/actions'
import { updateStoreFilters, clearStoreFilters } from '../../../actions'
import tabItems from '../../../constants/storeTabItems'
import {
......@@ -19,8 +19,8 @@ function enhanceFilters(ComposedComponent) {
...initialFiltersState,
...storeFilters,
})
const WINE_FILTERS = ['wine_type', 'unit_size', 'varietal', 'country', 'region', 'sub_region']
const DRINK_FILTERS = ['tag', 'country', 'unit_size']
const WINE_FILTERS = ['price', 'wine_type', 'unit_size', 'varietal', 'country', 'region', 'sub_region']
const DRINK_FILTERS = ['price', 'tag', 'country', 'unit_size']
const PAGE_SIZE = 7
class Wrapper extends Component {
......@@ -45,15 +45,21 @@ function enhanceFilters(ComposedComponent) {
state = withInitialFilters(this.props.storeFilters)
getSmartFilterTypes = (storeFilters = {}, nextStoreFilters = {}) => {
shouldComponentUpdate(nextProps) {
console.log('shouldComponentUpdate', this.props, nextProps)
return !isEqual(this.props, nextProps)
}
getSmartFilterTypes(storeFilters = {}, nextStoreFilters = {}) {
const availableSmartFilterTypes = this.getDrinkType() === 'wine' ? WINE_FILTERS : DRINK_FILTERS
if (!storeFilters && !nextStoreFilters) {
if (isEmpty(nextStoreFilters)) {
return availableSmartFilterTypes
}
const changedSmartFilterTypes = union(
Object.keys(storeFilters), Object.keys(nextStoreFilters)
Object.keys(storeFilters),
Object.keys(nextStoreFilters)
)
.filter(key => !isEqual(storeFilters[key], nextStoreFilters[key]))
.map(snakeCase)
......@@ -94,6 +100,7 @@ function enhanceFilters(ComposedComponent) {
pageSize: PAGE_SIZE,
page: 1,
filters: convertFiltersToQuery(this.props.storeFilters),
query: this.props.searchQuery,
}
)
}
......@@ -116,7 +123,9 @@ function enhanceFilters(ComposedComponent) {
}))
)
handleBudgetValueChange = budget => this.updateFilters({ budget })
handleSortChange = orderBy => this.updateFilters({ orderBy })
handleBudgetValueChange = price => this.updateFilters({ price })
handleRatingValueChange = rating => this.updateFilters({ rating })
......@@ -157,6 +166,7 @@ function enhanceFilters(ComposedComponent) {
clearSmartFiltersCache={this.clearSmartFiltersCache}
loadSmartFilters={this.loadSmartFilters}
updateFilters={this.updateFilters}
handleSortChange={this.handleSortChange}
handleMapWineTypes={this.handleMapWineTypes}
handleBudgetValueChange={this.handleBudgetValueChange}
handleRatingValueChange={this.handleRatingValueChange}
......@@ -185,13 +195,15 @@ function enhanceFilters(ComposedComponent) {
const mapStateToProps = createSelector(
createSearchInventoryListSelector(searchInventoryKeySelector),
storeFiltersSelector,
({ result, count, isLoading }, storeFilters) => ({
state => state.searchQueries,
({ count, isLoading }, storeFilters, searchQueries) => ({
isLoading,
storeFilters,
itemsCount: count,
storeWines: result,
searchQuery: searchQueries[STORE_SEARCH_KEY],
})
)
return connect(mapStateToProps, {
updateStoreFilters,
clearStoreFilters,
......
......@@ -28,10 +28,10 @@ const tipsiMiddleware = createApiMiddleware({
}),
})
const middleware = [tipsiMiddleware, thunk, analyticsMiddleware ,logger]
const middleware = [tipsiMiddleware, thunk, analyticsMiddleware]
// if (__DEV__) {
// middleware.push(require('redux-logger')())
// middleware.push(logger)
// }
const createStoreWithNavigation = createNavigationEnabledStore({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment