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

[time picker] Only update time when updating input in TimePicker #4398

Merged
merged 7 commits into from
Apr 11, 2022

Conversation

flaviendelangle
Copy link
Member

Fixes #4397

@alexfauquette I would like your opinion on this one.

My logic is to get the time (hour, minute, seconds, milliseconds) from the new date parsed from the input. But to get the date (day, month, year) from the previous date.

It works great, except if you don't have the ignoreInvalidInputs set to true (it blocks the onChange firing when the date is invalid).
Because as soon as you get an invalid date, your previous date becomes null on the next onChange and I can't merge it.

What do you prefer ?

  • We only fix for ignoreInvalidInputs=true
  • We keep track of the last valid date in a ref
  • Something else ?

@flaviendelangle flaviendelangle added bug 🐛 Something doesn't work component: TimePicker The React component. labels Apr 8, 2022
@flaviendelangle flaviendelangle self-assigned this Apr 8, 2022
@@ -18,6 +18,13 @@ const valueManager: PickerStateValueManager<unknown, unknown> = {
parseInput: parsePickerInputValue,
areValuesEqual: (utils: MuiPickersAdapter<unknown>, a: unknown, b: unknown) =>
utils.isEqual(a, b),
updateValue: (utils, prevValue, newValue) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Optional method (to be named in a better way) that creates the new value from the previous valud and the new one.

Allows us in TimePicker to only take the time from the new value but keep the date of the old value.

TODO: Do the same for MobileTimePicker (maybe refacto to avoid duplication on the value managers at some point)


date-fns handles this behavior out of the box, you can pass a reference date and when updating a mask it only applies the change of the elements in the mask, the rest is taken from the reference date.
It would be perfect here, but the others date libs do not support it from what I see.

@mui-bot
Copy link

mui-bot commented Apr 8, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 228.9 524.5 310.4 345.56 107.765
Sort 100k rows ms 585.2 1,005.9 619.7 743.32 151.708
Select 100k rows ms 99 311.4 212 176.52 77.18
Deselect 100k rows ms 100.4 275.9 184.1 185.92 55.629

Generated by 🚫 dangerJS against 971fd16

@flaviendelangle flaviendelangle marked this pull request as draft April 8, 2022 08:26
@alexfauquette
Copy link
Member

For me, it makes sense to track the last valid date. Since we are talking about a time picker, I assume the date can only be modified by the value prop

Why using a ref instead of a state?

@flaviendelangle
Copy link
Member Author

The ref was to avoid a re-render since we are only querying its value in a callback.

I did a first version with a state and a test

@flaviendelangle flaviendelangle marked this pull request as ready for review April 8, 2022 10:04
@alexfauquette
Copy link
Member

It sounds good. Do you want to do the MobileTimePicker in this PR?

@flaviendelangle
Copy link
Member Author

Yes, I applied the same logic on the mobile

@@ -18,6 +18,13 @@ const valueManager: PickerStateValueManager<unknown, unknown> = {
parseInput: parsePickerInputValue,
areValuesEqual: (utils: MuiPickersAdapter<unknown>, a: unknown, b: unknown) =>
utils.isEqual(a, b),
mergeOldAndNewValues: (utils, prevValue, newValue) => {
Copy link
Member

Choose a reason for hiding this comment

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

Another naming option: valueReducer(newValue, prevValue?, utils?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed
I keep utils 1st like on the other methods.
But feel free to change it later 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: TimePicker The React component.
Projects
None yet
3 participants