@mui/x-codemod 6.0.0-alpha.9 → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +399 -4
- package/codemod.js +1 -1
- package/package.json +4 -4
- package/util/addComponentsSlots.js +67 -0
- package/util/removeProps.js +22 -0
- package/util/renameComponentsSlots.js +31 -0
- package/util/renameProps.js +7 -8
- package/v6.0.0/component-rename-prop/index.js +3 -2
- package/v6.0.0/data-grid/column-menu-components-rename/index.js +50 -0
- package/v6.0.0/data-grid/preset-safe/index.js +20 -0
- package/v6.0.0/data-grid/remove-disableExtendRowFullWidth-prop/index.js +24 -0
- package/v6.0.0/data-grid/rename-rowsPerPageOptions-prop/index.js +26 -0
- package/v6.0.0/data-grid/rename-selectors-and-events/index.js +39 -0
- package/v6.0.0/data-grid/row-selection-props-rename/index.js +32 -0
- package/v6.0.0/pickers/adapter-change-import/index.js +56 -0
- package/v6.0.0/{localization-provider-rename-locale → pickers/localization-provider-rename-locale}/index.js +4 -3
- package/v6.0.0/pickers/migrate-to-components-componentsProps/index.js +101 -0
- package/v6.0.0/pickers/preset-safe/index.js +32 -0
- package/v6.0.0/pickers/rename-components-to-slots/index.js +62 -0
- package/v6.0.0/pickers/rename-should-disable-time/index.js +39 -0
- package/v6.0.0/pickers/replace-arrows-button-slot/index.js +41 -0
- package/v6.0.0/pickers/replace-tabs-props/index.js +53 -0
- package/v6.0.0/pickers/replace-toolbar-props-by-slot/index.js +69 -0
- package/v6.0.0/pickers/text-props-to-localeText/index.js +101 -0
- package/v6.0.0/pickers/view-components-rename/index.js +83 -0
- package/v6.0.0/pickers/view-components-rename-value-prop/index.js +22 -0
- package/v6.0.0/preset-safe/index.js +4 -2
package/README.md
CHANGED
|
@@ -62,19 +62,94 @@ npx @mui/x-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":
|
|
|
62
62
|
|
|
63
63
|
#### 🚀 `preset-safe`
|
|
64
64
|
|
|
65
|
-
A combination of all important transformers for migrating v5 to v6. ⚠️ This codemod should be run only once.
|
|
65
|
+
A combination of all important transformers for migrating v5 to v6. ⚠️ This codemod should be run only once. It runs codemods for both Data Grid and Date and Time Pickers packages. To run codemods for a specific package, refer to the respective section.
|
|
66
66
|
|
|
67
67
|
```sh
|
|
68
68
|
npx @mui/x-codemod v6.0.0/preset-safe <path|folder>
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
The corresponding sub-sections are listed below
|
|
72
|
+
|
|
73
|
+
- [`preset-safe-for-pickers`](#preset-safe-for-pickers)
|
|
74
|
+
- [`preset-safe-for-data-grid`](#preset-safe-for-data-grid)
|
|
75
|
+
|
|
76
|
+
### Pickers codemods
|
|
77
|
+
|
|
78
|
+
#### `preset-safe` for pickers
|
|
79
|
+
|
|
80
|
+
The `preset-safe` codemods for pickers.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npx @mui/x-codemod v6.0.0/pickers/preset-safe <path|folder>
|
|
84
|
+
```
|
|
85
|
+
|
|
71
86
|
The list includes these transformers
|
|
72
87
|
|
|
88
|
+
- [`adapter-change-import`](#adapter-change-import)
|
|
89
|
+
- [`view-components-rename`](#view-components-rename)
|
|
90
|
+
- [`view-components-rename-value-prop`](#view-components-rename-value-prop)
|
|
73
91
|
- [`localization-provider-rename-locale`](#localization-provider-rename-locale)
|
|
92
|
+
- [`text-props-to-localeText`](#text-props-to-localeText)
|
|
93
|
+
- [`replace-tabs-props`](#replace-tabs-props)
|
|
94
|
+
- [`replace-toolbar-props-by-slot`](#replace-toolbar-props-by-slot)
|
|
95
|
+
- [`migrate-to-components-componentsProps`](#migrate-to-components-componentsProps)
|
|
96
|
+
- [`replace-arrows-button-slot`](#replace-arrows-button-slot)
|
|
97
|
+
- [`rename-should-disable-time`](#rename-should-disable-time)
|
|
98
|
+
|
|
99
|
+
#### `adapter-change-import`
|
|
100
|
+
|
|
101
|
+
Import the adapters from `@mui/x-date-pickers` instead of `@date-io`.
|
|
102
|
+
|
|
103
|
+
```diff
|
|
104
|
+
-import AdapterJalaali from '@date-io/jalaali';
|
|
105
|
+
+import { AdapterMomentJalaali } from '@mui/x-date-pickers/AdapterMomentJalaali';
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### `view-components-rename`
|
|
109
|
+
|
|
110
|
+
Renames the view components.
|
|
111
|
+
|
|
112
|
+
```diff
|
|
113
|
+
-<CalendarPicker {...props} />
|
|
114
|
+
+<DateCalendar {...props} />
|
|
115
|
+
|
|
116
|
+
-<DayPicker {...props} />
|
|
117
|
+
+<DayCalendar {...props} />
|
|
118
|
+
|
|
119
|
+
-<CalendarPickerSkeleton {...props} />
|
|
120
|
+
+<DayCalendarSkeleton {...props} />
|
|
121
|
+
|
|
122
|
+
-<MonthPicker {...props} />
|
|
123
|
+
+<MonthCalendar {...props} />
|
|
124
|
+
|
|
125
|
+
-<YearPicker {...props} />
|
|
126
|
+
+<YearCalendar {...props} />
|
|
127
|
+
|
|
128
|
+
-<ClockPicker {...props} />
|
|
129
|
+
+<TimeClock {...props} />
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### `view-components-rename-value-prop`
|
|
133
|
+
|
|
134
|
+
Renames the `date` prop of the view components into `value`.
|
|
135
|
+
|
|
136
|
+
```diff
|
|
137
|
+
-<MonthPicker date={dayjs()} />
|
|
138
|
+
+<MonthCalendar value={dayjs()} />
|
|
139
|
+
|
|
140
|
+
-<YearPicker date={dayjs()} />
|
|
141
|
+
+<YearCalendar value={dayjs()} />
|
|
142
|
+
|
|
143
|
+
-<ClockPicker date={dayjs()} />
|
|
144
|
+
+<TimeClock value={dayjs()} />
|
|
145
|
+
|
|
146
|
+
-<CalendarPicker date={dayjs()} />
|
|
147
|
+
+<DateCalendar value={dayjs()} />
|
|
148
|
+
```
|
|
74
149
|
|
|
75
150
|
#### `localization-provider-rename-locale`
|
|
76
151
|
|
|
77
|
-
Renames `locale`
|
|
152
|
+
Renames the `locale` prop of the `LocalizationProvider` component into `adapterLocale`.
|
|
78
153
|
|
|
79
154
|
```diff
|
|
80
155
|
<LocalizationProvider
|
|
@@ -88,7 +163,327 @@ Renames `locale` into `adapterLocale` (or `LocalizationProvider`)
|
|
|
88
163
|
```
|
|
89
164
|
|
|
90
165
|
```sh
|
|
91
|
-
npx @mui/x-codemod v6.0.0/localization-provider-rename-locale <path>
|
|
166
|
+
npx @mui/x-codemod v6.0.0/pickers/localization-provider-rename-locale <path>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### `text-props-to-localeText`
|
|
170
|
+
|
|
171
|
+
Replace props used for localization such as `cancelText` to their corresponding `localeText` key on all the Date and Time Pickers components.
|
|
172
|
+
|
|
173
|
+
```diff
|
|
174
|
+
<DatePicker
|
|
175
|
+
- cancelText="Cancelar"
|
|
176
|
+
+ localeText={{
|
|
177
|
+
+ cancelButtonLabel: "Cancelar"
|
|
178
|
+
+ }}
|
|
179
|
+
/>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```sh
|
|
183
|
+
npx @mui/x-codemod v6.0.0/pickers/text-props-to-localeText <path>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
If you were always using the same text value in all your components, consider moving those translation from the component to the `LocalizationProvider` by hand.
|
|
187
|
+
|
|
188
|
+
```diff
|
|
189
|
+
<LocalizationProvider
|
|
190
|
+
dateAdapter={AdapterDayjs}
|
|
191
|
+
+ localeText={{ cancelButtonLabel: "Cancelar" }}
|
|
192
|
+
>
|
|
193
|
+
<DatePicker
|
|
194
|
+
- localeText={{ cancelButtonLabel: "Cancelar" }}
|
|
195
|
+
/>
|
|
196
|
+
<DateTimePicker
|
|
197
|
+
- localeText={{ cancelButtonLabel: "Cancelar" }}
|
|
198
|
+
/>
|
|
199
|
+
</LocalizationProvider>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
You can find more details about Date and Time breaking changes in [the migration guide](https://next.mui.com/x/migration/migration-pickers-v5/).
|
|
203
|
+
|
|
204
|
+
#### `replace-tabs-props`
|
|
205
|
+
|
|
206
|
+
Replace props used for `Tabs` in DateTime pickers by `componentsProps.tabs` properties.
|
|
207
|
+
|
|
208
|
+
```diff
|
|
209
|
+
<DateTimePicker
|
|
210
|
+
- hideTabs={false}
|
|
211
|
+
- dateRangeIcon={<LightModeIcon />}
|
|
212
|
+
- timeIcon={<AcUnitIcon />}
|
|
213
|
+
+ componentsProps={{
|
|
214
|
+
+ tabs: {
|
|
215
|
+
+ hidden: false,
|
|
216
|
+
+ dateIcon: <LightModeIcon />,
|
|
217
|
+
+ timeIcon: <AcUnitIcon />,
|
|
218
|
+
+ }
|
|
219
|
+
+ }}
|
|
220
|
+
/>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
npx @mui/x-codemod v6.0.0/pickers/replace-tabs-props <path>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### `replace-toolbar-props-by-slot`
|
|
228
|
+
|
|
229
|
+
Replace props used to customize the `Toolbar` in pickers by slots properties and `localeText`.
|
|
230
|
+
|
|
231
|
+
```diff
|
|
232
|
+
<DatePicker
|
|
233
|
+
- ToolbarComponent={MyToolbar}
|
|
234
|
+
+ components={{ Toolbar: MyToolbar }}
|
|
235
|
+
- toolbarPlaceholder="__"
|
|
236
|
+
- toolbarFormat="DD / MM / YYYY"
|
|
237
|
+
- showToolbar
|
|
238
|
+
+ componentsProps={{
|
|
239
|
+
+ toolbar: {
|
|
240
|
+
+ toolbarPlaceholder: "__",
|
|
241
|
+
+ toolbarFormat: "DD / MM / YYYY",
|
|
242
|
+
+ hidden: false,
|
|
243
|
+
+ }
|
|
244
|
+
+ }}
|
|
245
|
+
- toolbarTitle="Title"
|
|
246
|
+
+ localeText={{ toolbarTitle: "Title" }}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
```sh
|
|
250
|
+
npx @mui/x-codemod v6.0.0/pickers/replace-toolbar-props-by-slot <path>
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### `migrate-to-components-componentsProps`
|
|
254
|
+
|
|
255
|
+
Replace customization props by their equivalent `components` and `componentsProps` properties.
|
|
256
|
+
|
|
257
|
+
```diff
|
|
258
|
+
<DatePicker
|
|
259
|
+
- PopperProps={{ onClick: handleClick }}
|
|
260
|
+
+ componentsProps={{ popper: { onClick: handleClick }}}
|
|
261
|
+
/>
|
|
262
|
+
|
|
263
|
+
<DatePicker
|
|
264
|
+
- TransitionComponent={Fade}
|
|
265
|
+
+ components={{ DesktopTransition: Fade }}
|
|
266
|
+
/>
|
|
267
|
+
|
|
268
|
+
<DatePicker
|
|
269
|
+
- DialogProps={{ backgroundColor: 'red' }}
|
|
270
|
+
+ componentsProps={{ dialog: { backgroundColor: 'red' }}}
|
|
271
|
+
/>
|
|
272
|
+
|
|
273
|
+
<DatePicker
|
|
274
|
+
- PaperProps={{ backgroundColor: 'red' }}
|
|
275
|
+
+ componentsProps={{ desktopPaper: { backgroundColor: 'red' }}}
|
|
276
|
+
/>
|
|
277
|
+
|
|
278
|
+
<DatePicker
|
|
279
|
+
- TrapFocusProps={{ isEnabled: () => false }}
|
|
280
|
+
+ componentsProps={{ desktopTrapFocus: { isEnabled: () => false }}}
|
|
281
|
+
/>
|
|
282
|
+
|
|
283
|
+
<DatePicker
|
|
284
|
+
- InputProps={{ color: 'primary' }}
|
|
285
|
+
+ componentsProps={{ textField: { InputProps: { color: 'primary' }}}}
|
|
286
|
+
/>
|
|
287
|
+
|
|
288
|
+
<DatePicker
|
|
289
|
+
- InputAdornmentProps={{ position: 'start' }}
|
|
290
|
+
+ componentsProps={{ inputAdornment: { position: 'start' }}}
|
|
291
|
+
/>
|
|
292
|
+
|
|
293
|
+
<DatePicker
|
|
294
|
+
- OpenPickerButtonProps={{ ref: buttonRef }}
|
|
295
|
+
+ componentsProps={{ openPickerButton: { ref: buttonRef }}}
|
|
296
|
+
/>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
```sh
|
|
300
|
+
npx @mui/x-codemod v6.0.0/pickers/migrate-to-components-componentsProps <path>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### `replace-arrows-button-slot`
|
|
304
|
+
|
|
305
|
+
Replace `LeftArrowButton` and `RightArrowButton` slots for navigation buttons by `PreviousIconButton` and `NextIconButton`.
|
|
306
|
+
|
|
307
|
+
```diff
|
|
308
|
+
<DatePicker
|
|
309
|
+
components={{
|
|
310
|
+
- LeftArrowButton: CustomButton,
|
|
311
|
+
+ PreviousIconButton: CustomButton,
|
|
312
|
+
- RightArrowButton: CustomButton,
|
|
313
|
+
+ NextIconButton: CustomButton,
|
|
314
|
+
}}
|
|
315
|
+
|
|
316
|
+
componentsProps={{
|
|
317
|
+
- leftArrowButton: {},
|
|
318
|
+
+ previousIconButton: {},
|
|
319
|
+
- rightArrowButton: {},
|
|
320
|
+
+ nextIconButton: {},
|
|
321
|
+
}}
|
|
322
|
+
/>
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
```sh
|
|
326
|
+
npx @mui/x-codemod v6.0.0/pickers/replace-arrows-button-slot <path>
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
#### `rename-should-disable-time`
|
|
330
|
+
|
|
331
|
+
Replace `shouldDisableTime` by `shouldDisableClock`.
|
|
332
|
+
|
|
333
|
+
```diff
|
|
334
|
+
<DateTimePicker
|
|
335
|
+
- shouldDisableTime={(timeValue, view) => view === 'hours' && timeValue < 12}
|
|
336
|
+
+ shouldDisableClock={(timeValue, view) => view === 'hours' && timeValue < 12}
|
|
337
|
+
/>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
```sh
|
|
341
|
+
npx @mui/x-codemod v6.0.0/pickers/rename-should-disable-time <path>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
#### `rename-components-to-slots`
|
|
345
|
+
|
|
346
|
+
Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
|
|
347
|
+
|
|
348
|
+
This change only affects pickers components.
|
|
349
|
+
|
|
350
|
+
```diff
|
|
351
|
+
<DatePicker
|
|
352
|
+
- components={{ Toolbar: CustomToolbar }}
|
|
353
|
+
+ slots={{ toolbar: CustomToolbar }}
|
|
354
|
+
- componentsProps={{ actionBar: { actions: ['clear'] } }}
|
|
355
|
+
+ slotProps={{ actionBar: { actions: ['clear'] } }}
|
|
356
|
+
/>;
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
npx @mui/x-codemod v6.0.0/pickers/rename-components-to-slots <path>
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Data grid codemods
|
|
364
|
+
|
|
365
|
+
#### `preset-safe` for data grid
|
|
366
|
+
|
|
367
|
+
The `preset-safe` codemods for data grid.
|
|
368
|
+
|
|
369
|
+
```sh
|
|
370
|
+
npx @mui/x-codemod v6.0.0/data-grid/preset-safe <path|folder>
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
The list includes these transformers
|
|
374
|
+
|
|
375
|
+
- [`column-menu-components-rename`](#column-menu-components-rename)
|
|
376
|
+
- [`row-selection-props-rename`](#row-selection-props-rename)
|
|
377
|
+
- [`rename-rowsPerPageOptions-prop`](#rename-rowsPerPageOptions-prop)
|
|
378
|
+
- [`remove-disableExtendRowFullWidth-prop`](#remove-disableExtendRowFullWidth-prop)
|
|
379
|
+
- [`rename-selectors-and-events`](#rename-selectors-and-events)
|
|
380
|
+
|
|
381
|
+
#### `column-menu-components-rename`
|
|
382
|
+
|
|
383
|
+
Replace column menu items that have been renamed.
|
|
384
|
+
|
|
385
|
+
```diff
|
|
386
|
+
<CustomColumnMenu>
|
|
387
|
+
- <GridFilterMenuItem column={column} onClick={hideMenu} />
|
|
388
|
+
+ <GridColumnMenuFilterItem colDef={column} onClick={hideMenu} />
|
|
389
|
+
- <HideGridColMenuItem column={column} onClick={hideMenu} />
|
|
390
|
+
+ <GridColumnMenuHideItem colDef={column} onClick={hideMenu} />
|
|
391
|
+
- <GridColumnsMenuItem column={column} onClick={hideMenu} />
|
|
392
|
+
+ <GridColumnMenuColumnsItem colDef={column} onClick={hideMenu} />
|
|
393
|
+
- <SortGridMenuItems column={column} onClick={hideMenu} />
|
|
394
|
+
+ <GridColumnMenuSortItem colDef={column} onClick={hideMenu} />
|
|
395
|
+
- <GridColumnPinningMenuItems column={column} onClick={hideMenu} />
|
|
396
|
+
+ <GridColumnMenuPinningItem colDef={column} onClick={hideMenu} />
|
|
397
|
+
</CustomColumnMenu>
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
```sh
|
|
401
|
+
npx @mui/x-codemod v6.0.0/data-grid/column-menu-components-rename <path>
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
If you are using `GridRowGroupingColumnMenuItems` and `GridRowGroupableColumnMenuItems` for grouping, consider fixing them manually as these imports are replaced by `GridColumnMenuGroupingItem` and may require some extra work to port.
|
|
405
|
+
|
|
406
|
+
#### `row-selection-props-rename`
|
|
407
|
+
|
|
408
|
+
Data grid props that have been renamed.
|
|
409
|
+
|
|
410
|
+
```diff
|
|
411
|
+
<DataGrid
|
|
412
|
+
- selectionModel={model}
|
|
413
|
+
+ rowSelectionModel={model}
|
|
414
|
+
- onSelectionModelChange={handler}
|
|
415
|
+
+ onRowSelectionModelChange={handler}
|
|
416
|
+
- disableSelectionOnClick
|
|
417
|
+
+ disableRowSelectionOnClick
|
|
418
|
+
- disableMultipleSelection
|
|
419
|
+
+ disableMultipleRowSelection
|
|
420
|
+
- showCellRightBorder
|
|
421
|
+
+ showCellVerticalBorder
|
|
422
|
+
- showColumnRightBorder
|
|
423
|
+
+ showColumnVerticalBorder
|
|
424
|
+
/>
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
```sh
|
|
428
|
+
npx @mui/x-codemod v6.0.0/data-grid/row-selection-props-rename <path>
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
#### `rename-rowsPerPageOptions-prop`
|
|
432
|
+
|
|
433
|
+
Rename `rowsPerPageOptions` prop to `pageSizeOptions`.
|
|
434
|
+
|
|
435
|
+
```diff
|
|
436
|
+
<DataGrid
|
|
437
|
+
- rowsPerPageOptions={[5, 10, 20]}
|
|
438
|
+
+ pageSizeOptions={[5, 10, 20]}
|
|
439
|
+
/>
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
```sh
|
|
443
|
+
npx @mui/x-codemod v6.0.0/data-grid/rename-rowsPerPageOptions-prop <path>
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
#### `remove-disableExtendRowFullWidth-prop`
|
|
447
|
+
|
|
448
|
+
Remove `disableExtendRowFullWidth` prop which is no longer supported.
|
|
449
|
+
|
|
450
|
+
```diff
|
|
451
|
+
<DataGrid
|
|
452
|
+
- disableExtendRowFullWidth
|
|
453
|
+
/>
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
```sh
|
|
457
|
+
npx @mui/x-codemod v6.0.0/data-grid/remove-disableExtendRowFullWidth-prop <path>
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
#### `rename-selectors-and-events`
|
|
461
|
+
|
|
462
|
+
Rename selectors and events.
|
|
463
|
+
|
|
464
|
+
```diff
|
|
465
|
+
function App() {
|
|
466
|
+
- useGridApiEventHandler('selectionChange', handleEvent);
|
|
467
|
+
- apiRef.current.subscribeEvent('selectionChange', handleEvent);
|
|
468
|
+
- const selection = useGridSelector(apiRef, gridSelectionStateSelector);
|
|
469
|
+
- const sortedRowIds = useGridSelector(apiRef, gridVisibleSortedRowIdsSelector);
|
|
470
|
+
- const sortedRowEntries = useGridSelector(apiRef, gridVisibleSortedRowEntriesSelector);
|
|
471
|
+
- const rowCount = useGridSelector(apiRef, gridVisibleRowCountSelector);
|
|
472
|
+
- const sortedTopLevelRowEntries = useGridSelector(apiRef, gridVisibleSortedTopLevelRowEntriesSelector);
|
|
473
|
+
- const topLevelRowCount = useGridSelector(apiRef, gridVisibleTopLevelRowCountSelector);
|
|
474
|
+
+ useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
475
|
+
+ apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
476
|
+
+ const selection = useGridSelector(apiRef, gridRowSelectionStateSelector);
|
|
477
|
+
+ const sortedRowIds = useGridSelector(apiRef, gridExpandedSortedRowIdsSelector);
|
|
478
|
+
+ const sortedRowEntries = useGridSelector(apiRef, gridExpandedSortedRowEntriesSelector);
|
|
479
|
+
+ const rowCount = useGridSelector(apiRef, gridExpandedRowCountSelector);
|
|
480
|
+
+ const sortedTopLevelRowEntries = useGridSelector(apiRef, gridFilteredSortedTopLevelRowEntriesSelector);
|
|
481
|
+
+ const topLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
```sh
|
|
486
|
+
npx @mui/x-codemod v6.0.0/data-grid/rename-selectors-and-events <path>
|
|
92
487
|
```
|
|
93
488
|
|
|
94
|
-
You can find more details about
|
|
489
|
+
You can find more details about Data Grid breaking change in [the migration guide](https://next.mui.com/x/migration/migration-data-grid-v5/).
|
package/codemod.js
CHANGED
|
@@ -57,7 +57,6 @@ function run(argv) {
|
|
|
57
57
|
_yargs.default.command({
|
|
58
58
|
command: '$0 <codemod> <paths...>',
|
|
59
59
|
describe: 'Applies a `@mui/x-codemod` to the specified paths',
|
|
60
|
-
// @ts-expect-error
|
|
61
60
|
builder: command => {
|
|
62
61
|
return command.positional('codemod', {
|
|
63
62
|
description: 'The name of the codemod',
|
|
@@ -76,5 +75,6 @@ _yargs.default.command({
|
|
|
76
75
|
type: 'array'
|
|
77
76
|
});
|
|
78
77
|
},
|
|
78
|
+
// @ts-expect-error
|
|
79
79
|
handler: run
|
|
80
80
|
}).scriptName('npx @mui/x-codemod').example('$0 v6.0.0/localization-provider-rename-locale src', 'Run "localization-provider-rename-locale" codemod on "src" path').example('$0 v6.0.0/component-rename-prop src -- --component=DataGrid --from=prop --to=newProp', 'Run "component-rename-prop" codemod in "src" path on "DataGrid" component with custom "from" and "to" arguments').help().parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-codemod",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-beta.1",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"url": "https://opencollective.com/mui"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@babel/core": "^7.20.
|
|
35
|
-
"@babel/runtime": "^7.20.
|
|
36
|
-
"@babel/traverse": "^7.20.
|
|
34
|
+
"@babel/core": "^7.20.12",
|
|
35
|
+
"@babel/runtime": "^7.20.7",
|
|
36
|
+
"@babel/traverse": "^7.20.12",
|
|
37
37
|
"jscodeshift": "0.13.1",
|
|
38
38
|
"jscodeshift-add-imports": "^1.0.10",
|
|
39
39
|
"yargs": "^17.6.2"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformNestedProp = exports.addItemToObject = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Recusive function that:
|
|
9
|
+
* Return a jscodeshift object with `value` associated to path.
|
|
10
|
+
* The path can be such as 'tabs.hidden' which will return `{ tabs: { hidden: value } }`.
|
|
11
|
+
* If object is not null, path/value will be added respecting the other properties of the object.
|
|
12
|
+
*/
|
|
13
|
+
const addItemToObject = (path, value, object, j) => {
|
|
14
|
+
const splitedPath = path.split('.');
|
|
15
|
+
|
|
16
|
+
// Final case where we have to add the property to the object.
|
|
17
|
+
if (splitedPath.length === 1) {
|
|
18
|
+
const propertyToAdd = j.objectProperty(j.identifier(path), value);
|
|
19
|
+
if (object === null) {
|
|
20
|
+
return j.objectExpression([propertyToAdd]);
|
|
21
|
+
}
|
|
22
|
+
return j.objectExpression([...(object.properties ?? []).filter(property => property.key.name !== path), propertyToAdd]);
|
|
23
|
+
}
|
|
24
|
+
const remainingPath = splitedPath.slice(1).join('.');
|
|
25
|
+
const targetKey = splitedPath[0];
|
|
26
|
+
if (object === null) {
|
|
27
|
+
// Simplest case, no object to take into consideration
|
|
28
|
+
const propertyToAdd = j.objectProperty(j.identifier(targetKey), addItemToObject(remainingPath, value, null, j));
|
|
29
|
+
return j.objectExpression([propertyToAdd]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Look if the object we got already contains the property we have to use.
|
|
33
|
+
const correspondingObject = (object.properties ?? []).find(property => property.key.name === targetKey);
|
|
34
|
+
const propertyToAdd = j.objectProperty(j.identifier(targetKey),
|
|
35
|
+
// Here we use recursion to mix the new value with the current one
|
|
36
|
+
addItemToObject(remainingPath, value, correspondingObject?.value ?? null, j));
|
|
37
|
+
return j.objectExpression([...(object.properties ?? []).filter(property => property.key.name !== targetKey), propertyToAdd]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param elementPath jscodshift path of the element
|
|
43
|
+
* @param propName the name of the prop to edit (`'componentsProps'` for example)
|
|
44
|
+
* @param nestedPath path of the nested object keys with '.' to separate. ('tabs.hidden' for example)
|
|
45
|
+
* @param value the jscodeshift value to associate to the key
|
|
46
|
+
* @param j jscodeshift
|
|
47
|
+
*/
|
|
48
|
+
exports.addItemToObject = addItemToObject;
|
|
49
|
+
const transformNestedProp = (elementPath, propName, nestedPath, value, j) => {
|
|
50
|
+
const initialAttribute = elementPath.value.openingElement.attributes?.find(attribute => attribute.name.name === propName);
|
|
51
|
+
// the object in JSX element
|
|
52
|
+
const initialValue = initialAttribute?.value.expression;
|
|
53
|
+
|
|
54
|
+
// Add the value
|
|
55
|
+
const withNewValues = addItemToObject(nestedPath, value, initialValue ?? null, j);
|
|
56
|
+
|
|
57
|
+
// Create a new component with the prop added
|
|
58
|
+
const newComponent = j.jsxElement(j.jsxOpeningElement(elementPath.node.openingElement.name, [...(elementPath.node.openingElement.attributes ?? []).filter(attribute => attribute.name.name !== propName),
|
|
59
|
+
// build and insert our new prop
|
|
60
|
+
j.jsxAttribute(j.jsxIdentifier(propName), j.jsxExpressionContainer(withNewValues))]), elementPath.node.closingElement, elementPath.node.children);
|
|
61
|
+
newComponent.openingElement.selfClosing = elementPath.node.closingElement === null;
|
|
62
|
+
newComponent.selfClosing = elementPath.node.closingElement === null;
|
|
63
|
+
|
|
64
|
+
// Replace our original component with our modified one
|
|
65
|
+
j(elementPath).replaceWith(newComponent);
|
|
66
|
+
};
|
|
67
|
+
exports.transformNestedProp = transformNestedProp;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = removeProps;
|
|
7
|
+
function removeProps({
|
|
8
|
+
root,
|
|
9
|
+
componentNames,
|
|
10
|
+
props,
|
|
11
|
+
j
|
|
12
|
+
}) {
|
|
13
|
+
return root.find(j.JSXElement).filter(path => {
|
|
14
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
15
|
+
}).find(j.JSXAttribute).filter(attribute => props.includes(attribute.node.name.name)).forEach(attribute => {
|
|
16
|
+
// Only remove props from components in componentNames. Not nested ones.
|
|
17
|
+
const attributeParent = attribute.parentPath.parentPath;
|
|
18
|
+
if (attributeParent.value.type === 'JSXOpeningElement' && componentNames.includes(attributeParent.value.name.name)) {
|
|
19
|
+
j(attribute).remove();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = renameComponentsSlots;
|
|
7
|
+
const lowerCase = key => `${key.slice(0, 1).toLowerCase()}${key.slice(1)}`;
|
|
8
|
+
const getSlotsTranslation = translations => {
|
|
9
|
+
const lowercasedTranslation = {};
|
|
10
|
+
Object.entries(translations).forEach(([key, value]) => {
|
|
11
|
+
lowercasedTranslation[lowerCase(key)] = lowerCase(value);
|
|
12
|
+
});
|
|
13
|
+
return lowercasedTranslation;
|
|
14
|
+
};
|
|
15
|
+
function renameComponentsSlots({
|
|
16
|
+
root,
|
|
17
|
+
componentNames,
|
|
18
|
+
translation,
|
|
19
|
+
j
|
|
20
|
+
}) {
|
|
21
|
+
return root.find(j.JSXElement).filter(path => {
|
|
22
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
23
|
+
}).find(j.JSXAttribute).filter(attribute => ['components', 'componentsProps', 'slots', 'slotProps'].includes(attribute.node.name.name)).forEach(attribute => {
|
|
24
|
+
const usedTranslation = attribute.node.name.name === 'components' ? translation : getSlotsTranslation(translation);
|
|
25
|
+
j(attribute).find(j.Property).forEach(property => {
|
|
26
|
+
if (property.value.key.type === 'Identifier' && usedTranslation[property.value.key.name] !== undefined) {
|
|
27
|
+
property.value.key.name = usedTranslation[property.value.key.name];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
package/util/renameProps.js
CHANGED
|
@@ -6,14 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = renameProps;
|
|
7
7
|
function renameProps({
|
|
8
8
|
root,
|
|
9
|
-
|
|
10
|
-
props
|
|
9
|
+
componentNames,
|
|
10
|
+
props,
|
|
11
|
+
j
|
|
11
12
|
}) {
|
|
12
|
-
return root.
|
|
13
|
-
path.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
});
|
|
13
|
+
return root.find(j.JSXElement).filter(path => {
|
|
14
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
15
|
+
}).find(j.JSXAttribute).filter(attribute => Object.keys(props).includes(attribute.node.name.name)).forEach(attribute => {
|
|
16
|
+
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(props[attribute.node.name.name]), attribute.node.value));
|
|
18
17
|
});
|
|
19
18
|
}
|
|
@@ -12,9 +12,10 @@ function transformer(file, api, options) {
|
|
|
12
12
|
const printOptions = options.printOptions;
|
|
13
13
|
return (0, _renameProps.default)({
|
|
14
14
|
root,
|
|
15
|
-
|
|
15
|
+
componentNames: [options.component],
|
|
16
16
|
props: {
|
|
17
17
|
[options.from]: options.to
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
j
|
|
19
20
|
}).toSource(printOptions);
|
|
20
21
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
var _renameProps = _interopRequireDefault(require("../../../util/renameProps"));
|
|
9
|
+
const VARIABLES = {
|
|
10
|
+
GridFilterMenuItem: 'GridColumnMenuFilterItem',
|
|
11
|
+
HideGridColMenuItem: 'GridColumnMenuHideItem',
|
|
12
|
+
GridColumnsMenuItem: 'GridColumnMenuColumnsItem',
|
|
13
|
+
SortGridMenuItems: 'GridColumnMenuSortItem',
|
|
14
|
+
GridColumnPinningMenuItems: 'GridColumnMenuPinningItem',
|
|
15
|
+
GridAggregationColumnMenuItem: 'GridColumnMenuAggregationItem',
|
|
16
|
+
GridFilterItemProps: 'GridColumnMenuItemProps'
|
|
17
|
+
};
|
|
18
|
+
const PACKAGE_REGEXP = /@mui\/x-data-grid(-pro|-premium)?/;
|
|
19
|
+
const matchImport = path => (path.node.source.value?.toString() ?? '').match(PACKAGE_REGEXP);
|
|
20
|
+
function transformer(file, api, options) {
|
|
21
|
+
const j = api.jscodeshift;
|
|
22
|
+
const root = j(file.source);
|
|
23
|
+
const printOptions = options.printOptions || {
|
|
24
|
+
quote: 'single',
|
|
25
|
+
trailingComma: true
|
|
26
|
+
};
|
|
27
|
+
const matchingImports = root.find(j.ImportDeclaration).filter(path => !!matchImport(path));
|
|
28
|
+
|
|
29
|
+
// Rename the import specifiers
|
|
30
|
+
// - import { GridFilterMenuItem } from '@mui/x-data-grid'
|
|
31
|
+
// + import { GridColumnMenuFilterItem } from '@mui/x-data-grid'
|
|
32
|
+
matchingImports.find(j.ImportSpecifier).filter(path => !!VARIABLES[path.node.imported.name]).replaceWith(path => j.importSpecifier(j.identifier(VARIABLES[path.node.imported.name])));
|
|
33
|
+
|
|
34
|
+
// Rename the import usage
|
|
35
|
+
// - <GridFilterMenuItem />
|
|
36
|
+
// + <GridColumnMenuFilterItem />
|
|
37
|
+
root.find(j.Identifier).filter(path => !!VARIABLES[path.node.name]).replaceWith(path => j.identifier(VARIABLES[path.node.name]));
|
|
38
|
+
|
|
39
|
+
// Rename `column` prop to `colDef`
|
|
40
|
+
// - <GridFilterMenuItem column={col} onClick={onClick} />
|
|
41
|
+
// + <GridFilterMenuItem colDef={col} onClick={onClick} />
|
|
42
|
+
return (0, _renameProps.default)({
|
|
43
|
+
root,
|
|
44
|
+
componentNames: Object.values(VARIABLES),
|
|
45
|
+
props: {
|
|
46
|
+
column: 'colDef'
|
|
47
|
+
},
|
|
48
|
+
j
|
|
49
|
+
}).toSource(printOptions);
|
|
50
|
+
}
|