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

feat: Implement transformItems API #3042

Merged
merged 26 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8623d6e
feat(infinite-hits): implement `transformItems`
francoischalifour Jul 20, 2018
56da733
feat(hits): implement `transformItems`
francoischalifour Jul 20, 2018
85033ec
feat(breadcrumb): implement `transformItems`
francoischalifour Jul 20, 2018
f5aec2e
feat(hierarchical-menu): implement `transformItems`
francoischalifour Jul 20, 2018
e9b2d4c
feat(menu): implement `transformItems`
francoischalifour Jul 20, 2018
e55dba2
feat(menu-select): implement `transformItems`
francoischalifour Jul 20, 2018
1818edb
feat(refinement-list): implement `transformItems`
francoischalifour Jul 23, 2018
526d308
feat(geo-search): implement `transformItems`
francoischalifour Jul 23, 2018
c898c4a
feat(sort-by): implement `transformItems`
francoischalifour Jul 23, 2018
ee19dd7
feat(hits-per-page): implement `transformItems`
francoischalifour Jul 23, 2018
93e7af4
feat(current-refined-values): implement `transformItems`
francoischalifour Jul 23, 2018
b0f8611
feat(numeric-refinement-list): implement `transformItems`
francoischalifour Jul 23, 2018
63840dc
feat(numeric-selector): implement `transformItems`
francoischalifour Jul 23, 2018
01e3bb4
refactor(hits): use default identity function for `transformItems`
francoischalifour Jul 27, 2018
ca82ede
refactor(infinite-hits): use default identity function for `transform…
francoischalifour Jul 27, 2018
547f028
test(hits-per-page): migrate to Jest
francoischalifour Jul 30, 2018
b23df37
test(menu): migrate to Jest
francoischalifour Jul 30, 2018
7ffc09b
test(numeric-refinement-list): migrate to Jest
francoischalifour Jul 30, 2018
d74fe50
test(sort-by-selector): migrate to Jest
francoischalifour Jul 30, 2018
9dd9064
test(infinite-hits): migrate to Jest
francoischalifour Jul 30, 2018
54b30cf
test(refinement-list): migrate to Jest
francoischalifour Jul 30, 2018
80ad6e5
test(hits): migrate to Jest
francoischalifour Jul 30, 2018
a8e58b3
test(hierarchical-menu): migrate to Jest
francoischalifour Jul 30, 2018
dcaf3ca
test(current-refined-values): migrate to Jest and remove Lodash imports
francoischalifour Jul 30, 2018
4be30e9
Merge branch 'develop' into feat/transform-items
bobylito Jul 30, 2018
7c10a17
test(refinement-list): update snapshots
francoischalifour Jul 30, 2018
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
35 changes: 35 additions & 0 deletions dev/app/builtin/stories/breadcrumb.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,40 @@ export default () => {
})
);
})
)
.add(
'with transformed items',
wrapWithHits(container => {
container.innerHTML = `
<div id="hierarchicalMenu"></div>
<div id="breadcrumb"></div>
`;

window.search.addWidget(
instantsearch.widgets.breadcrumb({
container: '#breadcrumb',
attributes: [
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2',
],
transformItems: items =>
items.map(item => ({
...item,
name: `${item.name} (transformed)`,
})),
})
);

// Custom Widget to toggle refinement
window.search.addWidget({
init({ helper }) {
helper.toggleRefinement(
'hierarchicalCategories.lvl0',
'Cameras & Camcorders > Digital Cameras'
);
},
});
})
);
};
25 changes: 25 additions & 0 deletions dev/app/builtin/stories/current-refined-values.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,30 @@ export default () => {
},
}
)
)
.add(
'with transformed items',
wrapWithHits(
container => {
window.search.addWidget(
instantsearch.widgets.currentRefinedValues({
container,
clearsQuery: true,
transformItems: items =>
items.map(item => ({
...item,
name: `${item.name} (transformed)`,
})),
})
);
},
{
searchParameters: {
disjunctiveFacetsRefinements: { brand: ['Apple', 'Samsung'] },
disjunctiveFacets: ['brand'],
numericRefinements: { price: { '>=': [100] } },
},
}
)
);
};
24 changes: 24 additions & 0 deletions dev/app/builtin/stories/geo-search.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ export default () => {
})
);

start();
})
)
).add(
'with transformed items',
wrapWithHitsAndConfiguration((container, start) =>
injectGoogleMaps(() => {
container.style.height = '600px';

window.search.addWidget(
instantsearch.widgets.geoSearch({
googleReference: window.google,
container,
transformItems: items =>
items.map(item => ({
...item,
_geoloc: {
lat: item._geoloc.lat + 2,
lng: item._geoloc.lng + 2,
},
})),
})
);

start();
})
)
Expand Down
20 changes: 20 additions & 0 deletions dev/app/builtin/stories/hierarchical-menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,25 @@ export default () => {
})
);
})
)
.add(
'with transformed items',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.hierarchicalMenu({
container,
attributes: [
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2',
],
transformItems: items =>
items.map(item => ({
...item,
label: `${item.label} (transformed)`,
})),
})
);
})
);
};
20 changes: 20 additions & 0 deletions dev/app/builtin/stories/hits-per-page-selector.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,25 @@ export default () => {
})
);
})
)
.add(
'with transformed items',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.hitsPerPageSelector({
container,
items: [
{ value: 3, label: '3 per page' },
{ value: 5, label: '5 per page' },
{ value: 10, label: '10 per page' },
],
transformItems: items =>
items.map(item => ({
...item,
label: `${item.label} (transformed)`,
})),
})
);
})
);
};
15 changes: 15 additions & 0 deletions dev/app/builtin/stories/hits.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ export default () => {
window.search.addWidget(instantsearch.widgets.hits({ container }));
})
)
.add(
'with transformed items',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.hits({
container,
transformItems: items =>
items.map(item => ({
...item,
name: `${item.name} (transformed)`,
})),
})
);
})
)
.add(
'with highlighted array',
wrapWithHits(
Expand Down
19 changes: 19 additions & 0 deletions dev/app/builtin/stories/infinite-hits.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,24 @@ export default () => {
})
);
})
)
.add(
'with transformed items',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.infiniteHits({
container,
showMoreLabel: 'Show more',
templates: {
item: '{{name}}',
},
transformItems: items =>
items.map(item => ({
...item,
name: `${item.name} (transformed)`,
})),
})
);
})
);
};
16 changes: 16 additions & 0 deletions dev/app/builtin/stories/menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ export default () => {
);
})
)
.add(
'with transformed items',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.menu({
container,
attributeName: 'categories',
transformItems: items =>
items.map(item => ({
...item,
label: `${item.label} (transformed)`,
})),
})
);
})
)
.add(
'with show more and header',
wrapWithHits(container => {
Expand Down
90 changes: 62 additions & 28 deletions dev/app/builtin/stories/numeric-refinement-list.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,66 @@ import { wrapWithHits } from '../../utils/wrap-with-hits.js';
const stories = storiesOf('NumericRefinementList');

export default () => {
stories.add(
'default',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.numericRefinementList({
container,
attributeName: 'price',
operator: 'or',
options: [
{ name: 'All' },
{ end: 4, name: 'less than 4' },
{ start: 4, end: 4, name: '4' },
{ start: 5, end: 10, name: 'between 5 and 10' },
{ start: 10, name: 'more than 10' },
],
cssClasses: {
header: 'facet-title',
link: 'facet-value',
count: 'facet-count pull-right',
active: 'facet-active',
},
templates: {
header: 'Numeric refinement list (price)',
},
})
);
})
);
stories
.add(
'default',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.numericRefinementList({
container,
attributeName: 'price',
operator: 'or',
options: [
{ name: 'All' },
{ end: 4, name: 'less than 4' },
{ start: 4, end: 4, name: '4' },
{ start: 5, end: 10, name: 'between 5 and 10' },
{ start: 10, name: 'more than 10' },
],
cssClasses: {
header: 'facet-title',
link: 'facet-value',
count: 'facet-count pull-right',
active: 'facet-active',
},
templates: {
header: 'Numeric refinement list (price)',
},
})
);
})
)
.add(
'with transformed hits',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.numericRefinementList({
container,
attributeName: 'price',
operator: 'or',
options: [
{ name: 'All' },
{ end: 4, name: 'less than 4' },
{ start: 4, end: 4, name: '4' },
{ start: 5, end: 10, name: 'between 5 and 10' },
{ start: 10, name: 'more than 10' },
],
cssClasses: {
header: 'facet-title',
link: 'facet-value',
count: 'facet-count pull-right',
active: 'facet-active',
},
templates: {
header: 'Numeric refinement list (price)',
},
transformItems: items =>
items.map(item => ({
...item,
label: `${item.label} (transformed)`,
})),
})
);
})
);
};
25 changes: 25 additions & 0 deletions dev/app/builtin/stories/numeric-selector.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,29 @@ export default () => {
);
})
);
stories.add(
'with transformed items',
wrapWithHits(container => {
window.search.addWidget(
instantsearch.widgets.numericSelector({
container,
operator: '=',
attributeName: 'rating',
options: [
{ label: 'No rating selected', value: undefined },
{ label: 'Rating: 5', value: 5 },
{ label: 'Rating: 4', value: 4 },
{ label: 'Rating: 3', value: 3 },
{ label: 'Rating: 2', value: 2 },
{ label: 'Rating: 1', value: 1 },
],
transformItems: items =>
items.map(item => ({
...item,
label: `${item.label} (transformed)`,
})),
})
);
})
);
};
Loading