From 123b7bdd8935f7a5929a05bc8d6b2ca09a3cea21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 27 Sep 2018 10:32:49 +0200 Subject: [PATCH 01/16] feat(refinement-list): apply new options, markup and css --- docgen/src/guides/v3-migration.md | 142 +++++++++++++++ .../RefinementList/RefinementList.js | 117 +++++++----- .../RefinementList/RefinementListItem.js | 13 +- .../__tests__/RefinementList-test.js | 104 +++++++++-- .../__tests__/RefinementListItem-test.js | 4 +- .../__snapshots__/RefinementList-test.js.snap | 88 +++++++++ .../RefinementListItem-test.js.snap | 4 +- .../__tests__/connectRefinementList-test.js | 49 ++--- .../refinement-list/connectRefinementList.js | 56 +++--- .../hierarchical-menu-test.js.snap | 18 +- .../__tests__/__snapshots__/menu-test.js.snap | 6 +- .../numeric-refinement-list-test.js.snap | 9 +- .../refinement-list-test.js.snap | 36 ++-- .../__tests__/refinement-list-test.js | 168 ++++++------------ .../refinement-list/defaultTemplates.js | 4 +- .../refinement-list/refinement-list.js | 123 +++++++------ .../__snapshots__/star-rating-test.js.snap | 6 +- 17 files changed, 623 insertions(+), 324 deletions(-) create mode 100644 src/components/RefinementList/__tests__/__snapshots__/RefinementList-test.js.snap diff --git a/docgen/src/guides/v3-migration.md b/docgen/src/guides/v3-migration.md index 13a839e88b..79d890e8b5 100644 --- a/docgen/src/guides/v3-migration.md +++ b/docgen/src/guides/v3-migration.md @@ -497,6 +497,138 @@ Widget removed. ``` +### RefinementList + +#### CSS classes + +| Before | After | +| ----------------------------------- | --------------------------------------- | +| `ais-refinement-list` | `ais-RefinementList` | +| | `ais-RefinementList--noRefinement` | +| | `ais-RefinementList-noResults` | +| `ais-refinement-list--header` | | +| `ais-refinement-list--body` | | +| `ais-refinement-list--footer` | | +| `ais-refinement-list--list` | `ais-RefinementList-list` | +| `ais-refinement-list--item` | `ais-RefinementList-item` | +| `ais-refinement-list--item__active` | `ais-RefinementList-item--selected` | +| `ais-refinement-list--label` | `ais-RefinementList-label` | +| `ais-refinement-list--checkbox` | `ais-RefinementList-checkbox` | +| | `ais-RefinementList-labelText` | +| `ais-refinement-list--count` | `ais-RefinementList-count` | +| | `ais-RefinementList-showMore` | +| | `ais-RefinementList-showMore--disabled` | + +#### Options + +| Before | After | +| ---------------------- | ------------ | +| `attributeName` | `attribute` | +| `searchForFacetValues` | `searchable` | + +* `escapeFacetValues` defaults to `true` +* `isAlwaysActive` defaults to `true` + +#### Markup + +##### Default + +```html +
+ + + +
+``` + +##### Show more disabled + +```html +
+ + + +
+``` + +##### With search and no results + +```html +
+ +
No results.
+
+``` + ### SortBy #### Options @@ -600,3 +732,13 @@ We've moved the `label` into the `templates.labelText` template to make it consi | Before | After | | ------------------- | -------------------- | | `excludeAttributes` | `excludedAttributes` | + +### connectRefinementList + +#### Options + +| Before | After | +| --------------- | ----------- | +| `attributeName` | `attribute` | + +* `escapeFacetValues` defaults to `true` diff --git a/src/components/RefinementList/RefinementList.js b/src/components/RefinementList/RefinementList.js index 4e239964a4..1a4697e76e 100644 --- a/src/components/RefinementList/RefinementList.js +++ b/src/components/RefinementList/RefinementList.js @@ -9,10 +9,7 @@ import isEqual from 'lodash/isEqual'; import SearchBox from '../SearchBox'; -import autoHideContainerHOC from '../../decorators/autoHideContainer.js'; -import headerFooterHOC from '../../decorators/headerFooter.js'; - -export class RawRefinementList extends Component { +class RefinementList extends Component { constructor(props) { super(props); this.handleItemClick = this.handleItemClick.bind(this); @@ -37,7 +34,7 @@ export class RawRefinementList extends Component { const hasChildren = facetValue.data && facetValue.data.length > 0; if (hasChildren) { subItems = ( - - ) : ( - undefined - ); + ) : null; - const shouldDisableSearchInput = + const shouldDisableSearchBox = this.props.searchIsAlwaysActive !== true && !(this.props.isFromSearch || !this.props.hasExhaustiveItems); - const searchInput = this.props.searchFacetValues ? ( - { - this.searchbox = i; - }} - placeholder={this.props.searchPlaceholder} - onChange={this.props.searchFacetValues} - onValidate={() => this.refineFirstValue()} - disabled={shouldDisableSearchInput} - /> + const searchBox = this.props.searchFacetValues ? ( +
+ { + this.searchbox = i; + }} + placeholder={this.props.searchPlaceholder} + onChange={this.props.searchFacetValues} + onValidate={() => this.refineFirstValue()} + disabled={shouldDisableSearchBox} + /> +
) : null; + const facetValues = + this.props.facetValues && this.props.facetValues.length > 0 ? ( +
    + {this.props.facetValues.map(this._generateFacetItem, this)} +
+ ) : null; + const noResults = this.props.searchFacetValues && this.props.isFromSearch && this.props.facetValues.length === 0 ? ( -