Skip to content

Commit

Permalink
fix(connectors): don't expose duplicates of canRefine
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
Haroenv committed Dec 26, 2024
1 parent b37ba30 commit 84b17ba
Show file tree
Hide file tree
Showing 23 changed files with 29 additions and 118 deletions.
4 changes: 2 additions & 2 deletions examples/react/default-theme/src/components/NumericMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export type NumericMenuProps = React.ComponentProps<'div'> &
UseNumericMenuProps;

export function NumericMenu(props: NumericMenuProps) {
const { hasNoResults, items, refine } = useNumericMenu(props);
const { canRefine, items, refine } = useNumericMenu(props);

return (
<div
className={cx(
'ais-NumericMenu',
hasNoResults && 'ais-NumericMenu--noRefinement',
!canRefine && 'ais-NumericMenu--noRefinement',
props.className
)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
});
Expand All @@ -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);
});

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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!(
Expand All @@ -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);
});

Expand All @@ -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!(
Expand All @@ -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);
});

Expand All @@ -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!(
Expand All @@ -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);
});

Expand All @@ -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!(
Expand All @@ -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);
});

Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -210,7 +204,6 @@ export const connectClearRefinements: ClearRefinementsConnector =

return {
canRefine,
hasRefinements: canRefine,
refine: cachedRefine,
createURL: cachedCreateURL,
widgetParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ export type NumericMenuRenderState = {
*/
createURL: CreateURL<NumericMenuRenderStateItem['value']>;

/**
* `true` if the last search contains no result
* @deprecated Use `canRefine` instead.
*/
hasNoResults: boolean;

/**
* Indicates if search state can be refined.
*
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 84b17ba

Please sign in to comment.