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

Commit

Permalink
feat(DynamicWidgets): add implementation (#3056)
Browse files Browse the repository at this point in the history
* feat(DynamicWidgets): add implementation

<!--
  Thanks for submitting a pull request!
  Please provide enough information so that others can review your pull request.
-->

**Summary**

<!--
  Explain the **motivation** for making this change.
  What existing problem does the pull request solve?
  Are there any linked issues?
-->

Adds a new widget _ExperimentalDynamicWidgets_ that can be used to conditionally render other widgets. This condition is based on the search results. At the moment there isn't yet a default way to enforce facet ordering in the Algolia engine, thus the data available to `transformItems` is an empty array. This will change once the Algolia engine adds support for facet ordering and this widget will move out of experimental mode.

**Result**

<!--
  Demonstrate the code is solid.
  Example: The exact commands you ran and their output,
  screenshots / videos if the pull request changes UI.

  You will be able to test out these changes on the deploy
  preview (address will be commented by a bot):

  1. the documentation site (/)
  2. a widget playground (/stories)
-->

```jsx
<DynamicWidgets
  transformItems={(_attributes, { results }) => {
    // add a condition based on the results, eg. if you add the ordering via a query rule:
    return results.userData[0].facetOrdering;
  }}
>
  <HierarchicalMenu
    attributes={[
      'hierarchicalCategories.lvl0',
      'hierarchicalCategories.lvl1',
      'hierarchicalCategories.lvl2',
      'hierarchicalCategories.lvl3',
    ]}
  />
  <Panel>
    <RefinementList attribute="brand" />
  </Panel>
  <Menu attribute="categories" />
</DynamicWidgets>
```

See also:

- algolia/instantsearch#4687
- algolia/vue-instantsearch#922
- DX-1665

* fix TS

* feat: retrieve from results

* update dependencies

* read from facet ordering

* expose widget from root

* change error message and test more

* make and expose a dom component

* update bundlesizes

* clarify test

* redo some of the tests
  • Loading branch information
Haroenv committed Jul 1, 2021
1 parent fddaaef commit 691ef87
Show file tree
Hide file tree
Showing 31 changed files with 1,065 additions and 145 deletions.
2 changes: 1 addition & 1 deletion examples/autocomplete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react-test-renderer": "16.8.6"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"antd": "3.23.2",
"lodash": "4.17.15",
"prop-types": "15.6.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/default-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "6.11.2",
"private": true,
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"qs": "6.8.0",
"react": "16.8.6",
"react-dom": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/e-commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "6.11.2",
"private": true,
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"classnames": "2.2.6",
"qs": "6.8.0",
"react": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/geo-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react-test-renderer": "16.8.6"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"instantsearch.css": "7.3.1",
"qs": "6.8.0",
"react": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "6.11.2",
"private": true,
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"qs": "6.8.0",
"react": "16.8.6",
"react-dom": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-index/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react-test-renderer": "16.8.6"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"instantsearch.css": "7.3.1",
"prop-types": "15.6.0",
"react": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"style-loader": "1.0.0"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"next": "9.1.1",
"prop-types": "15.6.2",
"qs": "6.8.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native-query-suggestions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "jest"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"expo": "37.0.3",
"lodash": "4.17.15",
"prop-types": "15.6.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@ptomasroos/react-native-multi-slider": "2.2.2",
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"expo": "37.0.3",
"lodash": "4.17.15",
"prop-types": "15.6.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-router-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react-test-renderer": "16.8.6"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"instantsearch.css": "7.3.1",
"lodash": "4.17.15",
"prop-types": "15.6.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react-test-renderer": "16.8.6"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"instantsearch.css": "7.3.1",
"lodash": "4.17.15",
"prop-types": "15.6.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/server-side-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"webpack-node-externals": "1.7.2"
},
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"express": "4.17.1",
"prop-types": "15.6.0",
"react": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/tourism/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "6.11.2",
"private": true,
"dependencies": {
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"qs": "6.8.0",
"react": "16.8.6",
"react-dom": "16.8.6",
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"website:build": "yarn build && yarn webpack --config website/webpack.config.js"
},
"devDependencies": {
"@algolia/client-search": "4.8.5",
"@algolia/client-search": "4.9.3",
"@babel/cli": "7.4.4",
"@babel/core": "7.4.5",
"@babel/plugin-proposal-class-properties": "7.4.4",
Expand Down Expand Up @@ -72,7 +72,7 @@
"@wdio/selenium-standalone-service": "5.16.10",
"@wdio/spec-reporter": "5.16.11",
"@wdio/static-server-service": "5.16.10",
"algoliasearch": "4.8.5",
"algoliasearch": "4.9.3",
"argos-cli": "0.1.3",
"babel-eslint": "10.0.2",
"babel-jest": "24.9.0",
Expand Down Expand Up @@ -114,6 +114,7 @@
"react": "16.8.6",
"react-autosuggest": "9.4.3",
"react-dom": "16.8.6",
"react-error-boundary": "3.1.3",
"react-instantsearch-dom": "6.10.3",
"react-instantsearch-dom-maps": "6.10.3",
"react-native": "0.58.4",
Expand All @@ -136,23 +137,23 @@
"bundlesize": [
{
"path": "packages/react-instantsearch/dist/umd/Core.min.js",
"maxSize": "2.95 kB"
"maxSize": "3 kB"
},
{
"path": "packages/react-instantsearch/dist/umd/Connectors.min.js",
"maxSize": "22.1 kB"
"maxSize": "22.5 kB"
},
{
"path": "packages/react-instantsearch/dist/umd/Dom.min.js",
"maxSize": "34.90 kB"
"maxSize": "35.5 kB"
},
{
"path": "packages/react-instantsearch-core/dist/umd/ReactInstantSearchCore.min.js",
"maxSize": "25.80 kB"
"maxSize": "26.5 kB"
},
{
"path": "packages/react-instantsearch-dom/dist/umd/ReactInstantSearchDOM.min.js",
"maxSize": "38.41 kB"
"maxSize": "39 kB"
},
{
"path": "packages/react-instantsearch-dom-maps/dist/umd/ReactInstantSearchDOMMaps.min.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-instantsearch-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@babel/runtime": "^7.1.2",
"algoliasearch-helper": "^3.4.3",
"algoliasearch-helper": "^3.5.3",
"prop-types": "^15.6.2",
"react-fast-compare": "^3.0.0"
},
Expand Down

0 comments on commit 691ef87

Please sign in to comment.