diff --git a/.storybook/MemoryRouter.ts b/.storybook/MemoryRouter.ts
deleted file mode 100644
index f7b059b619..0000000000
--- a/.storybook/MemoryRouter.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { action } from '@storybook/addon-actions';
-
-const urlLogger = action('Routing state');
-
-interface MemoryState {
- [key: string]: string | number;
-}
-
-export class MemoryRouter {
- private _memoryState: MemoryState;
- constructor(initialState: MemoryState = {}) {
- this._memoryState = initialState;
- }
- write(routeState: MemoryState) {
- this._memoryState = routeState;
- urlLogger(JSON.stringify(routeState, null, 2));
- }
- read() {
- return this._memoryState;
- }
- createURL() {
- return '';
- }
- onUpdate() {
- return {};
- }
-}
diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html
index b55fcbf640..a957de0631 100644
--- a/.storybook/preview-head.html
+++ b/.storybook/preview-head.html
@@ -1,2 +1,2 @@
-
+
diff --git a/src/components/InfiniteHits/InfiniteHits.js b/src/components/InfiniteHits/InfiniteHits.js
index 281ec43dd6..4de989b62e 100644
--- a/src/components/InfiniteHits/InfiniteHits.js
+++ b/src/components/InfiniteHits/InfiniteHits.js
@@ -6,10 +6,7 @@ import Template from '../Template/Template';
const InfiniteHits = ({
results,
hits,
- hasShowPrevious,
- showPrevious,
showMore,
- isFirstPage,
isLastPage,
cssClasses,
templateProps,
@@ -29,21 +26,6 @@ const InfiniteHits = ({
return (
- {hasShowPrevious && (
-
- )}
-
{hits.map((hit, position) => (
{
emptyRoot: 'emptyRoot',
item: 'item',
list: 'list',
- loadPrevious: 'loadPrevious',
- disabledLoadPrevious: 'disabledLoadPrevious',
loadMore: 'loadMore',
disabledLoadMore: 'disabledLoadMore',
};
@@ -28,12 +26,8 @@ describe('InfiniteHits', () => {
];
const props = {
- hasShowPrevious: false,
- showPrevious: () => {},
- showMore: () => {},
results: { hits },
hits,
- isFirstPage: true,
isLastPage: false,
templateProps: {
templates: {
@@ -62,12 +56,8 @@ describe('InfiniteHits', () => {
];
const props = {
- hasShowPrevious: false,
- showPrevious: () => {},
- showMore: () => {},
results: { hits },
hits,
- isFirstPage: false,
isLastPage: true,
templateProps: {
templates: {
@@ -87,12 +77,8 @@ describe('InfiniteHits', () => {
const hits = [];
const props = {
- hasShowPrevious: false,
- showPrevious: () => {},
- showMore: () => {},
results: { hits },
hits,
- isFirstPage: true,
isLastPage: false,
templateProps: {
templates: {
@@ -112,12 +98,8 @@ describe('InfiniteHits', () => {
const hits = [];
const props = {
- hasShowPrevious: false,
- showPrevious: () => {},
- showMore: () => {},
results: { hits },
hits,
- isFirstPage: false,
isLastPage: true,
templateProps: {
templates: {
@@ -132,85 +114,5 @@ describe('InfiniteHits', () => {
expect(tree).toMatchSnapshot();
});
-
- it('should render with "Show previous" button on first page', () => {
- const hits = [
- {
- objectID: 'one',
- foo: 'bar',
- },
- {
- objectID: 'two',
- foo: 'baz',
- },
- ];
-
- const props = {
- hasShowPrevious: true,
- showPrevious: () => {},
- showMore: () => {},
- results: { hits },
- hits,
- isFirstPage: true,
- isLastPage: false,
- templateProps: {
- templates: {
- item: 'item',
- showMoreText: 'showMoreText',
- showPreviousText: 'showPreviousText',
- },
- },
- cssClasses,
- };
-
- const tree = mount();
-
- const previousButton = tree.find('.loadPrevious');
-
- expect(previousButton.exists()).toEqual(true);
- expect(previousButton.hasClass('disabledLoadPrevious')).toEqual(true);
- expect(previousButton.props().disabled).toEqual(true);
- expect(tree).toMatchSnapshot();
- });
-
- it('should render with "Show previous" button on last page', () => {
- const hits = [
- {
- objectID: 'one',
- foo: 'bar',
- },
- {
- objectID: 'two',
- foo: 'baz',
- },
- ];
-
- const props = {
- hasShowPrevious: true,
- showPrevious: () => {},
- showMore: () => {},
- results: { hits },
- hits,
- isFirstPage: false,
- isLastPage: true,
- templateProps: {
- templates: {
- item: 'item',
- showMoreText: 'showMoreText',
- showPreviousText: 'showPreviousText',
- },
- },
- cssClasses,
- };
-
- const tree = mount();
-
- const previousButton = tree.find('.loadPrevious');
-
- expect(previousButton.exists()).toEqual(true);
- expect(previousButton.hasClass('disabledLoadPrevious')).toEqual(false);
- expect(previousButton.props().disabled).toEqual(false);
- expect(tree).toMatchSnapshot();
- });
});
});
diff --git a/src/components/InfiniteHits/__tests__/__snapshots__/InfiniteHits-test.js.snap b/src/components/InfiniteHits/__tests__/__snapshots__/InfiniteHits-test.js.snap
index b62c5c4a2e..f9839812e0 100644
--- a/src/components/InfiniteHits/__tests__/__snapshots__/InfiniteHits-test.js.snap
+++ b/src/components/InfiniteHits/__tests__/__snapshots__/InfiniteHits-test.js.snap
@@ -32,7 +32,6 @@ exports[`InfiniteHits markup should render on first page 1`] =
}
}
disabled={false}
- onClick={[Function]}
/>
`;
@@ -69,101 +68,6 @@ exports[`InfiniteHits markup should render on last page 1`] = `
}
}
disabled={true}
- onClick={[Function]}
- />
-
-`;
-
-exports[`InfiniteHits markup should render with "Show previous" button on first page 1`] = `
-
-`;
-
-exports[`InfiniteHits markup should render with "Show previous" button on last page 1`] = `
-
`;
diff --git a/src/connectors/infinite-hits/__tests__/__snapshots__/connectInfiniteHits-test.js.snap b/src/connectors/infinite-hits/__tests__/__snapshots__/connectInfiniteHits-test.js.snap
deleted file mode 100644
index 4533985c54..0000000000
--- a/src/connectors/infinite-hits/__tests__/__snapshots__/connectInfiniteHits-test.js.snap
+++ /dev/null
@@ -1,121 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`connectInfiniteHits routing getWidgetSearchParameters should add the refinements according to the UI state provided 1`] = `
-SearchParameters {
- "advancedSyntax": undefined,
- "allowTyposOnNumericTokens": undefined,
- "analytics": undefined,
- "analyticsTags": undefined,
- "aroundLatLng": undefined,
- "aroundLatLngViaIP": undefined,
- "aroundPrecision": undefined,
- "aroundRadius": undefined,
- "attributesToHighlight": undefined,
- "attributesToRetrieve": undefined,
- "attributesToSnippet": undefined,
- "disableExactOnAttributes": undefined,
- "disjunctiveFacets": Array [],
- "disjunctiveFacetsRefinements": Object {},
- "distinct": undefined,
- "enableExactOnSingleWordQuery": undefined,
- "facets": Array [],
- "facetsExcludes": Object {},
- "facetsRefinements": Object {},
- "getRankingInfo": undefined,
- "hierarchicalFacets": Array [],
- "hierarchicalFacetsRefinements": Object {},
- "highlightPostTag": undefined,
- "highlightPreTag": undefined,
- "hitsPerPage": undefined,
- "ignorePlurals": undefined,
- "index": "",
- "insideBoundingBox": undefined,
- "insidePolygon": undefined,
- "length": undefined,
- "maxValuesPerFacet": undefined,
- "minProximity": undefined,
- "minWordSizefor1Typo": undefined,
- "minWordSizefor2Typos": undefined,
- "minimumAroundRadius": undefined,
- "numericFilters": undefined,
- "numericRefinements": Object {},
- "offset": undefined,
- "optionalFacetFilters": undefined,
- "optionalTagFilters": undefined,
- "optionalWords": undefined,
- "page": 1,
- "query": "",
- "queryType": undefined,
- "removeWordsIfNoResults": undefined,
- "replaceSynonymsInHighlight": undefined,
- "restrictSearchableAttributes": undefined,
- "snippetEllipsisText": undefined,
- "synonyms": undefined,
- "tagFilters": undefined,
- "tagRefinements": Array [],
- "typoTolerance": undefined,
-}
-`;
-
-exports[`connectInfiniteHits routing getWidgetSearchParameters should enforce the default value if no value is in the UI State 1`] = `
-SearchParameters {
- "advancedSyntax": undefined,
- "allowTyposOnNumericTokens": undefined,
- "analytics": undefined,
- "analyticsTags": undefined,
- "aroundLatLng": undefined,
- "aroundLatLngViaIP": undefined,
- "aroundPrecision": undefined,
- "aroundRadius": undefined,
- "attributesToHighlight": undefined,
- "attributesToRetrieve": undefined,
- "attributesToSnippet": undefined,
- "disableExactOnAttributes": undefined,
- "disjunctiveFacets": Array [],
- "disjunctiveFacetsRefinements": Object {},
- "distinct": undefined,
- "enableExactOnSingleWordQuery": undefined,
- "facets": Array [],
- "facetsExcludes": Object {},
- "facetsRefinements": Object {},
- "getRankingInfo": undefined,
- "hierarchicalFacets": Array [],
- "hierarchicalFacetsRefinements": Object {},
- "highlightPostTag": undefined,
- "highlightPreTag": undefined,
- "hitsPerPage": undefined,
- "ignorePlurals": undefined,
- "index": "",
- "insideBoundingBox": undefined,
- "insidePolygon": undefined,
- "length": undefined,
- "maxValuesPerFacet": undefined,
- "minProximity": undefined,
- "minWordSizefor1Typo": undefined,
- "minWordSizefor2Typos": undefined,
- "minimumAroundRadius": undefined,
- "numericFilters": undefined,
- "numericRefinements": Object {},
- "offset": undefined,
- "optionalFacetFilters": undefined,
- "optionalTagFilters": undefined,
- "optionalWords": undefined,
- "page": 0,
- "query": "",
- "queryType": undefined,
- "removeWordsIfNoResults": undefined,
- "replaceSynonymsInHighlight": undefined,
- "restrictSearchableAttributes": undefined,
- "snippetEllipsisText": undefined,
- "synonyms": undefined,
- "tagFilters": undefined,
- "tagRefinements": Array [],
- "typoTolerance": undefined,
-}
-`;
-
-exports[`connectInfiniteHits routing getWidgetState should add an entry equal to the refinement 1`] = `
-Object {
- "page": 2,
-}
-`;
diff --git a/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js b/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js
index eb37fe1e93..f9f8dd0663 100644
--- a/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js
+++ b/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.js
@@ -1,7 +1,4 @@
-import jsHelper, {
- SearchResults,
- SearchParameters,
-} from 'algoliasearch-helper';
+import jsHelper, { SearchResults } from 'algoliasearch-helper';
import { TAG_PLACEHOLDER } from '../../../lib/escape-highlight';
import connectInfiniteHits from '../connectInfiniteHits';
@@ -50,10 +47,8 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: [],
- showPrevious: expect.any(Function),
showMore: expect.any(Function),
results: undefined,
- isFirstPage: true,
isLastPage: true,
instantSearchInstance: undefined,
widgetParams: {
@@ -78,10 +73,8 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
hits: [],
- showPrevious: expect.any(Function),
showMore: expect.any(Function),
results: expect.any(Object),
- isFirstPage: true,
isLastPage: false,
instantSearchInstance: undefined,
widgetParams: {
@@ -103,7 +96,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
});
});
- it('Provides the hits and accumulates results on next page', () => {
+ it('Provides the hits and the whole results', () => {
const rendering = jest.fn();
const makeWidget = connectInfiniteHits(rendering);
const widget = makeWidget();
@@ -155,68 +148,27 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
const thirdRenderingOptions = rendering.mock.calls[2][0];
expect(thirdRenderingOptions.hits).toEqual([...hits, ...otherHits]);
expect(thirdRenderingOptions.results).toEqual(otherResults);
- });
- it('Provides the hits and prepends results on previous page', () => {
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget();
+ helper.setPage(0);
- const helper = jsHelper({}, '', {});
- helper.setPage(1);
- helper.search = jest.fn();
- helper.emit = jest.fn();
+ // If the page goes back to 0, the hits cache should be flushed
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const firstRenderingOptions = rendering.mock.calls[0][0];
- expect(firstRenderingOptions.hits).toEqual([]);
- expect(firstRenderingOptions.results).toBe(undefined);
-
- const hits = [{ fake: 'data' }, { sample: 'infos' }];
- const results = new SearchResults(helper.state, [
+ const thirdHits = [{ fake: 'data 3' }, { sample: 'infos 3' }];
+ const thirdResults = new SearchResults(helper.state, [
{
- hits,
+ hits: thirdHits,
},
]);
widget.render({
- results,
+ results: thirdResults,
state: helper.state,
helper,
createURL: () => '#',
});
- const secondRenderingOptions = rendering.mock.calls[1][0];
- const { showPrevious } = secondRenderingOptions;
- expect(secondRenderingOptions.hits).toEqual(hits);
- expect(secondRenderingOptions.results).toEqual(results);
- showPrevious();
- expect(helper.getPage()).toBe(0);
- expect(helper.emit).not.toHaveBeenCalled();
- expect(helper.search).toHaveBeenCalledTimes(1);
-
- // the results should be prepended if there is an decrement in page
- const previousHits = [{ fake: 'data 2' }, { sample: 'infos 2' }];
- const previousResults = new SearchResults(helper.state, [
- {
- hits: previousHits,
- },
- ]);
- widget.render({
- results: previousResults,
- state: helper.state,
- helper,
- createURL: () => '#',
- });
-
- const thirdRenderingOptions = rendering.mock.calls[2][0];
- expect(thirdRenderingOptions.hits).toEqual([...previousHits, ...hits]);
- expect(thirdRenderingOptions.results).toEqual(previousResults);
+ const fourthRenderingOptions = rendering.mock.calls[3][0];
+ expect(fourthRenderingOptions.hits).toEqual(thirdHits);
+ expect(fourthRenderingOptions.results).toEqual(thirdResults);
});
it('escape highlight properties if requested', () => {
@@ -480,220 +432,4 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
false
);
});
-
- describe('routing', () => {
- describe('getWidgetState', () => {
- it('should give back the object unmodified if the default value is selected', () => {
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: true });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const uiStateBefore = { page: 1 };
- const uiStateAfter = widget.getWidgetState(uiStateBefore, {
- searchParameters: helper.state,
- helper,
- });
-
- expect(uiStateAfter).toBe(uiStateBefore);
- });
-
- it('should add an entry equal to the refinement', () => {
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: true });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const { showMore } = rendering.mock.calls[0][0];
-
- showMore();
-
- const uiStateBefore = { page: 1 };
- const uiStateAfter = widget.getWidgetState(uiStateBefore, {
- searchParameters: helper.state,
- helper,
- });
-
- expect(uiStateAfter).toMatchSnapshot();
- });
-
- it('should give back the object unmodified if showPrevious is disabled', () => {
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: false });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const { showMore } = rendering.mock.calls[0][0];
-
- showMore();
-
- const uiStateBefore = { page: 1 };
- const uiStateAfter = widget.getWidgetState(uiStateBefore, {
- searchParameters: helper.state,
- helper,
- });
-
- expect(uiStateAfter).toBe(uiStateBefore);
- });
- });
-
- describe('getWidgetSearchParameters', () => {
- it('should return the same SP if there are no refinements in the UI state', () => {
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: true });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- // The user presses back (browser), and the URL contains no parameters
- const uiState = {};
- // The current state is empty (and page is set to 0 by default)
- const searchParametersBefore = SearchParameters.make(helper.state);
- const searchParametersAfter = widget.getWidgetSearchParameters(
- searchParametersBefore,
- { uiState }
- );
- // Applying the same values should not return a new object
- expect(searchParametersAfter).toBe(searchParametersBefore);
- });
-
- it('should enforce the default value if no value is in the UI State', () => {
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: true });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const { showMore } = rendering.mock.calls[0][0];
-
- // The user presses back (browser), and the URL contains no parameters
- const uiState = {};
- // The current state is set to next page
- showMore();
- const searchParametersBefore = SearchParameters.make(helper.state);
- const searchParametersAfter = widget.getWidgetSearchParameters(
- searchParametersBefore,
- {
- uiState,
- }
- );
- // Applying an empty state, should force back to page 0
- expect(searchParametersAfter).toMatchSnapshot();
- expect(searchParametersAfter.page).toBe(0);
- });
-
- it('should add the refinements according to the UI state provided', () => {
- global.window = { location: { pathname: null } };
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: true });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const { showMore } = rendering.mock.calls[0][0];
-
- // The user presses back (browser), and the URL contains some parameters
- const uiState = {
- page: 2,
- };
- // The current state is set to next page
- showMore();
- const searchParametersBefore = SearchParameters.make(helper.state);
- const searchParametersAfter = widget.getWidgetSearchParameters(
- searchParametersBefore,
- {
- uiState,
- }
- );
- // Applying a state with new parameters should apply them on the search
- expect(searchParametersAfter).toMatchSnapshot();
- expect(searchParametersAfter.page).toBe(1);
- });
- });
-
- it('should return the same SP if showPrevious is disabled', () => {
- global.window = { location: { pathname: null } };
- const rendering = jest.fn();
- const makeWidget = connectInfiniteHits(rendering);
- const widget = makeWidget({ showPrevious: false });
-
- const helper = jsHelper({}, '', {});
- helper.search = jest.fn();
-
- widget.init({
- helper,
- state: helper.state,
- createURL: () => '#',
- onHistoryChange: () => {},
- });
-
- const { showMore } = rendering.mock.calls[0][0];
-
- // The user presses back (browser), and the URL contains some parameters
- const uiState = {
- page: 4,
- };
- // The current state is set to next page
- showMore();
- const searchParametersBefore = SearchParameters.make(helper.state);
- const searchParametersAfter = widget.getWidgetSearchParameters(
- searchParametersBefore,
- {
- uiState,
- }
- );
- expect(searchParametersAfter).toBe(searchParametersBefore);
- });
- });
});
diff --git a/src/connectors/infinite-hits/connectInfiniteHits.js b/src/connectors/infinite-hits/connectInfiniteHits.js
index ebb1801d73..414cc5083e 100644
--- a/src/connectors/infinite-hits/connectInfiniteHits.js
+++ b/src/connectors/infinite-hits/connectInfiniteHits.js
@@ -68,28 +68,11 @@ export default function connectInfiniteHits(renderFn, unmountFn) {
checkRendering(renderFn, withUsage());
return (widgetParams = {}) => {
- const {
- escapeHTML = true,
- transformItems = items => items,
- showPrevious = false,
- } = widgetParams;
+ const { escapeHTML = true, transformItems = items => items } = widgetParams;
let hitsCache = [];
- let firstReceivedPage = Infinity;
let lastReceivedPage = -1;
- const getShowPrevious = helper => () => {
- // Using the helper's `overrideStateWithoutTriggeringChangeEvent` method
- // avoid updating the browser URL when the user displays the previous page.
- helper
- .overrideStateWithoutTriggeringChangeEvent({
- ...helper.state,
- page: firstReceivedPage - 1,
- })
- .search();
- };
- const getShowMore = helper => () => {
- helper.setPage(lastReceivedPage + 1).search();
- };
+ const getShowMore = helper => () => helper.nextPage().search();
return {
getConfiguration() {
@@ -97,18 +80,13 @@ export default function connectInfiniteHits(renderFn, unmountFn) {
},
init({ instantSearchInstance, helper }) {
- this.showPrevious = getShowPrevious(helper);
this.showMore = getShowMore(helper);
- firstReceivedPage = helper.state.page;
- lastReceivedPage = helper.state.page;
renderFn(
{
hits: hitsCache,
results: undefined,
- showPrevious: this.showPrevious,
showMore: this.showMore,
- isFirstPage: firstReceivedPage === 0,
isLastPage: true,
instantSearchInstance,
widgetParams,
@@ -118,30 +96,29 @@ export default function connectInfiniteHits(renderFn, unmountFn) {
},
render({ results, state, instantSearchInstance }) {
+ if (state.page === 0) {
+ hitsCache = [];
+ lastReceivedPage = -1;
+ }
+
if (escapeHTML && results.hits && results.hits.length > 0) {
results.hits = escapeHits(results.hits);
}
results.hits = transformItems(results.hits);
- if (lastReceivedPage < state.page || !hitsCache.length) {
+ if (lastReceivedPage < state.page) {
hitsCache = [...hitsCache, ...results.hits];
lastReceivedPage = state.page;
- } else if (firstReceivedPage > state.page) {
- hitsCache = [...results.hits, ...hitsCache];
- firstReceivedPage = state.page;
}
- const isFirstPage = firstReceivedPage === 0;
const isLastPage = results.nbPages <= results.page + 1;
renderFn(
{
hits: hitsCache,
results,
- showPrevious: this.showPrevious,
showMore: this.showMore,
- isFirstPage,
isLastPage,
instantSearchInstance,
widgetParams,
@@ -153,30 +130,6 @@ export default function connectInfiniteHits(renderFn, unmountFn) {
dispose() {
unmountFn();
},
-
- getWidgetState(uiState, { searchParameters }) {
- const page = searchParameters.page;
-
- if (!showPrevious || page === 0 || page + 1 === uiState.page) {
- return uiState;
- }
-
- return {
- ...uiState,
- page: page + 1,
- };
- },
-
- getWidgetSearchParameters(searchParameters, { uiState }) {
- if (!showPrevious) {
- return searchParameters;
- }
- const uiPage = uiState.page;
- if (uiPage) {
- return searchParameters.setQueryParameter('page', uiPage - 1);
- }
- return searchParameters.setQueryParameter('page', 0);
- },
};
};
}
diff --git a/src/widgets/infinite-hits/__tests__/__snapshots__/infinite-hits-test.js.snap b/src/widgets/infinite-hits/__tests__/__snapshots__/infinite-hits-test.js.snap
index 6847dab297..39bc1d7a7e 100644
--- a/src/widgets/infinite-hits/__tests__/__snapshots__/infinite-hits-test.js.snap
+++ b/src/widgets/infinite-hits/__tests__/__snapshots__/infinite-hits-test.js.snap
@@ -5,16 +5,13 @@ exports[`infiniteHits() calls twice render(, container) 1`] = `
cssClasses={
Object {
"disabledLoadMore": "ais-InfiniteHits-loadMore--disabled",
- "disabledLoadPrevious": "ais-InfiniteHits-loadPrevious--disabled",
"emptyRoot": "ais-InfiniteHits--empty",
"item": "ais-InfiniteHits-item",
"list": "ais-InfiniteHits-list",
"loadMore": "ais-InfiniteHits-loadMore",
- "loadPrevious": "ais-InfiniteHits-loadPrevious",
"root": "ais-InfiniteHits root cx",
}
}
- hasShowPrevious={false}
hits={
Array [
Object {
@@ -23,7 +20,6 @@ exports[`infiniteHits() calls twice render(, container) 1`] = `
},
]
}
- isFirstPage={true}
isLastPage={false}
results={
Object {
@@ -36,21 +32,18 @@ exports[`infiniteHits() calls twice render(, container) 1`] = `
}
}
showMore={[Function]}
- showPrevious={[Function]}
templateProps={
Object {
"templates": Object {
"empty": "No results",
"item": [Function],
"showMoreText": "Show more results",
- "showPreviousText": "Show previous results",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"empty": false,
"item": false,
"showMoreText": false,
- "showPreviousText": false,
},
}
}
@@ -62,16 +55,13 @@ exports[`infiniteHits() calls twice render(, container) 2`] = `
cssClasses={
Object {
"disabledLoadMore": "ais-InfiniteHits-loadMore--disabled",
- "disabledLoadPrevious": "ais-InfiniteHits-loadPrevious--disabled",
"emptyRoot": "ais-InfiniteHits--empty",
"item": "ais-InfiniteHits-item",
"list": "ais-InfiniteHits-list",
"loadMore": "ais-InfiniteHits-loadMore",
- "loadPrevious": "ais-InfiniteHits-loadPrevious",
"root": "ais-InfiniteHits root cx",
}
}
- hasShowPrevious={false}
hits={
Array [
Object {
@@ -80,7 +70,6 @@ exports[`infiniteHits() calls twice render(, container) 2`] = `
},
]
}
- isFirstPage={true}
isLastPage={false}
results={
Object {
@@ -93,21 +82,18 @@ exports[`infiniteHits() calls twice render(, container) 2`] = `
}
}
showMore={[Function]}
- showPrevious={[Function]}
templateProps={
Object {
"templates": Object {
"empty": "No results",
"item": [Function],
"showMoreText": "Show more results",
- "showPreviousText": "Show previous results",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"empty": false,
"item": false,
"showMoreText": false,
- "showPreviousText": false,
},
}
}
@@ -119,16 +105,13 @@ exports[`infiniteHits() if it is the last page, then the props should contain is
cssClasses={
Object {
"disabledLoadMore": "ais-InfiniteHits-loadMore--disabled",
- "disabledLoadPrevious": "ais-InfiniteHits-loadPrevious--disabled",
"emptyRoot": "ais-InfiniteHits--empty",
"item": "ais-InfiniteHits-item",
"list": "ais-InfiniteHits-list",
"loadMore": "ais-InfiniteHits-loadMore",
- "loadPrevious": "ais-InfiniteHits-loadPrevious",
"root": "ais-InfiniteHits root cx",
}
}
- hasShowPrevious={false}
hits={
Array [
Object {
@@ -137,7 +120,6 @@ exports[`infiniteHits() if it is the last page, then the props should contain is
},
]
}
- isFirstPage={true}
isLastPage={false}
results={
Object {
@@ -152,21 +134,18 @@ exports[`infiniteHits() if it is the last page, then the props should contain is
}
}
showMore={[Function]}
- showPrevious={[Function]}
templateProps={
Object {
"templates": Object {
"empty": "No results",
"item": [Function],
"showMoreText": "Show more results",
- "showPreviousText": "Show previous results",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"empty": false,
"item": false,
"showMoreText": false,
- "showPreviousText": false,
},
}
}
@@ -178,16 +157,13 @@ exports[`infiniteHits() if it is the last page, then the props should contain is
cssClasses={
Object {
"disabledLoadMore": "ais-InfiniteHits-loadMore--disabled",
- "disabledLoadPrevious": "ais-InfiniteHits-loadPrevious--disabled",
"emptyRoot": "ais-InfiniteHits--empty",
"item": "ais-InfiniteHits-item",
"list": "ais-InfiniteHits-list",
"loadMore": "ais-InfiniteHits-loadMore",
- "loadPrevious": "ais-InfiniteHits-loadPrevious",
"root": "ais-InfiniteHits root cx",
}
}
- hasShowPrevious={false}
hits={
Array [
Object {
@@ -196,7 +172,6 @@ exports[`infiniteHits() if it is the last page, then the props should contain is
},
]
}
- isFirstPage={true}
isLastPage={true}
results={
Object {
@@ -211,21 +186,18 @@ exports[`infiniteHits() if it is the last page, then the props should contain is
}
}
showMore={[Function]}
- showPrevious={[Function]}
templateProps={
Object {
"templates": Object {
"empty": "No results",
"item": [Function],
"showMoreText": "Show more results",
- "showPreviousText": "Show previous results",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"empty": false,
"item": false,
"showMoreText": false,
- "showPreviousText": false,
},
}
}
@@ -237,16 +209,13 @@ exports[`infiniteHits() renders transformed items 1`] = `
cssClasses={
Object {
"disabledLoadMore": "ais-InfiniteHits-loadMore--disabled",
- "disabledLoadPrevious": "ais-InfiniteHits-loadPrevious--disabled",
"emptyRoot": "ais-InfiniteHits--empty",
"item": "ais-InfiniteHits-item",
"list": "ais-InfiniteHits-list",
"loadMore": "ais-InfiniteHits-loadMore",
- "loadPrevious": "ais-InfiniteHits-loadPrevious",
"root": "ais-InfiniteHits",
}
}
- hasShowPrevious={false}
hits={
Array [
Object {
@@ -256,7 +225,6 @@ exports[`infiniteHits() renders transformed items 1`] = `
},
]
}
- isFirstPage={true}
isLastPage={false}
results={
Object {
@@ -270,21 +238,18 @@ exports[`infiniteHits() renders transformed items 1`] = `
}
}
showMore={[Function]}
- showPrevious={[Function]}
templateProps={
Object {
"templates": Object {
"empty": "No results",
"item": [Function],
"showMoreText": "Show more results",
- "showPreviousText": "Show previous results",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"empty": false,
"item": false,
"showMoreText": false,
- "showPreviousText": false,
},
}
}
diff --git a/src/widgets/infinite-hits/__tests__/defaultTemplates-test.js b/src/widgets/infinite-hits/__tests__/defaultTemplates-test.js
index 7db192eeb7..5d0916bf11 100644
--- a/src/widgets/infinite-hits/__tests__/defaultTemplates-test.js
+++ b/src/widgets/infinite-hits/__tests__/defaultTemplates-test.js
@@ -22,10 +22,4 @@ describe('hits defaultTemplates', () => {
expect(defaultTemplates.item(item)).toBe(expected);
});
-
- it('has a `showPreviousText` default template', () => {
- expect(defaultTemplates.showPreviousText).toMatchInlineSnapshot(
- `"Show previous results"`
- );
- });
});
diff --git a/src/widgets/infinite-hits/__tests__/infinite-hits-test.js b/src/widgets/infinite-hits/__tests__/infinite-hits-test.js
index 2292780301..bd52819aec 100644
--- a/src/widgets/infinite-hits/__tests__/infinite-hits-test.js
+++ b/src/widgets/infinite-hits/__tests__/infinite-hits-test.js
@@ -40,7 +40,6 @@ describe('infiniteHits()', () => {
container,
escapeHTML: true,
cssClasses: { root: ['root', 'cx'] },
- showPrevious: false,
});
widget.init({ helper, instantSearchInstance: {} });
results = { hits: [{ first: 'hit', second: 'hit' }] };
@@ -72,7 +71,6 @@ describe('infiniteHits()', () => {
container,
transformItems: items =>
items.map(item => ({ ...item, transformed: true })),
- showPrevious: false,
});
widget.init({ helper, instantSearchInstance: {} });
@@ -112,46 +110,4 @@ describe('infiniteHits()', () => {
expect(helper.state.page).toBe(1);
expect(helper.search).toHaveBeenCalledTimes(1);
});
-
- it('if it is the first page, then the props should contain isFirstPage true', () => {
- const state = { page: 0 };
- widget.render({
- results: { ...results, page: 0, nbPages: 2 },
- state,
- });
- widget.render({
- results: { ...results, page: 1, nbPages: 2 },
- state,
- });
-
- expect(render).toHaveBeenCalledTimes(2);
-
- const [
- firstRenderingParameters,
- secondRenderingParameters,
- ] = render.mock.calls;
-
- expect(firstRenderingParameters[0].props.isFirstPage).toEqual(true);
- expect(firstRenderingParameters[1]).toEqual(container);
-
- expect(secondRenderingParameters[0].props.isFirstPage).toEqual(true);
- expect(secondRenderingParameters[1]).toEqual(container);
- });
-
- it('if it is not the first page, then the props should contain isFirstPage false', () => {
- // Init widget at page 1
- helper.setPage(1);
- widget.init({ helper, instantSearchInstance: {} });
-
- const state = { page: 1 };
- widget.render({
- results: { ...results, page: 1, nbPages: 2 },
- state,
- });
-
- expect(render).toHaveBeenCalledTimes(1);
-
- expect(render.mock.calls[0][0].props.isFirstPage).toEqual(false);
- expect(render.mock.calls[0][1]).toEqual(container);
- });
});
diff --git a/src/widgets/infinite-hits/defaultTemplates.js b/src/widgets/infinite-hits/defaultTemplates.js
index 79bc7270c8..220849dbf0 100644
--- a/src/widgets/infinite-hits/defaultTemplates.js
+++ b/src/widgets/infinite-hits/defaultTemplates.js
@@ -1,6 +1,5 @@
export default {
empty: 'No results',
- showPreviousText: 'Show previous results',
showMoreText: 'Show more results',
item(data) {
return JSON.stringify(data, null, 2);
diff --git a/src/widgets/infinite-hits/infinite-hits.js b/src/widgets/infinite-hits/infinite-hits.js
index 0301b82808..ebd10bfb13 100644
--- a/src/widgets/infinite-hits/infinite-hits.js
+++ b/src/widgets/infinite-hits/infinite-hits.js
@@ -17,22 +17,8 @@ const withUsage = createDocumentationMessageGenerator({
});
const suit = component('InfiniteHits');
-const renderer = ({
- cssClasses,
- containerNode,
- renderState,
- templates,
- showPrevious: hasShowPrevious,
-}) => (
- {
- hits,
- results,
- showMore,
- showPrevious,
- isFirstPage,
- isLastPage,
- instantSearchInstance,
- },
+const renderer = ({ cssClasses, containerNode, renderState, templates }) => (
+ { hits, results, showMore, isLastPage, instantSearchInstance },
isFirstRendering
) => {
if (isFirstRendering) {
@@ -49,11 +35,8 @@ const renderer = ({
cssClasses={cssClasses}
hits={hits}
results={results}
- hasShowPrevious={hasShowPrevious}
- showPrevious={showPrevious}
showMore={showMore}
templateProps={renderState.templateProps}
- isFirstPage={isFirstPage}
isLastPage={isLastPage}
/>,
containerNode
@@ -116,7 +99,6 @@ export default function infiniteHits({
transformItems,
templates = defaultTemplates,
cssClasses: userCssClasses = {},
- showPrevious,
} = {}) {
if (!container) {
throw new Error(withUsage('The `container` option is required.'));
@@ -139,14 +121,6 @@ export default function infiniteHits({
emptyRoot: cx(suit({ modifierName: 'empty' }), userCssClasses.emptyRoot),
item: cx(suit({ descendantName: 'item' }), userCssClasses.item),
list: cx(suit({ descendantName: 'list' }), userCssClasses.list),
- loadPrevious: cx(
- suit({ descendantName: 'loadPrevious' }),
- userCssClasses.loadPrevious
- ),
- disabledLoadPrevious: cx(
- suit({ descendantName: 'loadPrevious', modifierName: 'disabled' }),
- userCssClasses.disabledLoadPrevious
- ),
loadMore: cx(suit({ descendantName: 'loadMore' }), userCssClasses.loadMore),
disabledLoadMore: cx(
suit({ descendantName: 'loadMore', modifierName: 'disabled' }),
@@ -158,7 +132,6 @@ export default function infiniteHits({
containerNode,
cssClasses,
templates,
- showPrevious,
renderState: {},
});
@@ -166,5 +139,5 @@ export default function infiniteHits({
unmountComponentAtNode(containerNode)
);
- return makeInfiniteHits({ escapeHTML, transformItems, showPrevious });
+ return makeInfiniteHits({ escapeHTML, transformItems });
}
diff --git a/stories/infinite-hits.stories.js b/stories/infinite-hits.stories.js
index 875bca85de..3e6510cc19 100644
--- a/stories/infinite-hits.stories.js
+++ b/stories/infinite-hits.stories.js
@@ -1,6 +1,5 @@
import { storiesOf } from '@storybook/html';
import { withHits } from '../.storybook/decorators';
-import { MemoryRouter } from '../.storybook/MemoryRouter';
storiesOf('InfiniteHits', module)
.add(
@@ -69,25 +68,4 @@ storiesOf('InfiniteHits', module)
})
);
})
- )
- .add(
- 'with previous button enabled',
- withHits(
- ({ search, container, instantsearch }) => {
- search.addWidget(
- instantsearch.widgets.infiniteHits({
- container,
- showPrevious: true,
- templates: {
- item: '{{name}}',
- },
- })
- );
- },
- {
- routing: {
- router: new MemoryRouter({ page: 3 }),
- },
- }
- )
);
diff --git a/website/examples/calendar-widget/index.html b/website/examples/calendar-widget/index.html
index 24cd77ca4d..cdfbd6b0df 100644
--- a/website/examples/calendar-widget/index.html
+++ b/website/examples/calendar-widget/index.html
@@ -1,7 +1,7 @@
-
+
InstantSearch Calendar Widget
diff --git a/website/examples/e-commerce/index.html b/website/examples/e-commerce/index.html
index 1742da5d81..c2304d4838 100644
--- a/website/examples/e-commerce/index.html
+++ b/website/examples/e-commerce/index.html
@@ -14,7 +14,7 @@
/>