Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: algolia/instantsearch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.24.3
Choose a base ref
...
head repository: algolia/instantsearch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.25.0
Choose a head ref
  • 4 commits
  • 37 files changed
  • 3 contributors

Commits on Jul 5, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    dc2fd95 View commit details
  2. feat(facets): apply result from facet ordering (#4784)

    * feat(facets): apply sort from facetOrdering
    
    * feat(facets): apply result from facet ordering
    
    This adds a new option "facetOrdering" (boolean) to refinementList, menu, hierarchicalMenu which will read facet ordering from the results if available, but fall back to sortBy if no facetOrdering is available.
    
    The option facetOrdering defaults to `true` if no sortBy is given, to make it apply out of the box.
    
    references:
    - NLP-110
    - [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
    
    * forward facetOrdering option from widget
    
    * suppress v3 ts errors
    
    * remove option
    
    * test: rename
    Haroenv authored Jul 5, 2021
    Copy the full SHA
    9e9d839 View commit details
  3. Copy the full SHA
    b417fa5 View commit details

Commits on Jul 6, 2021

  1. chore: release v4.25.0 (#4804)

    Co-authored-by: Haroen Viaene <hello@haroen.me>
    instantsearch-bot and Haroenv authored Jul 6, 2021
    Copy the full SHA
    fc215a5 View commit details
Showing with 892 additions and 336 deletions.
  1. +9 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +195 −0 src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.ts
  4. +6 −6 src/connectors/hierarchical-menu/connectHierarchicalMenu.ts
  5. +200 −1 src/connectors/menu/__tests__/connectMenu-test.ts
  6. +6 −1 src/connectors/menu/connectMenu.ts
  7. +136 −0 src/connectors/refinement-list/__tests__/connectRefinementList-test.ts
  8. +8 −1 src/connectors/refinement-list/connectRefinementList.ts
  9. +1 −1 src/lib/version.ts
  10. +13 −13 src/widgets/answers/answers.tsx
  11. +13 −13 src/widgets/breadcrumb/breadcrumb.tsx
  12. +8 −8 src/widgets/clear-refinements/clear-refinements.tsx
  13. +9 −9 src/widgets/current-refinements/current-refinements.tsx
  14. +17 −17 src/widgets/geo-search/geo-search.ts
  15. +4 −2 src/widgets/hierarchical-menu/__tests__/hierarchical-menu-test.ts
  16. +18 −18 src/widgets/hierarchical-menu/hierarchical-menu.tsx
  17. +5 −5 src/widgets/hits-per-page/hits-per-page.tsx
  18. +10 −10 src/widgets/hits/hits.tsx
  19. +16 −16 src/widgets/infinite-hits/infinite-hits.tsx
  20. +10 −10 src/widgets/menu-select/menu-select.tsx
  21. +16 −16 src/widgets/menu/menu.tsx
  22. +13 −13 src/widgets/numeric-menu/numeric-menu.tsx
  23. +20 −20 src/widgets/pagination/pagination.tsx
  24. +16 −16 src/widgets/panel/panel.tsx
  25. +5 −5 src/widgets/powered-by/powered-by.tsx
  26. +6 −6 src/widgets/query-rule-custom-data/query-rule-custom-data.tsx
  27. +15 −15 src/widgets/range-input/range-input.tsx
  28. +4 −4 src/widgets/range-slider/range-slider.tsx
  29. +17 −17 src/widgets/rating-menu/rating-menu.tsx
  30. +36 −36 src/widgets/refinement-list/refinement-list.tsx
  31. +9 −9 src/widgets/relevant-sort/relevant-sort.tsx
  32. +16 −16 src/widgets/search-box/search-box.tsx
  33. +5 −5 src/widgets/sort-by/sort-by.tsx
  34. +7 −7 src/widgets/stats/stats.tsx
  35. +9 −9 src/widgets/toggle-refinement/toggle-refinement.tsx
  36. +9 −9 src/widgets/voice-search/voice-search.tsx
  37. +4 −1 tsconfig.v3.json
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [4.25.0](https://github.com/algolia/instantsearch.js/compare/v4.24.3...v4.25.0) (2021-07-06)


### Features

* **facets:** apply result from facet ordering ([#4784](https://github.com/algolia/instantsearch.js/issues/4784)) ([9e9d839](https://github.com/algolia/instantsearch.js/commit/9e9d8394067bec35425b7d66f94fcce504faee7f))



## [4.24.3](https://github.com/algolia/instantsearch.js/compare/v4.24.2...v4.24.3) (2021-07-05)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instantsearch.js",
"version": "4.24.3",
"version": "4.25.0",
"description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
"homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
"types": "es/index.d.ts",
Original file line number Diff line number Diff line change
@@ -691,6 +691,201 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
canToggleShowMore: false,
});
});

describe('facetOrdering', () => {
const resultsViaFacetOrdering = [
{
count: 47,
data: null,
exhaustive: true,
isRefined: false,
label: 'Outdoor',
value: 'Outdoor',
},
{
count: 880,
data: [
{
count: 173,
data: null,
exhaustive: true,
isRefined: false,
label: 'Frames & pictures',
value: 'Decoration > Frames & pictures',
},
{
count: 193,
data: null,
exhaustive: true,
isRefined: false,
label: 'Candle holders & candles',
value: 'Decoration > Candle holders & candles',
},
],
exhaustive: true,
isRefined: true,
label: 'Decoration',
value: 'Decoration',
},
];
const resultsViaDefaultSortBy = [
{
count: 880,
data: [
{
count: 193,
data: null,
exhaustive: true,
isRefined: false,
label: 'Candle holders & candles',
value: 'Decoration > Candle holders & candles',
},
{
count: 173,
data: null,
exhaustive: true,
isRefined: false,
label: 'Frames & pictures',
value: 'Decoration > Frames & pictures',
},
],
exhaustive: true,
isRefined: true,
label: 'Decoration',
value: 'Decoration',
},
{
count: 47,
data: null,
exhaustive: true,
isRefined: false,
label: 'Outdoor',
value: 'Outdoor',
},
];
const resultsViaSortBy = [
{
count: 47,
data: null,
exhaustive: true,
isRefined: false,
label: 'Outdoor',
value: 'Outdoor',
},
{
count: 880,
data: [
{
count: 173,
data: null,
exhaustive: true,
isRefined: false,
label: 'Frames & pictures',
value: 'Decoration > Frames & pictures',
},
{
count: 193,
data: null,
exhaustive: true,
isRefined: false,
label: 'Candle holders & candles',
value: 'Decoration > Candle holders & candles',
},
],
exhaustive: true,
isRefined: true,
label: 'Decoration',
value: 'Decoration',
},
];

test.each`
facetOrderingInResult | sortBy | expected
${true} | ${undefined} | ${resultsViaFacetOrdering}
${false} | ${undefined} | ${resultsViaDefaultSortBy}
${true} | ${['name:desc']} | ${resultsViaSortBy}
${false} | ${['name:desc']} | ${resultsViaSortBy}
`(
'renderingContent present: $facetOrderingInResult, sortBy: $sortBy',
({ facetOrderingInResult, sortBy, expected }) => {
const renderFn = jest.fn();
const unmountFn = jest.fn();
const createHierarchicalMenu = connectHierarchicalMenu(
renderFn,
unmountFn
);
const hierarchicalMenu = createHierarchicalMenu({
attributes: ['category', 'subCategory'],
sortBy,
});
const helper = algoliasearchHelper(
createSearchClient(),
'indexName',
hierarchicalMenu.getWidgetSearchParameters!(
new SearchParameters(),
{
uiState: {
hierarchicalMenu: {
category: ['Decoration'],
},
},
}
)
);

hierarchicalMenu.init!(createInitOptions({ helper }));

const renderingContent = facetOrderingInResult
? {
facetOrdering: {
values: {
category: {
order: ['Outdoor'],
sortRemainingBy: 'alpha' as const,
},
subCategory: {
order: ['Decoration > Frames & pictures'],
sortRemainingBy: 'count' as const,
},
},
},
}
: undefined;

const results = new SearchResults(helper.state, [
createSingleSearchResponse({
renderingContent,
facets: {
category: {
Decoration: 880,
},
subCategory: {
'Decoration > Candle holders & candles': 193,
'Decoration > Frames & pictures': 173,
},
},
}),
createSingleSearchResponse({
facets: {
category: {
Decoration: 880,
Outdoor: 47,
},
},
}),
]);

const renderState = hierarchicalMenu.getWidgetRenderState(
createRenderOptions({
helper,
results,
})
);

expect(renderState.items).toEqual(expected);
}
);
});
});

