-
Notifications
You must be signed in to change notification settings - Fork 157
feat(ais-dynamic-widgets): add implementation #922
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c0d1823:
|
2dcf646
to
6651f6c
Compare
52c2475
to
27ecb1f
Compare
27ecb1f
to
0992be7
Compare
Adds a new widget _ais-experimental-dynamic-widgets_ 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. ```vue <template> <ais-experimental-dynamic-widgets :transform-items="transformItems"> <ais-refinement-list attribute="test1" /> <ais-menu attribute="test2" /> <ais-panel> <ais-hierarchical-menu :attributes="hierarchicalAttributes" /> </ais-panel> </ais-experimental-dynamic-widgets> </template> <script> export default { data() { return { hierarchicalAttributes: ["test3", "unused"], }; }, methods(_attributes, { results }) { // add a condition based on the results, eg. if you add the ordering via a query rule: return results.userData[0].facetOrdering; }, }; </script> ``` See also: algolia/instantsearch#4687
0992be7
to
895435a
Compare
Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com>
<!-- 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
<!-- 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
} | ||
}); | ||
|
||
// by default, render everything, but hidden so that the routing doesn't disappear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this behavior result in an unexpected UI flash were some widget will appear and then get removed because computed based on state.attributesToRender
?
What if we don't render anything when we don't have a state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that the widgets we render initially are hidden, so this won't cause a flash, but possibly slightly delayed visuals compared to server side rendering (which solves this, as the widget information is available on that server + initial frontend render)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I think I rather meant: won't this results in an unnecessary search parameters computation because it mounts widgets that will likely get removed?
Why don't we render nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we render nothing, the parameters of the URL can't be applied unfortunately, this was the best workaround I found
* 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go!
…arch#922) * feat(ais-dynamic-widgets): add implementation Adds a new widget _ais-experimental-dynamic-widgets_ 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. ```vue <template> <ais-experimental-dynamic-widgets :transform-items="transformItems"> <ais-refinement-list attribute="test1" /> <ais-menu attribute="test2" /> <ais-panel> <ais-hierarchical-menu :attributes="hierarchicalAttributes" /> </ais-panel> </ais-experimental-dynamic-widgets> </template> <script> export default { data() { return { hierarchicalAttributes: ["test3", "unused"], }; }, methods: { 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; } }, }; </script> ``` See also: #4687 Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com>
Summary
Adds a new widget ais-experimental-dynamic-widgets that can be used to conditionally render other widgets. This condition is based on the search results, by default results.facetOrdering.facet.values, but can be overridden using transformItems
Result
See also: