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

Recomputes more modifiers when focusedInput changes #522

Conversation

timhwang21
Copy link
Collaborator

Previously, only props.isDayBlocked() and props.isDayHighlighted() are computed. However, in my use case, where there are different validations on the start and end date inputs, 'blocked' and 'blocked-out-of-range' persisted when the focused input changes. This PR adds recomputation of modifiers with this.isBlocked() and props.isOutOfRange().

I've also added tests; however, it seems like this.isBlocked() is getting called for all visible dates instead of only the changed dates. I commented out the failing tests for now (returns 183 calls or something) -- more clarification on that would be appreciated!

Also, if there's any reason I missed that these checks shouldn't be done, please let me know. I tested my fork in my use case and the problem was fixed.

Thanks!

Previously, only `props.isDayBlocked()` and `props.isDayHighlighted()` are computed. However, in my use case, where there are different validations on the start and end date inputs, `'blocked'` and `'blocked-out-of-range'` persisted when the focused input changes. This PR adds recomputation of modifiers with `this.isBlocked()` and `props.isOutOfRange()`.

I've also added tests; however, it seems like `this.isBlocked()` is getting called for all visible dates instead of only the changed dates. I commented out the failing tests for now (returns 183 calls or something) -- more clarification on that would be appreciated!

Also, if there's any reason I missed that these checks shouldn't be done, please let me know. I tested my fork in my use case and the problem was fixed.

Thanks!
@timhwang21
Copy link
Collaborator Author

This PR is meant to fix #517.

@majapw
Copy link
Collaborator

majapw commented May 17, 2017

Woo! Thanks for adding this! I will look over this tonight or tomorrow!

@coveralls
Copy link

coveralls commented May 17, 2017

Coverage Status

Coverage increased (+0.1%) to 86.677% when pulling 6a7e3b6 on timhwang21:timhwang21/recompute-modifiers-after-focusedinput-change into 0eb0d04 on airbnb:master.

@@ -796,6 +796,140 @@ describe('DayPickerRangeController', () => {
});
});

describe('blocked', () => {
describe.skip('focusedInput did not change', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is one of the two tests I referenced in my commit message. I wasn't sure if it was appropriate to leave them out, or if it getting called 183 times actually isn't expected.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So you probably have to reset the stub after the initial shallow render. The first mount is going to call this method a bunch of times! You want to isolate it to make sure that you're only checking how many times componentWillReceiveProps is calling it!

});
const blockedCalendarCalls = getCallsByModifier(addModifierSpy, 'blocked');
expect(blockedCalendarCalls.length).to.equal(numVisibleDays);
isBlockedStub.restore();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@majapw thanks for the tip re: resetting stubs! However, in this test and the following one, I need to make a stub that returns true or false. However, I don't ever need to access the stub, as blockedCalendarCalls is what's used to verify the test.

I realized I was mistakenly passing the stub in with the props in my previous commit (doing nothing) but after removing it I started getting a no-unused-vars lint error. So I shoehorned isBlockedStub.restore() in. Would this be an acceptable place for // eslint-ignore-line no-unused-vars?

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

You don't need the restore - just don't assign the stub to a variable. In other words, sinon.stub(foo, bar); is fine by itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, fixed

@coveralls
Copy link

coveralls commented May 18, 2017

Coverage Status

Coverage increased (+0.1%) to 86.677% when pulling 8ab3a09 on timhwang21:timhwang21/recompute-modifiers-after-focusedinput-change into 0eb0d04 on airbnb:master.

@coveralls
Copy link

coveralls commented May 18, 2017

Coverage Status

Coverage increased (+0.1%) to 86.677% when pulling 6aae9fe on timhwang21:timhwang21/recompute-modifiers-after-focusedinput-change into 0eb0d04 on airbnb:master.

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

This seems great!

@majapw majapw merged commit e801f9d into react-dates:master May 26, 2017
@timhwang21
Copy link
Collaborator Author

Awesome, thanks!

@dvmorris
Copy link

dvmorris commented Jun 1, 2017

Any idea when this will be released? I ran into this issue today.

@timhwang21 timhwang21 deleted the timhwang21/recompute-modifiers-after-focusedinput-change branch July 29, 2017 14:46
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.

5 participants