From 34ae6d227fedb7258e111732277d7f091820704f Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Thu, 19 Dec 2024 17:23:57 +0100 Subject: [PATCH] fix(connectors): don't expose duplicates of canRefine In the past, `canRefine` has been introduced as a consistent way to check if any widget can be refined. There were previous largely overlapping pieces of information exposed which were deprecated. These are now removed. [FX-3195] BREAKING CHANGE: clearRefinements: replace `hasRefinements` with `canRefine` BREAKING CHANGE: hitsPerPage: replace `hasNoResults` with `!canRefine` BREAKING CHANGE: numericMenu: replace `hasNoResults` with `!canRefine` BREAKING CHANGE: ratingMenu: replace `hasNoResults` with `!canRefine` BREAKING CHANGE: sortBy: replace `hasNoResults` with `!canRefine` --- .../__tests__/connectClearRefinements.test.ts | 19 ------------------- .../__tests__/connectHitsPerPage.test.ts | 6 ------ .../__tests__/connectNumericMenu.test.ts | 5 ----- .../__tests__/connectRatingMenu.test.ts | 5 ----- .../__tests__/connectSortBy.test.ts | 4 ---- .../src/connectors/connectClearRefinements.ts | 7 ------- .../src/connectors/connectHitsPerPage.ts | 7 ------- .../src/connectors/connectNumericMenu.ts | 7 ------- .../src/connectors/connectRatingMenu.ts | 8 -------- .../src/connectors/connectSortBy.ts | 6 ------ .../__tests__/useClearRefinements.test.tsx | 4 ---- .../__tests__/useHitsPerPage.test.tsx | 2 -- .../__tests__/useNumericMenu.test.tsx | 2 -- .../connectors/__tests__/useSortBy.test.tsx | 2 -- .../src/components/ClearRefinements.vue | 12 ++++++------ .../components/__tests__/ClearRefinements.js | 6 +++--- 16 files changed, 9 insertions(+), 93 deletions(-) diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectClearRefinements.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectClearRefinements.test.ts index df58df05e7..5bc39c2c5d 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectClearRefinements.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectClearRefinements.test.ts @@ -97,7 +97,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin expect(firstRenderingOptions.createURL).toBeInstanceOf(Function); expect(firstRenderingOptions.refine).toBeInstanceOf(Function); expect(firstRenderingOptions.canRefine).toBe(false); - expect(firstRenderingOptions.hasRefinements).toBe(false); expect(firstRenderingOptions.widgetParams).toEqual({ foo: 'bar', // dummy param to test `widgetParams` }); @@ -121,7 +120,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin expect(isFirstRenderAtRender).toBe(false); expect(secondRenderingOptions.createURL).toBeInstanceOf(Function); expect(secondRenderingOptions.refine).toBeInstanceOf(Function); - expect(secondRenderingOptions.hasRefinements).toBe(false); expect(secondRenderingOptions.canRefine).toBe(false); }); @@ -162,7 +160,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin ); expect(renderState1.clearRefinements).toEqual({ - hasRefinements: false, canRefine: false, createURL: expect.any(Function), refine: expect.any(Function), @@ -209,7 +206,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin ); expect(renderState2.clearRefinements).toEqual({ - hasRefinements: true, canRefine: true, createURL: expect.any(Function), refine: expect.any(Function), @@ -243,7 +239,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin ); expect(renderState1).toEqual({ - hasRefinements: false, canRefine: false, createURL: expect.any(Function), refine: expect.any(Function), @@ -289,7 +284,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin ); expect(renderState2).toEqual({ - hasRefinements: true, canRefine: true, createURL: expect.any(Function), refine: expect.any(Function), @@ -449,7 +443,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[0][0].hasRefinements).toBe(false); expect(rendering.mock.calls[0][0].canRefine).toBe(false); widget.render!( @@ -462,7 +455,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[1][0].hasRefinements).toBe(true); expect(rendering.mock.calls[1][0].canRefine).toBe(true); }); @@ -488,7 +480,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[0][0].hasRefinements).toBe(false); expect(rendering.mock.calls[0][0].canRefine).toBe(false); widget.render!( @@ -501,7 +492,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[1][0].hasRefinements).toBe(true); expect(rendering.mock.calls[1][0].canRefine).toBe(true); }); @@ -524,7 +514,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[0][0].hasRefinements).toBe(false); expect(rendering.mock.calls[0][0].canRefine).toBe(false); widget.render!( @@ -537,7 +526,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[1][0].hasRefinements).toBe(false); expect(rendering.mock.calls[1][0].canRefine).toBe(false); }); @@ -557,7 +545,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[0][0].hasRefinements).toBe(false); expect(rendering.mock.calls[0][0].canRefine).toBe(false); widget.render!( @@ -570,7 +557,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin }) ); - expect(rendering.mock.calls[1][0].hasRefinements).toBe(false); expect(rendering.mock.calls[1][0].canRefine).toBe(false); }); @@ -624,7 +610,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin expect(helper.hasRefinements('facet1')).toBe(false); expect(helper.hasRefinements('facet2')).toBe(true); - expect(rendering.mock.calls[2][0].hasRefinements).toBe(false); expect(rendering.mock.calls[2][0].canRefine).toBe(false); }); @@ -675,7 +660,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin expect(helper.hasRefinements('facet1')).toBe(false); expect(helper.state.query).toBe(''); - expect(rendering.mock.calls[2][0].hasRefinements).toBe(false); expect(rendering.mock.calls[2][0].canRefine).toBe(false); }); @@ -723,8 +707,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin expect(helper.hasRefinements('facet1')).toBe(false); expect(helper.hasRefinements('facet2')).toBe(true); - - expect(rendering.mock.calls[1][0].hasRefinements).toBe(true); expect(rendering.mock.calls[1][0].canRefine).toBe(true); } @@ -824,7 +806,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin expect(helper.hasRefinements('facet2')).toBe(true); expect(helper.hasRefinements('facet3')).toBe(false); expect(helper.state.query).toBe(''); - expect(rendering.mock.calls[2][0].hasRefinements).toBe(false); expect(rendering.mock.calls[2][0].canRefine).toBe(false); }); diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectHitsPerPage.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectHitsPerPage.test.ts index 3b2bc06ef5..f3f8a5038f 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectHitsPerPage.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectHitsPerPage.test.ts @@ -769,7 +769,6 @@ You may want to add another entry to the \`items\` option with this value.`); ], createURL: expect.any(Function), refine: expect.any(Function), - hasNoResults: false, canRefine: true, widgetParams: { items: [ @@ -804,7 +803,6 @@ You may want to add another entry to the \`items\` option with this value.`); }, ], createURL: expect.any(Function), - hasNoResults: true, canRefine: false, refine: expect.any(Function), widgetParams: { @@ -841,7 +839,6 @@ You may want to add another entry to the \`items\` option with this value.`); ], createURL: () => '', refine: () => {}, - hasNoResults: true, canRefine: false, widgetParams: { items: [ @@ -889,7 +886,6 @@ You may want to add another entry to the \`items\` option with this value.`); }, ], createURL: expect.any(Function), - hasNoResults: true, canRefine: false, refine: expect.any(Function), widgetParams: { @@ -944,7 +940,6 @@ You may want to add another entry to the \`items\` option with this value.`); ], refine: expect.any(Function), createURL: expect.any(Function), - hasNoResults: true, canRefine: false, widgetParams: { items: [ @@ -995,7 +990,6 @@ You may want to add another entry to the \`items\` option with this value.`); }, ], createURL: expect.any(Function), - hasNoResults: true, canRefine: false, refine: expect.any(Function), widgetParams: { diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectNumericMenu.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectNumericMenu.test.ts index 5a72026e1c..faef0e728d 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectNumericMenu.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectNumericMenu.test.ts @@ -1172,7 +1172,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men expect(renderState1.numericMenu).toEqual({ numerics: { createURL: expect.any(Function), - hasNoResults: true, canRefine: false, items: [ { @@ -1232,7 +1231,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men createURL: expect.any(Function), refine: renderState1.numericMenu.numerics.refine, sendEvent: renderState1.numericMenu.numerics.sendEvent, - hasNoResults: true, canRefine: false, items: [ { @@ -1314,7 +1312,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men createURL: expect.any(Function), refine: expect.any(Function), sendEvent: expect.any(Function), - hasNoResults: true, canRefine: false, widgetParams: { attribute: 'numerics', @@ -1365,7 +1362,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men createURL: expect.any(Function), refine: expect.any(Function), sendEvent: expect.any(Function), - hasNoResults: true, canRefine: false, widgetParams: { attribute: 'numerics', @@ -1401,7 +1397,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men expect(renderState2).toEqual({ createURL: expect.any(Function), - hasNoResults: true, canRefine: false, items: [ { diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectRatingMenu.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectRatingMenu.test.ts index 0e95d40c58..e0b094eba8 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectRatingMenu.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectRatingMenu.test.ts @@ -493,7 +493,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu canRefine: false, refine: expect.any(Function), sendEvent: expect.any(Function), - hasNoResults: true, widgetParams: { attribute: 'grade', }, @@ -577,7 +576,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu canRefine: true, refine: expect.any(Function), sendEvent: renderState1.ratingMenu.grade.sendEvent, - hasNoResults: true, widgetParams: { attribute: 'grade', }, @@ -613,7 +611,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu canRefine: false, refine: expect.any(Function), sendEvent: expect.any(Function), - hasNoResults: true, widgetParams: { attribute: 'grade', }, @@ -695,7 +692,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu canRefine: true, refine: expect.any(Function), sendEvent: renderState1.sendEvent, - hasNoResults: true, widgetParams: { attribute: 'grade', }, @@ -735,7 +731,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu canRefine: false, refine: expect.any(Function), sendEvent: renderState1.sendEvent, - hasNoResults: true, widgetParams: { attribute: 'grade', }, diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectSortBy.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectSortBy.test.ts index 6424fdaad1..e0f5f5c26f 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectSortBy.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectSortBy.test.ts @@ -329,7 +329,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/sort-by/js/ expect(renderState1.sortBy).toEqual({ currentRefinement: 'index_default', refine: expect.any(Function), - hasNoResults: true, canRefine: false, options: [ { label: 'default', value: 'index_default' }, @@ -371,7 +370,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/sort-by/js/ expect(renderState2.sortBy).toEqual({ currentRefinement: 'index_desc', refine: expect.any(Function), - hasNoResults: false, canRefine: true, options: [ { label: 'default', value: 'index_default' }, @@ -412,7 +410,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/sort-by/js/ expect(renderState1).toEqual({ currentRefinement: 'index_desc', refine: expect.any(Function), - hasNoResults: true, canRefine: false, options: [ { label: 'default', value: 'index_default' }, @@ -452,7 +449,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/sort-by/js/ expect(renderState2).toEqual({ currentRefinement: 'index_default', refine: expect.any(Function), - hasNoResults: false, canRefine: true, options: [ { label: 'default', value: 'index_default' }, diff --git a/packages/instantsearch-core/src/connectors/connectClearRefinements.ts b/packages/instantsearch-core/src/connectors/connectClearRefinements.ts index 453a3afffe..a810bc48be 100644 --- a/packages/instantsearch-core/src/connectors/connectClearRefinements.ts +++ b/packages/instantsearch-core/src/connectors/connectClearRefinements.ts @@ -43,12 +43,6 @@ export type ClearRefinementsRenderState = { */ refine: () => void; - /** - * Indicates if search state is refined. - * @deprecated prefer reading canRefine - */ - hasRefinements: boolean; - /** * Indicates if search state can be refined. */ @@ -210,7 +204,6 @@ export const connectClearRefinements: ClearRefinementsConnector = return { canRefine, - hasRefinements: canRefine, refine: cachedRefine, createURL: cachedCreateURL, widgetParams, diff --git a/packages/instantsearch-core/src/connectors/connectHitsPerPage.ts b/packages/instantsearch-core/src/connectors/connectHitsPerPage.ts index 7eebe8a8d2..6f200a225e 100644 --- a/packages/instantsearch-core/src/connectors/connectHitsPerPage.ts +++ b/packages/instantsearch-core/src/connectors/connectHitsPerPage.ts @@ -88,12 +88,6 @@ export type HitsPerPageRenderState = { */ refine: (value: number) => void; - /** - * Indicates whether or not the search has results. - * @deprecated Use `canRefine` instead. - */ - hasNoResults: boolean; - /** * Indicates if search state can be refined. */ @@ -278,7 +272,6 @@ You may want to add another entry to the \`items\` option with this value.` getWidgetUiState: this.getWidgetUiState, helper, }), - hasNoResults: !canRefine, canRefine, widgetParams, }; diff --git a/packages/instantsearch-core/src/connectors/connectNumericMenu.ts b/packages/instantsearch-core/src/connectors/connectNumericMenu.ts index a44d6d0e60..968d96fb89 100644 --- a/packages/instantsearch-core/src/connectors/connectNumericMenu.ts +++ b/packages/instantsearch-core/src/connectors/connectNumericMenu.ts @@ -82,12 +82,6 @@ export type NumericMenuRenderState = { */ createURL: CreateURL; - /** - * `true` if the last search contains no result - * @deprecated Use `canRefine` instead. - */ - hasNoResults: boolean; - /** * Indicates if search state can be refined. * @@ -340,7 +334,6 @@ export const connectNumericMenu: NumericMenuConnector = return { createURL: connectorState.createURL(state), items: transformItems(preparedItems, { results }), - hasNoResults, canRefine: !(hasNoResults && allIsSelected), refine: connectorState.refine, sendEvent: connectorState.sendEvent, diff --git a/packages/instantsearch-core/src/connectors/connectRatingMenu.ts b/packages/instantsearch-core/src/connectors/connectRatingMenu.ts index 1a354dea7a..ef69a7920b 100644 --- a/packages/instantsearch-core/src/connectors/connectRatingMenu.ts +++ b/packages/instantsearch-core/src/connectors/connectRatingMenu.ts @@ -131,13 +131,6 @@ export type RatingMenuRenderState = { */ refine: (value: string) => void; - /** - * `true` if the last search contains no result. - * - * @deprecated Use `canRefine` instead. - */ - hasNoResults: boolean; - /** * Send event to insights middleware */ @@ -415,7 +408,6 @@ export const connectRatingMenu: RatingMenuConnector = return { items: facetValues, - hasNoResults, canRefine: (!hasNoResults || refinementIsApplied) && totalCount > 0, refine: connectorState.toggleRefinementFactory(helper), sendEvent, diff --git a/packages/instantsearch-core/src/connectors/connectSortBy.ts b/packages/instantsearch-core/src/connectors/connectSortBy.ts index e27b8ce846..d6e0bf261b 100644 --- a/packages/instantsearch-core/src/connectors/connectSortBy.ts +++ b/packages/instantsearch-core/src/connectors/connectSortBy.ts @@ -57,11 +57,6 @@ export type SortByRenderState = { * Switches indices and triggers a new search. */ refine: (value: string) => void; - /** - * `true` if the last search contains no result. - * @deprecated Use `canRefine` instead. - */ - hasNoResults: boolean; /** * `true` if we can refine. */ @@ -179,7 +174,6 @@ export const connectSortBy: SortByConnector = function connectSortBy( currentRefinement: state.index, options: transformItems(items, { results }), refine: connectorState.setIndex, - hasNoResults, canRefine: !hasNoResults && items.length > 0, widgetParams, }; diff --git a/packages/react-instantsearch-core/src/connectors/__tests__/useClearRefinements.test.tsx b/packages/react-instantsearch-core/src/connectors/__tests__/useClearRefinements.test.tsx index 7c7f93fb3c..a02fcc54b8 100644 --- a/packages/react-instantsearch-core/src/connectors/__tests__/useClearRefinements.test.tsx +++ b/packages/react-instantsearch-core/src/connectors/__tests__/useClearRefinements.test.tsx @@ -19,7 +19,6 @@ describe('useClearRefinements', () => { // Initial render state from manual `getWidgetRenderState` expect(result.current).toEqual({ - hasRefinements: false, canRefine: false, refine: expect.any(Function), createURL: expect.any(Function), @@ -29,7 +28,6 @@ describe('useClearRefinements', () => { // InstantSearch.js state from the `render` lifecycle step expect(result.current).toEqual({ - hasRefinements: false, canRefine: false, refine: expect.any(Function), createURL: expect.any(Function), @@ -64,7 +62,6 @@ describe('useClearRefinements', () => { // Initial render state from manual `getWidgetRenderState` expect(result.current).toEqual({ - hasRefinements: true, canRefine: true, refine: expect.any(Function), createURL: expect.any(Function), @@ -74,7 +71,6 @@ describe('useClearRefinements', () => { // InstantSearch.js state from the `render` lifecycle step expect(result.current).toEqual({ - hasRefinements: true, canRefine: true, refine: expect.any(Function), createURL: expect.any(Function), diff --git a/packages/react-instantsearch-core/src/connectors/__tests__/useHitsPerPage.test.tsx b/packages/react-instantsearch-core/src/connectors/__tests__/useHitsPerPage.test.tsx index bf16f57ebe..465acb69da 100644 --- a/packages/react-instantsearch-core/src/connectors/__tests__/useHitsPerPage.test.tsx +++ b/packages/react-instantsearch-core/src/connectors/__tests__/useHitsPerPage.test.tsx @@ -23,7 +23,6 @@ describe('useHitsPerPage', () => { expect(result.current).toEqual({ refine: expect.any(Function), createURL: expect.any(Function), - hasNoResults: true, canRefine: false, items: [ { @@ -46,7 +45,6 @@ describe('useHitsPerPage', () => { expect(result.current).toEqual({ refine: expect.any(Function), createURL: expect.any(Function), - hasNoResults: true, canRefine: false, items: [ { diff --git a/packages/react-instantsearch-core/src/connectors/__tests__/useNumericMenu.test.tsx b/packages/react-instantsearch-core/src/connectors/__tests__/useNumericMenu.test.tsx index 2ee933954c..f1a5d94f38 100644 --- a/packages/react-instantsearch-core/src/connectors/__tests__/useNumericMenu.test.tsx +++ b/packages/react-instantsearch-core/src/connectors/__tests__/useNumericMenu.test.tsx @@ -25,7 +25,6 @@ describe('useNumericMenu', () => { // Initial render state from manual `getWidgetRenderState` expect(result.current).toEqual({ createURL: expect.any(Function), - hasNoResults: true, canRefine: false, items: [ { @@ -58,7 +57,6 @@ describe('useNumericMenu', () => { // InstantSearch.js state from the `render` lifecycle step expect(result.current).toEqual({ createURL: expect.any(Function), - hasNoResults: true, canRefine: false, items: [ { diff --git a/packages/react-instantsearch-core/src/connectors/__tests__/useSortBy.test.tsx b/packages/react-instantsearch-core/src/connectors/__tests__/useSortBy.test.tsx index 2dec820032..9bf75daed0 100644 --- a/packages/react-instantsearch-core/src/connectors/__tests__/useSortBy.test.tsx +++ b/packages/react-instantsearch-core/src/connectors/__tests__/useSortBy.test.tsx @@ -21,7 +21,6 @@ describe('useSortBy', () => { currentRefinement: 'indexName', options: items, refine: expect.any(Function), - hasNoResults: expect.any(Boolean), canRefine: expect.any(Boolean), }); @@ -31,7 +30,6 @@ describe('useSortBy', () => { currentRefinement: 'indexName', options: items, refine: expect.any(Function), - hasNoResults: expect.any(Boolean), canRefine: expect.any(Boolean), }); }); diff --git a/packages/vue-instantsearch/src/components/ClearRefinements.vue b/packages/vue-instantsearch/src/components/ClearRefinements.vue index 066d9ae51a..e5a514932f 100644 --- a/packages/vue-instantsearch/src/components/ClearRefinements.vue +++ b/packages/vue-instantsearch/src/components/ClearRefinements.vue @@ -2,14 +2,17 @@