Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(index): warn for inconsistent UI state in development mode #4140

Merged
merged 6 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,9 @@ describe('UI state', () => {
range: {
price: '100:200',
},
menu: {
category: 'Hardware',
},
},
},
});
Expand All @@ -1245,6 +1248,7 @@ To fully reflect the state, some widgets need to be added to the index "indexNam
- \`refinementList\` needs one of these widgets: "refinementList"
- \`hierarchicalMenu\` needs one of these widgets: "hierarchicalMenu"
- \`range\` needs one of these widgets: "rangeInput", "rangeSlider"
- \`menu\` needs one of these widgets: "menu", "menuSelect"

If you do not wish to display widgets but still want to support their search parameters, you can mount "virtual widgets" that don't render anything:

Expand All @@ -1253,12 +1257,14 @@ const virtualPagination = connectPagination(() => null);
const virtualRefinementList = connectRefinementList(() => null);
const virtualHierarchicalMenu = connectHierarchicalMenu(() => null);
const virtualRange = connectRange(() => null);
const virtualMenu = connectMenu(() => null);

search.addWidgets([
virtualPagination({ /* ... */ }),
virtualRefinementList({ /* ... */ }),
virtualHierarchicalMenu({ /* ... */ }),
virtualRange({ /* ... */ })
virtualRange({ /* ... */ }),
virtualMenu({ /* ... */ })
]);
\`\`\`

Expand Down
4 changes: 4 additions & 0 deletions src/widgets/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,15 @@ const index = (props: IndexProps): Index => {
if (__DEV__) {
// Some connectors are responsible for multiple widgets so we need
// to map them.
// eslint-disable-next-line no-inner-declarations
francoischalifour marked this conversation as resolved.
Show resolved Hide resolved
function getWidgetNames(connectorName: string): string[] {
switch (connectorName) {
case 'range':
francoischalifour marked this conversation as resolved.
Show resolved Hide resolved
return ['rangeInput', 'rangeSlider'];

case 'menu':
return ['menu', 'menuSelect'];

default:
return [connectorName];
}
Expand Down