Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(connectQueryRules): fix crash when using connectQueryRules with m…
Browse files Browse the repository at this point in the history
…ultiple indexes (#2903)
  • Loading branch information
Yannick Croissant committed Mar 27, 2020
1 parent b7e104d commit c66d612
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,24 @@ Consider using \`transformRuleContexts\` to minimize the number of rules sent to
'ais-price-3000',
]);
});

it('sets empty ruleContexts without search state', () => {
const props: ConnectedProps<QueryRulesProps> = {
...defaultPropsMultiIndex,
trackedFilters: {
price: values => values,
},
};
const searchState = {};

const searchParameters = connect.getSearchParameters(
new SearchParameters(),
props,
searchState
);

expect(searchParameters.ruleContexts).toEqual([]);
});
});

describe('transformRuleContexts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ export default createConnector({
return searchParameters;
}

const indexSearchState = hasMultipleIndices({
ais: props.contextValue,
multiIndexContext: props.indexContextValue,
})
? searchState.indices[
getIndexId({
ais: props.contextValue,
multiIndexContext: props.indexContextValue,
})
]
: searchState;
const indexSearchState =
hasMultipleIndices({
ais: props.contextValue,
multiIndexContext: props.indexContextValue,
}) && searchState.indices
? searchState.indices[
getIndexId({
ais: props.contextValue,
multiIndexContext: props.indexContextValue,
})
]
: searchState;

const newRuleContexts = getRuleContextsFromTrackedFilters({
searchState: indexSearchState,
Expand Down

0 comments on commit c66d612

Please sign in to comment.