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

[fields] Allow to explicitly define the reference date and improve its default value #9019

Merged
merged 11 commits into from
May 25, 2023

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented May 17, 2023

Closes #8311
Closes #9023

Introducing the same prop on the pickers would solve the following issues:

Part of #8426 (starts to introduce the ms methods on the adapters)

Goal 1: Smartly handle the referenceValue based on the validation props

When a field does not contain all the sections it could have (e.g: a DateField with no year), people can be stuck with an invalid value and not be able to fix it because the invalid part is not present in the format.

Goal 2: Smartly handle the referenceValue based on the sections present

When a field does not contain some more precise sections (e.g: a field without a seconds sections), we don't want to take the sections of today's date.
The sections with a higher granularity than the format should be set to 0 instead of the current value.

Goal 3: Allow user the set a custom referenceValue with the new referenceDate prop

The main use case I see is how to set the date the 1st filled value should have on a TimeField when there is not value / defaultValue.

  • Add a referenceDate prop on fields
  • Improve the default referenceValue based on validation
  • Round the default referenceValue based on the sections extracted from the format
  • Add tests

Follow up

  • Add a referenceValue prop on pickers, compute it's value based on the views and the validation props
  • Replace defaultCalendarMonth with referenceValue (keep the old one but deprecate)

@flaviendelangle flaviendelangle added the component: pickers This is the name of the generic UI component, not the React module! label May 17, 2023
@flaviendelangle flaviendelangle changed the title [fields] Expose the referenceValue and improve its default value [fields] Expose the referenceValue and improve its default value May 17, 2023
@flaviendelangle flaviendelangle self-assigned this May 17, 2023
@mui-bot
Copy link

mui-bot commented May 17, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-9019--material-ui-x.netlify.app/

Updated pages

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 631.3 1,261.5 631.3 883.82 243.437
Sort 100k rows ms 694.8 1,202.6 702 901.82 189.202
Select 100k rows ms 282.6 309.4 303 297.28 11.98
Deselect 100k rows ms 130.3 372.7 271.3 239.96 89.565

Generated by 🚫 dangerJS against f6a1ac2

@flaviendelangle flaviendelangle force-pushed the smart-referenceValue branch 5 times, most recently from 7e8063e to f7a2f5b Compare May 17, 2023 13:50
@flaviendelangle flaviendelangle changed the title [fields] Expose the referenceValue and improve its default value [fields] Allow to explicitly define the reference value and improve its default value May 19, 2023
@flaviendelangle flaviendelangle marked this pull request as ready for review May 22, 2023 07:26
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

From a limited amount of testing it looks like a really nice improvement! 👍 💯
Have you considered having referenceDate exposed top-level via pickers as well? Or do you want to firstly release it available only on fields for testing and only later add it to pickers if everything is smooth? 🤔

@flaviendelangle
Copy link
Member Author

Have you considered having referenceDate exposed top-level via pickers as well? Or do you want to firstly release it available only on fields for testing and only later add it to pickers if everything is smooth?

Yes, I'm splitting the work in two, but the goal is to release it on the pickers as well.
I'm not doing it here because it requires handling properly the defaultCalendarMonth fallback which would make this PR too big 👍

@flaviendelangle flaviendelangle merged commit 5aa1812 into mui:master May 25, 2023
@flaviendelangle flaviendelangle deleted the smart-referenceValue branch May 25, 2023 15:02
@flaviendelangle flaviendelangle changed the title [fields] Allow to explicitly define the reference value and improve its default value [fields] Allow to explicitly define the reference date and improve its default value Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
4 participants