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(sffv): no error when not providing noResults and no results #2310

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions dev/app/init-builtin-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,25 @@ export default () => {
);
})
)
.add(
'with search inside items (using the default noResults template)',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.refinementList({
container,
attributeName: 'brand',
operator: 'or',
limit: 10,
templates: {
header: 'Searchable brands',
},
searchForFacetValues: {
placeholder: 'Find other brands...',
},
})
);
})
)
.add(
'with operator `and`',
wrapWithHits(container => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
noResults: 'No results',
};
3 changes: 2 additions & 1 deletion src/widgets/refinement-list/refinement-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import filter from 'lodash/filter';
import RefinementList from '../../components/RefinementList/RefinementList.js';
import connectRefinementList from '../../connectors/refinement-list/connectRefinementList.js';
import defaultTemplates from './defaultTemplates.js';
import sffvDefaultTemplates from './defaultTemplates.searchForFacetValue.js';
import getShowMoreConfig from '../../lib/show-more/getShowMoreConfig.js';

import {
Expand Down Expand Up @@ -253,7 +254,7 @@ export default function refinementList(
? prefixKeys('show-more-', showMoreConfig.templates)
: {};
const searchForValuesTemplates = searchForFacetValues
? searchForFacetValues.templates
? searchForFacetValues.templates || sffvDefaultTemplates
: {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition seems a bit complex to me. I'm wondering if something like this is more straightforward:

const searchForValuesTemplates = searchForFacetValues
  ? searchForFacetValues.templates
    ? searchForFacetValues.templates
    : sffvDefaultTemplates
  : {};

It's still a double ternary, but this might be easier to read.

const allTemplates = {
...templates,
Expand Down