From 618d30af919697cfe0445e8c6904195b21ea515f Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Fri, 20 May 2022 16:24:45 +0200 Subject: [PATCH] feat(templates): various improvements (#572) Co-authored-by: Fabien Motte --- e2e/__snapshots__/templates.test.js.snap | 73 +++++++++++++------ .../src/app/app.component.html.hbs | 5 +- src/templates/InstantSearch.js/index.html.hbs | 5 +- src/templates/InstantSearch.js/src/app.js.hbs | 18 +++-- .../React InstantSearch Hooks/src/App.tsx.hbs | 2 + .../React InstantSearch/public/index.html | 2 +- .../React InstantSearch/src/App.js.hbs | 14 +++- .../Vue InstantSearch with Vue 3/index.html | 2 +- .../Vue InstantSearch with Vue 3/src/App.vue | 11 ++- .../Vue InstantSearch/public/index.html | 2 +- src/templates/Vue InstantSearch/src/App.vue | 24 ++++-- 11 files changed, 111 insertions(+), 47 deletions(-) diff --git a/e2e/__snapshots__/templates.test.js.snap b/e2e/__snapshots__/templates.test.js.snap index 1b2ec9e8f..8a3d7c44e 100644 --- a/e2e/__snapshots__/templates.test.js.snap +++ b/e2e/__snapshots__/templates.test.js.snap @@ -319,10 +319,15 @@ exports[`Templates Angular InstantSearch File content: src/app/app.component.htm
+
- - + + + + + +
@@ -3084,7 +3089,7 @@ exports[`Templates InstantSearch.js File content: index.html 1`] = ` - + @@ -3113,10 +3118,9 @@ exports[`Templates InstantSearch.js File content: index.html 1`] = `
+
- -
@@ -3234,25 +3238,30 @@ search.addWidgets([ }, }), instantsearch.widgets.configure({ - facets: ['*'], - maxValuesPerFacet: 20, + hitsPerPage: 8, }), instantsearch.widgets.dynamicWidgets({ container: '#dynamic-widgets', fallbackWidget({ container, attribute }) { - return instantsearch.widgets.refinementList({ + return instantsearch.widgets.panel({ templates: { header: attribute } })( + instantsearch.widgets.refinementList + )({ container, attribute, }); }, widgets: [ container => - instantsearch.widgets.refinementList({ + instantsearch.widgets.panel({ + templates: { header: 'facet1' }, + })(instantsearch.widgets.refinementList)({ container, attribute: 'facet1', }), container => - instantsearch.widgets.refinementList({ + instantsearch.widgets.panel({ + templates: { header: 'facet2' }, + })(instantsearch.widgets.refinementList)({ container, attribute: 'facet2', }), @@ -5611,7 +5620,7 @@ exports[`Templates React InstantSearch File content: public/index.html 1`] = ` Do not use @7 in production, use a complete version like x.x.x, see website for latest version: https://www.algolia.com/doc/guides/building-search-ui/installation/react/#load-the-style --> - + react-instantsearch-app @@ -5713,10 +5722,11 @@ exports[`Templates React InstantSearch File content: src/App.js 1`] = ` import algoliasearch from 'algoliasearch/lite'; import { InstantSearch, + Configure, Hits, SearchBox, - Configure, DynamicWidgets, + Panel, RefinementList, Pagination, Highlight, @@ -5743,12 +5753,16 @@ function App() {
+
- - - + + + + + +
@@ -6025,6 +6039,7 @@ em { exports[`Templates React InstantSearch Hooks File content: src/App.tsx 1`] = ` "import algoliasearch from 'algoliasearch/lite'; import { + Configure, DynamicWidgets, Highlight, Hits, @@ -6062,6 +6077,7 @@ export function App() {
+
@@ -8176,7 +8192,7 @@ exports[`Templates Vue InstantSearch File content: public/index.html 1`] = ` Do not use @7 in production, use a complete version like x.x.x, see website for latest version: https://www.algolia.com/doc/guides/building-search-ui/installation/react/#load-the-style --> - + vue-instantsearch-app @@ -8208,12 +8224,18 @@ exports[`Templates Vue InstantSearch File content: src/App.vue 1`] = `
+
- - - + + + + + + + +
@@ -8443,7 +8465,7 @@ exports[`Templates Vue InstantSearch with Vue 3 File content: index.html 1`] = ` Do not use @7 in production, use a complete version like x.x.x, see website for latest version: https://www.algolia.com/doc/guides/building-search-ui/installation/react/#load-the-style --> - + vue-instantsearch-app @@ -8487,11 +8509,18 @@ exports[`Templates Vue InstantSearch with Vue 3 File content: src/App.vue 1`] =
+
- - + + + + + + + +
diff --git a/src/templates/Angular InstantSearch/src/app/app.component.html.hbs b/src/templates/Angular InstantSearch/src/app/app.component.html.hbs index 71d94515c..4ec69e8d4 100644 --- a/src/templates/Angular InstantSearch/src/app/app.component.html.hbs +++ b/src/templates/Angular InstantSearch/src/app/app.component.html.hbs @@ -12,11 +12,14 @@
+
{{#if attributesForFaceting}}
{{#each attributesForFaceting}} - + + + {{/each}}
diff --git a/src/templates/InstantSearch.js/index.html.hbs b/src/templates/InstantSearch.js/index.html.hbs index 10bc9cf39..17dc67309 100644 --- a/src/templates/InstantSearch.js/index.html.hbs +++ b/src/templates/InstantSearch.js/index.html.hbs @@ -8,7 +8,7 @@ - + @@ -43,10 +43,9 @@
+
- -
diff --git a/src/templates/InstantSearch.js/src/app.js.hbs b/src/templates/InstantSearch.js/src/app.js.hbs index 6e1725b51..c70e08aac 100644 --- a/src/templates/InstantSearch.js/src/app.js.hbs +++ b/src/templates/InstantSearch.js/src/app.js.hbs @@ -31,22 +31,26 @@ search.addWidgets([ }, {{/if}} }), - {{#if flags.dynamicWidgets}} instantsearch.widgets.configure({ - facets: ['*'], - maxValuesPerFacet: 20, + hitsPerPage: 8, }), + {{#if flags.dynamicWidgets}} instantsearch.widgets.dynamicWidgets({ container: '#dynamic-widgets', fallbackWidget({ container, attribute }) { - return instantsearch.widgets.refinementList({ + return instantsearch.widgets.panel({ templates: { header: attribute } })( + instantsearch.widgets.refinementList + )({ container, attribute, }); }, widgets: [ {{#each attributesForFaceting}} - container => instantsearch.widgets.refinementList({ + container => + instantsearch.widgets.panel({ + templates: { header: '{{this}}' }, + })(instantsearch.widgets.refinementList)({ container, attribute: '{{this}}', }), @@ -55,7 +59,9 @@ search.addWidgets([ }), {{else}} {{#each attributesForFaceting}} - instantsearch.widgets.refinementList({ + instantsearch.widgets.panel({ + templates: { header: '{{this}}' }, + })(instantsearch.widgets.refinementList)({ container: '#{{this}}-list', attribute: '{{this}}', }), diff --git a/src/templates/React InstantSearch Hooks/src/App.tsx.hbs b/src/templates/React InstantSearch Hooks/src/App.tsx.hbs index 4859e2d4d..4d2d9782c 100644 --- a/src/templates/React InstantSearch Hooks/src/App.tsx.hbs +++ b/src/templates/React InstantSearch Hooks/src/App.tsx.hbs @@ -1,5 +1,6 @@ import algoliasearch from 'algoliasearch/lite'; import { + Configure, {{#if flags.dynamicWidgets}} DynamicWidgets, {{#unless attributesForFaceting}} @@ -46,6 +47,7 @@ export function App() {
+
{{#if flags.dynamicWidgets}} diff --git a/src/templates/React InstantSearch/public/index.html b/src/templates/React InstantSearch/public/index.html index d7ae1321e..7070d16c8 100644 --- a/src/templates/React InstantSearch/public/index.html +++ b/src/templates/React InstantSearch/public/index.html @@ -13,7 +13,7 @@ Do not use @7 in production, use a complete version like x.x.x, see website for latest version: https://www.algolia.com/doc/guides/building-search-ui/installation/react/#load-the-style --> - + {{name}} diff --git a/src/templates/React InstantSearch/src/App.js.hbs b/src/templates/React InstantSearch/src/App.js.hbs index bab15fa6f..19e196a09 100644 --- a/src/templates/React InstantSearch/src/App.js.hbs +++ b/src/templates/React InstantSearch/src/App.js.hbs @@ -2,14 +2,16 @@ import React from 'react'; import algoliasearch from 'algoliasearch/lite'; import { InstantSearch, + Configure, Hits, SearchBox, {{#if flags.dynamicWidgets}} - Configure, DynamicWidgets, + Panel, RefinementList, {{else}} {{#if attributesForFaceting}} + Panel, RefinementList, {{/if}} {{/if}} @@ -40,18 +42,22 @@ function App() {
+
{{#if flags.dynamicWidgets}} - {{#each attributesForFaceting}} - + + + {{/each}} {{else}} {{#each attributesForFaceting}} - + + + {{/each}} {{/if}}
diff --git a/src/templates/Vue InstantSearch with Vue 3/index.html b/src/templates/Vue InstantSearch with Vue 3/index.html index 24a0d477d..bd11cfdc8 100644 --- a/src/templates/Vue InstantSearch with Vue 3/index.html +++ b/src/templates/Vue InstantSearch with Vue 3/index.html @@ -9,7 +9,7 @@ Do not use @7 in production, use a complete version like x.x.x, see website for latest version: https://www.algolia.com/doc/guides/building-search-ui/installation/react/#load-the-style --> - + {{name}} diff --git a/src/templates/Vue InstantSearch with Vue 3/src/App.vue b/src/templates/Vue InstantSearch with Vue 3/src/App.vue index f0a1d94e0..3aeca314d 100644 --- a/src/templates/Vue InstantSearch with Vue 3/src/App.vue +++ b/src/templates/Vue InstantSearch with Vue 3/src/App.vue @@ -17,17 +17,24 @@ :search-client="searchClient" index-name="{{indexName}}" > +
{{#if flags.dynamicWidgets}} {{#each attributesForFaceting}} - + + + + {{/each}} {{else}} {{#each attributesForFaceting}} - + + + + {{/each}} {{/if}}
diff --git a/src/templates/Vue InstantSearch/public/index.html b/src/templates/Vue InstantSearch/public/index.html index ec6630c54..7a05d9758 100644 --- a/src/templates/Vue InstantSearch/public/index.html +++ b/src/templates/Vue InstantSearch/public/index.html @@ -9,7 +9,7 @@ Do not use @7 in production, use a complete version like x.x.x, see website for latest version: https://www.algolia.com/doc/guides/building-search-ui/installation/react/#load-the-style --> - + {{name}} diff --git a/src/templates/Vue InstantSearch/src/App.vue b/src/templates/Vue InstantSearch/src/App.vue index 2086dee52..e53808d0c 100644 --- a/src/templates/Vue InstantSearch/src/App.vue +++ b/src/templates/Vue InstantSearch/src/App.vue @@ -15,19 +15,28 @@
- + +
{{#if flags.dynamicWidgets}} - {{#each attributesForFaceting}} - + + + + {{/each}} {{else}} {{#each attributesForFaceting}} - + + + + {{/each}} {{/if}}
@@ -41,7 +50,10 @@ {{else}} - + {{/if}}