describe('getWidgetUiState', () => {
12 changes: 6 additions & 6 deletions src/connectors/hierarchical-menu/connectHierarchicalMenu.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ const withUsage = createDocumentationMessageGenerator({
connector: true,
});

const DEFAULT_SORT = ['name:asc'];

export type HierarchicalMenuItem = {
/**
* Value of the menu item.
@@ -79,6 +81,8 @@ export type HierarchicalMenuConnectorParams = {
/**
* How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
*
* If a facetOrdering is set in the index settings, it is used when sortBy isn't passed
*/
sortBy?: SortBy<HierarchicalMenuItem>;
/**
@@ -174,7 +178,7 @@ const connectHierarchicalMenu: HierarchicalMenuConnector = function connectHiera
limit = 10,
showMore = false,
showMoreLimit = 20,
sortBy = ['name:asc'],
sortBy = DEFAULT_SORT,
transformItems = (items => items) as TransformItems<HierarchicalMenuItem>,
} = widgetParams || {};

@@ -273,11 +277,6 @@ const connectHierarchicalMenu: HierarchicalMenuConnector = function connectHiera
);
},

/**
* @param {Object} param0 cleanup arguments
* @param {any} param0.state current search parameters
* @returns {any} next search parameters
*/
dispose({ state }) {
unmountFn();

@@ -336,6 +335,7 @@ const connectHierarchicalMenu: HierarchicalMenuConnector = function connectHiera
if (results) {
const facetValues = results.getFacetValues(hierarchicalFacetName, {
sortBy,
facetOrdering: sortBy === DEFAULT_SORT,
});
const facetItems =
facetValues && !Array.isArray(facetValues) && facetValues.data
Loading