diff --git a/docs/data/migration/migration-pickers-v6/migration-pickers-v6.md b/docs/data/migration/migration-pickers-v6/migration-pickers-v6.md index 9f21271e5b9a..1ccc92d08751 100644 --- a/docs/data/migration/migration-pickers-v6/migration-pickers-v6.md +++ b/docs/data/migration/migration-pickers-v6/migration-pickers-v6.md @@ -136,7 +136,7 @@ You can read more about the deprecation of this prop in [v6 migration guide](/x/ /> ``` -### Replace `defaultCalendarMonth` with `referenceDate` +### ✅ Replace `defaultCalendarMonth` with `referenceDate` The deprecated `defaultCalendarMonth` prop has been removed in favor of the more flexible `referenceDate` prop. diff --git a/packages/x-codemod/README.md b/packages/x-codemod/README.md index 4a5bf4f7cc5d..c4c005cc707d 100644 --- a/packages/x-codemod/README.md +++ b/packages/x-codemod/README.md @@ -76,17 +76,26 @@ The corresponding sub-sections are listed below ### Pickers codemods -#### `preset-safe` for pickers v6.0.0 +#### `preset-safe` for pickers v7.0.0 The `preset-safe` codemods for pickers. ```bash -npx @mui/x-codemod v6.0.0/pickers/preset-safe +npx @mui/x-codemod v7.0.0/pickers/preset-safe ``` The list includes these transformers -NO CODEMOD ADDED YET +- [`rename-default-calendar-month-to-reference-date`](#rename-default-calendar-month-to-reference-date) + +#### `rename-default-calendar-month-to-reference-date` + +Replace the `defaultCalendarMonth` prop with the `referenceDate` prop. + +```diff +- +``` ### Data grid codemods @@ -95,7 +104,7 @@ NO CODEMOD ADDED YET The `preset-safe` codemods for data grid. ```bash -npx @mui/x-codemod v6.0.0/data-grid/preset-safe +npx @mui/x-codemod v7.0.0/data-grid/preset-safe ``` The list includes these transformers diff --git a/packages/x-codemod/src/v7.0.0/pickers/preset-safe/index.ts b/packages/x-codemod/src/v7.0.0/pickers/preset-safe/index.ts index 4d9fb737ea9c..c1fb08fc7c2a 100644 --- a/packages/x-codemod/src/v7.0.0/pickers/preset-safe/index.ts +++ b/packages/x-codemod/src/v7.0.0/pickers/preset-safe/index.ts @@ -1,9 +1,11 @@ import transformRenameComponentsToSlots from '../../../v6.0.0/pickers/rename-components-to-slots'; +import transformRenameDefaultCalendarMonthToReferenceDate from '../rename-default-calendar-month-to-reference-date'; import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { file.source = transformRenameComponentsToSlots(file, api, options); + file.source = transformRenameDefaultCalendarMonthToReferenceDate(file, api, options); return file.source; } diff --git a/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/actual.spec.js b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/actual.spec.js new file mode 100644 index 000000000000..a2682a8607e4 --- /dev/null +++ b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/actual.spec.js @@ -0,0 +1,16 @@ +<> + + + + + + + + + + + + + + +; diff --git a/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/expected.spec.js b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/expected.spec.js new file mode 100644 index 000000000000..a95070957b1f --- /dev/null +++ b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/expected.spec.js @@ -0,0 +1,16 @@ +<> + + + + + + + + + + + + + + +; diff --git a/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/index.ts b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/index.ts new file mode 100644 index 000000000000..fe769579e65d --- /dev/null +++ b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/index.ts @@ -0,0 +1,31 @@ +import renameProps from '../../../util/renameProps'; +import type { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; + +export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { + const j = api.jscodeshift; + const root = j(file.source); + + const printOptions = options.printOptions; + + return renameProps({ + root, + componentNames: [ + 'DateCalendar', + 'DatePicker', + 'DateRangeCalendar', + 'DateRangePicker', + 'DateTimePicker', + 'DesktopDatePicker', + 'DesktopDateRangePicker', + 'DesktopDateTimePicker', + 'MobileDatePicker', + 'MobileDateRangePicker', + 'MobileDateTimePicker', + 'StaticDatePicker', + 'StaticDateRangePicker', + 'StaticDateTimePicker', + ], + props: { defaultCalendarMonth: 'referenceDate' }, + j, + }).toSource(printOptions); +} diff --git a/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/rename-default-calendar-month-to-reference-date.test.ts b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/rename-default-calendar-month-to-reference-date.test.ts new file mode 100644 index 000000000000..859a66b2f1c8 --- /dev/null +++ b/packages/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/rename-default-calendar-month-to-reference-date.test.ts @@ -0,0 +1,27 @@ +import path from 'path'; +import { expect } from 'chai'; +import jscodeshift from 'jscodeshift'; +import transform from '.'; +import readFile from '../../../util/readFile'; + +function read(fileName) { + return readFile(path.join(__dirname, fileName)); +} + +describe('v7.0.0/pickers', () => { + describe('rename-default-calendar-month-to-reference-date', () => { + it('transforms props as needed', () => { + const actual = transform({ source: read('./actual.spec.js') }, { jscodeshift }, {}); + + const expected = read('./expected.spec.js'); + expect(actual).to.equal(expected, 'The transformed version should be correct'); + }); + + it('should be idempotent', () => { + const actual = transform({ source: read('./expected.spec.js') }, { jscodeshift }, {}); + + const expected = read('./expected.spec.js'); + expect(actual).to.equal(expected, 'The transformed version should be correct'); + }); + }); +});