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] Rename AdapterDateFns into AdapterDateFnsV2 and AdapterDateFnsV3 into AdapterDateFns #16082

Merged
merged 19 commits into from
Jan 7, 2025

Conversation

LukasTy
Copy link
Member

@LukasTy LukasTy commented Jan 6, 2025

Fixes #14478.

  • Also accordingly rename AdapterDateFnsJalali.
  • Update codebase to use date-fns@4
  • Add codemod (should we include it in safe preset if it is NOT idempotent?)
  • Fix new TS issues

@LukasTy LukasTy added breaking change component: pickers This is the name of the generic UI component, not the React module! v8.x labels Jan 6, 2025
@LukasTy LukasTy self-assigned this Jan 6, 2025
@@ -50,17 +49,11 @@ describe('<AdapterDateFnsJalali />', () => {
placeholder: 'YYYY/MM/DD hh:mm aa',
value: '1397/02/25 09:35 ق.ظ.',
},
faJalaliIR: {
Copy link
Member Author

Choose a reason for hiding this comment

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

Such a locale no longer exists on v4.

import transformFieldValue from '../rename-and-move-field-value-type';

import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types';

export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) {
file.source = transformAdapterDateFnsImports(file, api, options);
Copy link
Member Author

Choose a reason for hiding this comment

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

WDYT, should we include it in the safe preset if it is NOT idempotent?
Running it repeatedly will change the imports back and forth. 🙈

Copy link
Member

Choose a reason for hiding this comment

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

WDYT, should we include it in the safe preset if it is NOT idempotent?

Oh crap, that's a good question.
Could it be work adding a small comment at the end of the line that we can check to make it idempotent? 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't imagine how we could do it cleanly (without adding some marker comment)... 🤷
It's the nature of the rename, that we are essentially swapping the adapter names, with the exception that AdapterV3 becomes Adapter and then after a subsequent run would become AdapterV2 at which point the codemod would no longer rename it back to Adapter, but it's still:

`AdapterV3` -> run codemod -> `Adapter` -> run codemod -> `AdapterV2`

Copy link
Member

@flaviendelangle flaviendelangle Jan 7, 2025

Choose a reason for hiding this comment

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

I don't imagine how we could do it cleanly (without adding some marker comment)... 🤷

Me neither
The only solution I see is to transform:

import { AdapterDateFnsV3 } from '@mui/x-date-pickers/AdapterDateFnsV3';

into

// x-codemod/v8.0.0/pickers/adapter-date-fns-imports makes sure this codemod is idempotent. Don't remove unless you are sure not to run the v8.0.0 preset safe again.
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; 

And check for the existence of the comment before transforming.

Which is far from great 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, exactly... 🙈
Let's go the slightly risky route and wait for user feedback if this seems problematic. 🤔

@@ -1129,6 +1129,36 @@ If you were using them, you need to replace them with the following code:
+ extends BaseMultiInputPickersTextFieldProps<true> {}
```

## ✅ Rename `date-fns` adapter imports

:::warning
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a warning here to align with the codemod package readme.
Does it sound like a decent compromise @flaviendelangle @michelengelen? 🤔
We can always remove it from the preset-safe and keep it opt-in if there are complaints... 🤷

```

:::
> [!WARNING]
Copy link
Member Author

Choose a reason for hiding this comment

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

This only works in our docs.
Fix the styling for markdown.

Before

Screenshot 2025-01-07 at 15 20 47

After

Screenshot 2025-01-07 at 15 19 08

@LukasTy LukasTy merged commit f1332f1 into mui:master Jan 7, 2025
18 checks passed
@LukasTy LukasTy deleted the swap-date-fns-majors branch January 7, 2025 14:45
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! v8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] Rename AdapterDateFns into AdapterDateFnsV2 and AdapterDateFnsV3 into AdapterDateFns
4 participants