-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Configure): add configure parameters in search state (#1935)
fixes #1863
- Loading branch information
Showing
3 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
37 changes: 33 additions & 4 deletions
37
packages/react-instantsearch/src/connectors/connectConfigure.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
import createConnector from '../core/createConnector.js'; | ||
import omit from 'lodash/omit'; | ||
import {omit, isEmpty} from 'lodash'; | ||
|
||
const namespace = 'configure'; | ||
|
||
function getCurrentRefinement(props, searchState) { | ||
return Object.keys(props).reduce((acc, item) => { | ||
acc[item] = searchState[namespace] && searchState[namespace][item] | ||
? searchState[namespace][item] : props[item]; | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
export default createConnector({ | ||
displayName: 'AlgoliaConfigure', | ||
getProvidedProps() { return {}; }, | ||
getSearchParameters(searchParameters, props) { | ||
const configuration = omit(props, 'children'); | ||
getProvidedProps() { | ||
return {}; | ||
}, | ||
getSearchParameters(searchParameters, props, searchState) { | ||
const items = omit(props, 'children'); | ||
const configuration = getCurrentRefinement(items, searchState); | ||
return searchParameters.setQueryParameters(configuration); | ||
}, | ||
transitionState(props, prevSearchState, nextSearchState) { | ||
const items = omit(props, 'children'); | ||
return { | ||
...nextSearchState, | ||
[namespace]: {...items, ...nextSearchState[namespace]}, | ||
}; | ||
}, | ||
cleanUp(props, searchState) { | ||
const configureState = Object.keys(searchState[namespace]).reduce((acc, item) => { | ||
if (!props[item]) { | ||
acc[item] = searchState[namespace][item]; | ||
} | ||
return acc; | ||
}, {}); | ||
return isEmpty(configureState) ? omit(searchState, namespace) : {...searchState, [namespace]: configureState}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters