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

fix(range): don't go out of bounds with min or max given #4627

Merged
merged 8 commits into from
Feb 2, 2021

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Jan 15, 2021

Summary

fixes #4626

This PR fixes the bug where connectRange set the wrong range when min or max was given.

If you look at lines like this, connectRange assumes there is only one value per operator (It's getting the first item from the array). However, in getWidgetSearchParameters, it adds refinements for min and max bound if given. After that, it again adds the bound from uiState.

It's reproduced in controlled mode (by calling setUiState).

Result

It should fixes the reproduction from #4626
The fixed example: https://codesandbox.io/s/confident-pasteur-ocls6?file=/src/app.js

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 15, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 01dfce9:

Sandbox Source
InstantSearch.js Configuration
sleepy-sid-wsjoo PR

@eunjae-lee
Copy link
Contributor Author

Wait, if the one from uiState is out of the bound, then it should keep things in the bound. I will add a new test and update the PR next week.

@Haroenv
Copy link
Contributor

Haroenv commented Jan 18, 2021

This is indeed correct, but I'm not sure which one of the two should be taken as the source of truth. In theory there's nothing wrong with an out-of-bounds refinement, but then more of the connector is wrong.

@eunjae-lee
Copy link
Contributor Author

This is indeed correct, but I'm not sure which one of the two should be taken as the source of truth. In theory there's nothing wrong with an out-of-bounds refinement, but then more of the connector is wrong.

Hmm I thought the min, max bound given to the widget should be the source of truth. In the latest change 404d29d, the out-of-bound refinements are capped with the bound.
What do you think?

@Haroenv
Copy link
Contributor

Haroenv commented Jan 18, 2021

this makes sense I think, although you'll need to change the initial test to make sense

@eunjae-lee
Copy link
Contributor Author

this makes sense I think, although you'll need to change the initial test to make sense

can you tell me what about the initial test needs to change?

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change is good, but I don't know what the first test is meant to assert

src/connectors/range/__tests__/connectRange-test.ts Outdated Show resolved Hide resolved
@eunjae-lee
Copy link
Contributor Author

change is good, but I don't know what the first test is meant to assert

It might be unclear to you.

      const widget = makeWidget({
        attribute: 'price',
        min: 0,
        max: 500,
      });

      const actual = widget.getWidgetSearchParameters!(helper.state, {
        uiState: {
          range: {
            price: '0:400',
          },
        },
      });

      console.log(actual.numericRefinements.price['<=']);

Before this PR, it used to print [400, 500], instead of [400].

@Haroenv Haroenv changed the title fix(range): fix the wrong range with min or max given fix(range): don't go out of bounds with min or max given Feb 2, 2021
@eunjae-lee eunjae-lee merged commit 8327ec0 into master Feb 2, 2021
@eunjae-lee eunjae-lee deleted the fix/range branch February 2, 2021 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

connectRange does not trigger an update when both range bounds are set to undefined
4 participants