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

[pickers] Remove TDate generics in favor of PickerValidDate direct usage #15001

Open
wants to merge 65 commits into
base: master
Choose a base branch
from

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Oct 16, 2024

Closes #14796

Side note: all PickerValidDate | null passed as a generic will be replaced with a true or false once TValue is replaced by TIsRange (phrase 2 of #14823).

I will do the migration guide after the phase 2 of #14823 to have a finalized list of the breaking changes on the generics.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
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.

This is a massive improvement on the codebase. 💙 😍
Thank you for working on it! 🙏
However, I'm really not fond of the ugly solutions we have to take for docs. 🙈

Have you tried exploring a solution of localized PickerValidDate redefining? 🤔

.circleci/config.yml Outdated Show resolved Hide resolved
@@ -18,7 +19,7 @@ export default function ReferenceDateExplicitDateTimePicker() {
referenceDate={dayjs('2022-04-17T15:30')}
/>
<Typography>
Stored value: {value == null ? 'null' : value.format()}
Stored value: {value == null ? 'null' : (value as Dayjs).format()}
Copy link
Member

Choose a reason for hiding this comment

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

Oh yes, this isn't lovely. 🙈
I think that if we are going forward with this approach, we need a way to avoid the need for casting. 🙈
At least in the generated "preview".
Maybe we could by default enforce 'Dayjs' type and keep the option to override the type in those few instances where another adapter is used? 🤔

packages/x-date-pickers/src/locales/beBY.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,6 @@
import { PickerValidDate } from './pickers';

export type SimpleValue = PickerValidDate | null;
Copy link
Member

Choose a reason for hiding this comment

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

SimpleValue sounds somewhat strange. 🤷
Have you considered PickerValue?

Suggested change
export type SimpleValue = PickerValidDate | null;
export type PickerValue = PickerValidDate | null;

Copy link
Member Author

@flaviendelangle flaviendelangle Oct 29, 2024

Choose a reason for hiding this comment

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

I would like to rename DateRange in a follow up to have both interfaces being named coherently.
I was going for SimpleValue / RangeValue, but we could go for PickerValue / PickerRangeValue if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

My vote goes for the PickerValue and PickerRangeValue. 👍
WDYT @arthurbalduini?

@@ -113,23 +113,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
}

act(() => {
setValue(adapterToUse.date(past));
setValue(past);
Copy link
Member

Choose a reason for hiding this comment

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

👏 🙈 😆

@flaviendelangle
Copy link
Member Author

Have you tried exploring a solution of localized PickerValidDate redefining? 🤔

How would you do that?

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
Co-authored-by: Lukas Tyla <[email protected]>
Signed-off-by: Flavien DELANGLE <[email protected]>
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
@flaviendelangle
Copy link
Member Author

@LukasTy one option would be to add the following code in one of the doc files:

declare module '@mui/x-date-pickers/models' {
  interface PickerValidDateLookup {
    fakeDocAdapter: any;
  }
}

It would not impact Codesandbox / Stackblitz.
We would have any as a value in the doc examples but I don't think we care since today we have the union of all the date library types and we never really missed this type safety.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 31, 2024
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Oct 31, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: pickers This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] Replace the TDate generic with PickerValidDate in every type / interface
3 participants