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] Add codemods for breaking changes #6997

Closed
16 of 19 tasks
LukasTy opened this issue Nov 25, 2022 · 5 comments
Closed
16 of 19 tasks

[pickers] Add codemods for breaking changes #6997

LukasTy opened this issue Nov 25, 2022 · 5 comments
Assignees
Labels
component: pickers This is the name of the generic UI component, not the React module! package: codemod Specific to @mui/codemod umbrella For grouping multiple issues to provide a holistic view v6.x

Comments

@LukasTy
Copy link
Member

LukasTy commented Nov 25, 2022

The v6 for pickers is bringing quite a few breaking changes.
To ease users' migration we ought to try and cover as most changes with codemods as possible.

The codemod package can be found here. It already contains all the core setup needed in order to add new codemods to it.

This is intended as an umbrella issue to group all the codemods needed for v.6.x migration.
Ideally as much migrations as possible should be provided with preset-safe codemod.

The process of adding a new codemod

  • One of the existing codemods can be used as an example (i.e.: localization-provider-rename-locale)
  • copy or create a new folder for your codemod
  • all the relevant code that is eventually shipped to the user is in index.ts
  • update/provide tests for your newly created codemod (test fixtures are authored as js files to allow as minimal syntax as you want—without triggering ts issues)
  • if your codemod is safe to add to preset-safe—update this codemod with your newly added codemod making sure the codemods order is correct if codemod is sensitive to that (i.e. separate props should firstly be migrated to componentProps and only later be passed through a codemod renaming componentProps to slotProps if we'd go with such approach)
  • update README file with your newly added codemod
    You can check @mui/codemod for inspiration on more advanced migration cases.

How to test your changes locally (on a different project)

P.S. yarn link does not create a bin command from a linked package

  • run build with either yarn workspace @mui/x-codemod build or yarn build if you are in src/packages/x-codemod
  • run cd build && yarn pack
  • copy the built 7.tgz file to the root of your project you want to run (test) the codemod in
  • add "@mui/x-codemod": "file:./<your_package_name>" into your project dependencies
  • run yarn install
  • now you can run the codemod in the way you prefer (either through npx @mui/x-codemod v6.0.0/preset-safe src or by adding an x-codemod script in your project)
  • caveat: testing iterative changes might result in a cached package version being used instead of your latest modification. You can either use a unique package name (possibly quicker) each time or clean npm cache each time.

Breaking changes requiring codemods

Breaking changes related to pickers are documented here and relevant PRs are available with applied filters.

@LukasTy LukasTy added umbrella For grouping multiple issues to provide a holistic view v6.x component: pickers This is the name of the generic UI component, not the React module! package: codemod Specific to @mui/codemod labels Nov 25, 2022
@LukasTy LukasTy self-assigned this Nov 25, 2022
@alexfauquette
Copy link
Member

alexfauquette commented Nov 28, 2022

For the localeText prop, I should import: mui/material-ui#34430

@alexfauquette
Copy link
Member

@LukasTy About rename-should-disable-time I don't know if we can do a codemod, or at least it should be not be in preset since there are two options to do the migration.

By the way, there is a typo in the migration example: The argument name is time, but the method uses value. I don't know which one is the best

 <DateTimePicker
-  shouldDisableTime={(timeValue, view) => view === 'hours' && timeValue < 12}
+  shouldDisableTime={(time, view) => view === 'hours' && value.hour() < 12}
 />

About rename-private-components and rename-next-components it's feasible to have a codemod, but it will not be that much different from a search and replace.

@LukasTy
Copy link
Member Author

LukasTy commented Jan 26, 2023

About rename-should-disable-time I don't know if we can do a codemod, or at least it should be not be in preset since there are two options to do the migration.

I do think that we should do the migration from shouldDIsableTime to shouldDisableClock as that is safe and shouldn't cause any issues.
But yes, the fact that the new shouldDisableTime is now more flexible should still be made clear 🙈

By the way, there is a typo in the migration example: The argument name is time, but the method uses value. I don't know which one is the best

🤦 I do think that value does sound a bit more correct, just because time.hour() seems a bit strange 🙈

About rename-private-components and rename-next-components it's feasible to have a codemod, but it will not be that much different from a search and replace.

Indeed, those are somewhat pointless as codemods and would probably cover a very small percentage of use-cases anyways. 👌
I do agree that they can be omitted from the package. 👍

@alexfauquette
Copy link
Member

OK, I will do the missing one + fix migration guide 👍

@LukasTy
Copy link
Member Author

LukasTy commented Mar 3, 2023

Closing this one as all the planned codemods for stable release have been added. 👍
If we will need any further improvements or fixes, they can be tackled via separate issues.

@LukasTy LukasTy closed this as completed Mar 3, 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! package: codemod Specific to @mui/codemod umbrella For grouping multiple issues to provide a holistic view v6.x
Projects
None yet
Development

No branches or pull requests

2 participants