@mui/x-codemod 6.0.0-beta.1 → 6.0.0-beta.3
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 +194 -0
- package/codemod.js +12 -1
- package/package.json +3 -3
- package/util/addComponentsSlots.js +5 -5
- package/util/removeObjectProperty.js +40 -0
- package/util/renameCSSClasses.js +20 -0
- package/util/renameIdentifiers.js +91 -0
- package/util/renameNestedProps.js +25 -0
- package/v6.0.0/data-grid/preset-safe/index.js +8 -0
- package/v6.0.0/data-grid/remove-stabilized-experimentalFeatures/index.js +27 -0
- package/v6.0.0/data-grid/rename-filter-item-props/index.js +53 -0
- package/v6.0.0/data-grid/rename-linkOperators-logicOperators/index.js +97 -0
- package/v6.0.0/data-grid/rename-selectors-and-events/index.js +24 -12
- package/v6.0.0/data-grid/replace-onCellFocusOut-prop/index.js +40 -0
- package/v6.0.0/pickers/preset-safe/index.js +4 -0
- package/v6.0.0/pickers/rename-default-toolbar-title-localeText/index.js +31 -0
- package/v6.0.0/pickers/rename-inputFormat-prop/index.js +39 -0
- package/util/renameClassKey.js +0 -29
package/README.md
CHANGED
|
@@ -95,6 +95,8 @@ The list includes these transformers
|
|
|
95
95
|
- [`migrate-to-components-componentsProps`](#migrate-to-components-componentsProps)
|
|
96
96
|
- [`replace-arrows-button-slot`](#replace-arrows-button-slot)
|
|
97
97
|
- [`rename-should-disable-time`](#rename-should-disable-time)
|
|
98
|
+
- [`rename-inputFormat-prop`](#rename-inputFormat-prop)
|
|
99
|
+
- [`rename-default-toolbar-title-localeText`](#rename-default-toolbar-title-localeText)
|
|
98
100
|
|
|
99
101
|
#### `adapter-change-import`
|
|
100
102
|
|
|
@@ -341,6 +343,44 @@ Replace `shouldDisableTime` by `shouldDisableClock`.
|
|
|
341
343
|
npx @mui/x-codemod v6.0.0/pickers/rename-should-disable-time <path>
|
|
342
344
|
```
|
|
343
345
|
|
|
346
|
+
#### `rename-inputFormat-prop`
|
|
347
|
+
|
|
348
|
+
Replace `inputFormat` prop with `format`.
|
|
349
|
+
|
|
350
|
+
```diff
|
|
351
|
+
<DatePicker
|
|
352
|
+
- inputFormat="YYYY"
|
|
353
|
+
+ format="YYYY"
|
|
354
|
+
/>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
```sh
|
|
358
|
+
npx @mui/x-codemod v6.0.0/pickers/rename-inputFormat-prop <path>
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### `rename-default-toolbar-title-localeText`
|
|
362
|
+
|
|
363
|
+
Rename toolbar related translation keys, removing `Default` part from them to better fit their usage.
|
|
364
|
+
|
|
365
|
+
```diff
|
|
366
|
+
<LocalizationProvider
|
|
367
|
+
localeText={{
|
|
368
|
+
- datePickerDefaultToolbarTitle: 'Date Picker',
|
|
369
|
+
+ datePickerToolbarTitle: 'Date Picker',
|
|
370
|
+
- timePickerDefaultToolbarTitle: 'Time Picker',
|
|
371
|
+
+ timePickerToolbarTitle: 'Time Picker',
|
|
372
|
+
- dateTimePickerDefaultToolbarTitle: 'Date Time Picker',
|
|
373
|
+
+ dateTimePickerToolbarTitle: 'Date Time Picker',
|
|
374
|
+
- dateRangePickerDefaultToolbarTitle: 'Date Range Picker',
|
|
375
|
+
+ dateRangePickerToolbarTitle: 'Date Range Picker',
|
|
376
|
+
}}
|
|
377
|
+
/>
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
```sh
|
|
381
|
+
npx @mui/x-codemod v6.0.0/pickers/rename-default-toolbar-title-localeText <path>
|
|
382
|
+
```
|
|
383
|
+
|
|
344
384
|
#### `rename-components-to-slots`
|
|
345
385
|
|
|
346
386
|
Renames the `components` and `componentsProps` props to `slots` and `slotProps`, respectively.
|
|
@@ -376,7 +416,11 @@ The list includes these transformers
|
|
|
376
416
|
- [`row-selection-props-rename`](#row-selection-props-rename)
|
|
377
417
|
- [`rename-rowsPerPageOptions-prop`](#rename-rowsPerPageOptions-prop)
|
|
378
418
|
- [`remove-disableExtendRowFullWidth-prop`](#remove-disableExtendRowFullWidth-prop)
|
|
419
|
+
- [`rename-linkOperators-logicOperators`](#rename-linkOperators-logicOperators)
|
|
420
|
+
- [`rename-filter-item-props`](#rename-filter-item-props)
|
|
379
421
|
- [`rename-selectors-and-events`](#rename-selectors-and-events)
|
|
422
|
+
- [`remove-stabilized-experimentalFeatures`](#remove-stabilized-experimentalFeatures)
|
|
423
|
+
- [`replace-onCellFocusOut-prop`](#replace-onCellFocusOut-prop)
|
|
380
424
|
|
|
381
425
|
#### `column-menu-components-rename`
|
|
382
426
|
|
|
@@ -457,6 +501,102 @@ Remove `disableExtendRowFullWidth` prop which is no longer supported.
|
|
|
457
501
|
npx @mui/x-codemod v6.0.0/data-grid/remove-disableExtendRowFullWidth-prop <path>
|
|
458
502
|
```
|
|
459
503
|
|
|
504
|
+
#### `rename-linkOperators-logicOperators`
|
|
505
|
+
|
|
506
|
+
Rename `linkOperators` related props to `logicOperators` and rename classes.
|
|
507
|
+
|
|
508
|
+
```diff
|
|
509
|
+
const [filterModel, setFilterModel] = React.useState<GridFilterModel>({
|
|
510
|
+
items: [],
|
|
511
|
+
- linkOperator: GridLinkOperator.Or,
|
|
512
|
+
- quickFilterLogicOperator: GridLinkOperator.Or,
|
|
513
|
+
+ logicOperator: GridLogicOperator.Or,
|
|
514
|
+
+ quickFilterLogicOperator: GridLogicOperator.Or,
|
|
515
|
+
});
|
|
516
|
+
- apiRef.current.setFilterLinkOperator('and')
|
|
517
|
+
- const localeText = apiRef.current.getLocaleText('filterPanelLinkOperator')
|
|
518
|
+
+ apiRef.current.setFilterLogicOperator('and')
|
|
519
|
+
+ const localeText = apiRef.current.getLocaleText('filterPanelLogicOperator')
|
|
520
|
+
<DataGrid
|
|
521
|
+
initialState={{
|
|
522
|
+
filter: {
|
|
523
|
+
filterModel: {
|
|
524
|
+
items: [],
|
|
525
|
+
- linkOperator: GridLinkOperator.Or,
|
|
526
|
+
- quickFilterLogicOperator: GridLinkOperator.Or,
|
|
527
|
+
+ logicOperator: GridLogicOperator.Or,
|
|
528
|
+
+ quickFilterLogicOperator: GridLogicOperator.Or,
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
}}
|
|
532
|
+
filterModel={filterModel}
|
|
533
|
+
componentsProps={{
|
|
534
|
+
filter: {
|
|
535
|
+
- linkOperators: [GridLinkOperator.And],
|
|
536
|
+
+ logicOperators: [GridLogicOperator.And],
|
|
537
|
+
filterFormProps: {
|
|
538
|
+
- linkOperatorInputProps: {
|
|
539
|
+
+ logicOperatorInputProps: {
|
|
540
|
+
variant: 'outlined',
|
|
541
|
+
size: 'small',
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
}}
|
|
546
|
+
sx={{
|
|
547
|
+
- '& .MuiDataGrid-filterFormLinkOperatorInput': { mr: 2 },
|
|
548
|
+
- '& .MuiDataGrid-withBorder': { borderColor: '#456' },
|
|
549
|
+
+ '& .MuiDataGrid-filterFormLogicOperatorInput': { mr: 2 },
|
|
550
|
+
+ '& .MuiDataGrid-withBorderColor': { borderColor: '#456' },
|
|
551
|
+
}}
|
|
552
|
+
/>
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
```sh
|
|
556
|
+
npx @mui/x-codemod v6.0.0/data-grid/rename-linkOperators-logicOperators <path>
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
#### `rename-filter-item-props`
|
|
560
|
+
|
|
561
|
+
Rename filter item props to the new values.
|
|
562
|
+
|
|
563
|
+
```diff
|
|
564
|
+
<DataGrid
|
|
565
|
+
columns={columns}
|
|
566
|
+
rows={rows}
|
|
567
|
+
initialState={{
|
|
568
|
+
filter: {
|
|
569
|
+
filterModel: {
|
|
570
|
+
items: [
|
|
571
|
+
{
|
|
572
|
+
- columnField: 'column',
|
|
573
|
+
- operatorValue: 'contains',
|
|
574
|
+
+ field: 'column',
|
|
575
|
+
+ operator: 'contains',
|
|
576
|
+
value: 'a',
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
}}
|
|
582
|
+
filterModel={{
|
|
583
|
+
items: [
|
|
584
|
+
{
|
|
585
|
+
- columnField: 'column',
|
|
586
|
+
- operatorValue: 'contains',
|
|
587
|
+
+ field: 'column',
|
|
588
|
+
+ operator: 'contains',
|
|
589
|
+
value: 'a',
|
|
590
|
+
},
|
|
591
|
+
],
|
|
592
|
+
}}
|
|
593
|
+
/>
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
```sh
|
|
597
|
+
npx @mui/x-codemod v6.0.0/data-grid/rename-filter-item-props <path>
|
|
598
|
+
```
|
|
599
|
+
|
|
460
600
|
#### `rename-selectors-and-events`
|
|
461
601
|
|
|
462
602
|
Rename selectors and events.
|
|
@@ -471,6 +611,11 @@ Rename selectors and events.
|
|
|
471
611
|
- const rowCount = useGridSelector(apiRef, gridVisibleRowCountSelector);
|
|
472
612
|
- const sortedTopLevelRowEntries = useGridSelector(apiRef, gridVisibleSortedTopLevelRowEntriesSelector);
|
|
473
613
|
- const topLevelRowCount = useGridSelector(apiRef, gridVisibleTopLevelRowCountSelector);
|
|
614
|
+
- const allGridColumnsFields = useGridSelector(apiRef, allGridColumnsFieldsSelector);
|
|
615
|
+
- const allGridColumns = useGridSelector(apiRef, allGridColumnsSelector);
|
|
616
|
+
- const visibleGridColumns = useGridSelector(apiRef, visibleGridColumnsSelector);
|
|
617
|
+
- const filterableGridColumns = useGridSelector(apiRef, filterableGridColumnsSelector);
|
|
618
|
+
- const getGridNumericColumn = useGridSelector(apiRef, getGridNumericColumnOperators);
|
|
474
619
|
+ useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
475
620
|
+ apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
476
621
|
+ const selection = useGridSelector(apiRef, gridRowSelectionStateSelector);
|
|
@@ -479,6 +624,11 @@ Rename selectors and events.
|
|
|
479
624
|
+ const rowCount = useGridSelector(apiRef, gridExpandedRowCountSelector);
|
|
480
625
|
+ const sortedTopLevelRowEntries = useGridSelector(apiRef, gridFilteredSortedTopLevelRowEntriesSelector);
|
|
481
626
|
+ const topLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
|
|
627
|
+
+ const allGridColumnsFields = useGridSelector(apiRef, gridColumnFieldsSelector);
|
|
628
|
+
+ const allGridColumns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
|
|
629
|
+
+ const visibleGridColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
|
|
630
|
+
+ const filterableGridColumns = useGridSelector(apiRef, gridFilterableColumnDefinitionsSelector);
|
|
631
|
+
+ const getGridNumericColumn = useGridSelector(apiRef, getGridNumericOperators);
|
|
482
632
|
}
|
|
483
633
|
```
|
|
484
634
|
|
|
@@ -486,4 +636,48 @@ Rename selectors and events.
|
|
|
486
636
|
npx @mui/x-codemod v6.0.0/data-grid/rename-selectors-and-events <path>
|
|
487
637
|
```
|
|
488
638
|
|
|
639
|
+
#### `remove-stabilized-experimentalFeatures`
|
|
640
|
+
|
|
641
|
+
Remove feature flags for stabilized `experimentalFeatures`.
|
|
642
|
+
|
|
643
|
+
```diff
|
|
644
|
+
<DataGrid
|
|
645
|
+
- experimentalFeatures={{
|
|
646
|
+
- newEditingApi: true,
|
|
647
|
+
- }}
|
|
648
|
+
/>
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
```diff
|
|
652
|
+
<DataGrid
|
|
653
|
+
experimentalFeatures={{
|
|
654
|
+
- newEditingApi: true,
|
|
655
|
+
columnGrouping: true,
|
|
656
|
+
}}
|
|
657
|
+
/>
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
```sh
|
|
661
|
+
npx @mui/x-codemod v6.0.0/data-grid/remove-stabilized-experimentalFeatures <path>
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
#### `replace-onCellFocusOut-prop`
|
|
665
|
+
|
|
666
|
+
Replace `onCellFocusOut` prop with `componentsProps.cell.onBlur`.
|
|
667
|
+
|
|
668
|
+
```diff
|
|
669
|
+
<DataGrid
|
|
670
|
+
- onCellFocusOut={handleBlur}
|
|
671
|
+
+ componentsProps={{
|
|
672
|
+
+ cell: {
|
|
673
|
+
+ onBlur: handleBlur,
|
|
674
|
+
+ },
|
|
675
|
+
+ }}
|
|
676
|
+
/>
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
```sh
|
|
680
|
+
npx @mui/x-codemod v6.0.0/data-grid/replace-onCellFocusOut-prop <path>
|
|
681
|
+
```
|
|
682
|
+
|
|
489
683
|
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
|
@@ -34,6 +34,17 @@ async function runTransform(transform, files, flags, codemodFlags) {
|
|
|
34
34
|
|
|
35
35
|
// eslint-disable-next-line no-console -- debug information
|
|
36
36
|
console.log(`Executing command: jscodeshift ${args.join(' ')}`);
|
|
37
|
+
console.warn(`
|
|
38
|
+
====================================
|
|
39
|
+
IMPORTANT NOTICE ABOUT CODEMOD USAGE
|
|
40
|
+
====================================
|
|
41
|
+
Not all use cases are covered by codemods. In some scenarios, like props spreading, cross-file dependencies and etc., the changes are not properly identified and therefore must be handled manually.
|
|
42
|
+
|
|
43
|
+
For example, if a codemod tries to rename a prop, but this prop is hidden with the spread operator, it won't be transformed as expected.
|
|
44
|
+
<DatePicker {...pickerProps} />
|
|
45
|
+
|
|
46
|
+
After running the codemods, make sure to test your application and that you don't have any console errors.
|
|
47
|
+
`);
|
|
37
48
|
const jscodeshiftProcess = _child_process.default.spawnSync('node', args, {
|
|
38
49
|
stdio: 'inherit'
|
|
39
50
|
});
|
|
@@ -77,4 +88,4 @@ _yargs.default.command({
|
|
|
77
88
|
},
|
|
78
89
|
// @ts-expect-error
|
|
79
90
|
handler: run
|
|
80
|
-
}).scriptName('npx @mui/x-codemod').example('$0 v6.0.0/
|
|
91
|
+
}).scriptName('npx @mui/x-codemod').example('$0 v6.0.0/preset-safe src', 'Run "preset-safe" 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-beta.
|
|
3
|
+
"version": "6.0.0-beta.3",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/core": "^7.20.12",
|
|
35
|
-
"@babel/runtime": "^7.20.
|
|
36
|
-
"@babel/traverse": "^7.20.
|
|
35
|
+
"@babel/runtime": "^7.20.13",
|
|
36
|
+
"@babel/traverse": "^7.20.13",
|
|
37
37
|
"jscodeshift": "0.13.1",
|
|
38
38
|
"jscodeshift-add-imports": "^1.0.10",
|
|
39
39
|
"yargs": "^17.6.2"
|
|
@@ -5,24 +5,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformNestedProp = exports.addItemToObject = void 0;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Recursive function that:
|
|
9
9
|
* Return a jscodeshift object with `value` associated to path.
|
|
10
10
|
* The path can be such as 'tabs.hidden' which will return `{ tabs: { hidden: value } }`.
|
|
11
11
|
* If object is not null, path/value will be added respecting the other properties of the object.
|
|
12
12
|
*/
|
|
13
13
|
const addItemToObject = (path, value, object, j) => {
|
|
14
|
-
const
|
|
14
|
+
const splittedPath = path.split('.');
|
|
15
15
|
|
|
16
16
|
// Final case where we have to add the property to the object.
|
|
17
|
-
if (
|
|
17
|
+
if (splittedPath.length === 1) {
|
|
18
18
|
const propertyToAdd = j.objectProperty(j.identifier(path), value);
|
|
19
19
|
if (object === null) {
|
|
20
20
|
return j.objectExpression([propertyToAdd]);
|
|
21
21
|
}
|
|
22
22
|
return j.objectExpression([...(object.properties ?? []).filter(property => property.key.name !== path), propertyToAdd]);
|
|
23
23
|
}
|
|
24
|
-
const remainingPath =
|
|
25
|
-
const targetKey =
|
|
24
|
+
const remainingPath = splittedPath.slice(1).join('.');
|
|
25
|
+
const targetKey = splittedPath[0];
|
|
26
26
|
if (object === null) {
|
|
27
27
|
// Simplest case, no object to take into consideration
|
|
28
28
|
const propertyToAdd = j.objectProperty(j.identifier(targetKey), addItemToObject(remainingPath, value, null, j));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = removeObjectProperty;
|
|
7
|
+
function removeObjectProperty({
|
|
8
|
+
root,
|
|
9
|
+
propName,
|
|
10
|
+
componentsNames,
|
|
11
|
+
propKey,
|
|
12
|
+
j
|
|
13
|
+
}) {
|
|
14
|
+
root.find(j.JSXElement).filter(path => {
|
|
15
|
+
return componentsNames.includes(path.value.openingElement.name.name);
|
|
16
|
+
}).forEach(element => {
|
|
17
|
+
const targetAttribute = element.value.openingElement.attributes.find(attribute => attribute.name.name === propName);
|
|
18
|
+
if (!targetAttribute) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const definedKeys = [];
|
|
22
|
+
const objectProperties = j(targetAttribute).find(j.Property);
|
|
23
|
+
objectProperties.forEach(path => {
|
|
24
|
+
const objectKey = path.value.key.name;
|
|
25
|
+
definedKeys.push(objectKey);
|
|
26
|
+
});
|
|
27
|
+
if (definedKeys.length === 1 && definedKeys[0] === propKey) {
|
|
28
|
+
// only that property is defined, remove the whole prop
|
|
29
|
+
j(element).find(j.JSXAttribute).filter(a => a.value.name.name === propName).forEach(path => {
|
|
30
|
+
j(path).remove();
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
objectProperties.forEach(path => {
|
|
34
|
+
if (path.value.key.name === propKey) {
|
|
35
|
+
j(path).remove();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = renameCSSClasses;
|
|
7
|
+
function renameCSSClasses({
|
|
8
|
+
root,
|
|
9
|
+
j,
|
|
10
|
+
renamedClasses
|
|
11
|
+
}) {
|
|
12
|
+
root.find(j.Literal).filter(path => !!Object.keys(renamedClasses).find(className => {
|
|
13
|
+
const literal = path.node.value;
|
|
14
|
+
return typeof literal === 'string' && literal.includes(className) && !literal.includes(renamedClasses[className]);
|
|
15
|
+
})).replaceWith(path => {
|
|
16
|
+
const literal = path.node.value;
|
|
17
|
+
const targetClassKey = Object.keys(renamedClasses).find(className => literal.includes(className));
|
|
18
|
+
return j.literal(literal.replace(targetClassKey, renamedClasses[targetClassKey]));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkPreRequisitesSatisfied = void 0;
|
|
7
|
+
exports.default = renameIdentifiers;
|
|
8
|
+
exports.matchImport = void 0;
|
|
9
|
+
/* eslint-disable no-underscore-dangle */
|
|
10
|
+
|
|
11
|
+
const matchImport = (path, regex) => (path.node.source.value.toString() || '').match(regex);
|
|
12
|
+
exports.matchImport = matchImport;
|
|
13
|
+
const findDeepASTPath = (j, currentPath, currentIdentifiers) => {
|
|
14
|
+
if (!currentIdentifiers.length) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const target = j(currentPath).find(j.Identifier).filter(path => path.value.name === currentIdentifiers[0]);
|
|
18
|
+
if (target.__paths.length === 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return findDeepASTPath(j, currentPath, currentIdentifiers.slice(1));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Checks if all pre-requisites are satisfied for the given path `root`.
|
|
26
|
+
* For it to be satisfied, at least one condition of all the pre-requisites must be fulfilled.
|
|
27
|
+
*
|
|
28
|
+
* @param {*} j
|
|
29
|
+
* @param {*} root
|
|
30
|
+
* @param {PreRequisiteUsage} preReqs
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
const checkPreRequisitesSatisfied = (j, root, preReqs) => {
|
|
34
|
+
if (preReqs.packageRegex || preReqs.components) {
|
|
35
|
+
// check if any of the components is imported from a package which satisfies `preReqs.packageRegex`
|
|
36
|
+
const imports = root.find(j.ImportDeclaration);
|
|
37
|
+
const matchingImports = preReqs.packageRegex ? imports.filter(path => !!matchImport(path, preReqs.packageRegex)) : imports;
|
|
38
|
+
if (!matchingImports.__paths.length) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// check if any of the `preReqs.components` is imported from the matching imports
|
|
42
|
+
const satisfyingImports = preReqs.components?.length ? matchingImports.find(j.Identifier).filter(path => preReqs.components.includes(path.node.name)) : matchingImports;
|
|
43
|
+
if (!satisfyingImports.__paths.length) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!preReqs.possiblePaths?.length) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const allComponents = root.find(j.JSXElement);
|
|
51
|
+
const matchingComponents = preReqs.components?.length ? allComponents.filter(path => preReqs.components.includes(path.node.openingElement.name.name)) : allComponents;
|
|
52
|
+
const matchingAttributes = matchingComponents.find(j.JSXAttribute)
|
|
53
|
+
// filter by props first
|
|
54
|
+
.filter(attribute => preReqs.possiblePaths.map(path => path.split('.')[0]).includes(attribute.node.name.name))
|
|
55
|
+
// filter by nested levels
|
|
56
|
+
.filter(attribute => findDeepASTPath(j, attribute, preReqs.possiblePaths.find(path => path.startsWith(attribute.node.name.name)).split('.').slice(1)));
|
|
57
|
+
return matchingAttributes.__paths.length > 0;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Renames identifiers based on the `identifiers` object passed plus an optional `preRequisiteUsages` object
|
|
62
|
+
* to control renaming based on certain conditions.
|
|
63
|
+
*
|
|
64
|
+
* @export renameIdentifiers
|
|
65
|
+
* @param {RenameIdentifiersArgs} {
|
|
66
|
+
* root, // jscodeshift root
|
|
67
|
+
* identifiers, // object of identifiers to rename
|
|
68
|
+
* preRequisiteUsages, // an optional list of pre-requisite to control renaming based on certain conditions
|
|
69
|
+
* // if any of the pre-requisites is satisfied then the identifier will be renamed
|
|
70
|
+
* // for more details, see the type definition of `PreRequisiteUsage`
|
|
71
|
+
* j, // jscodeshift
|
|
72
|
+
* }
|
|
73
|
+
*/
|
|
74
|
+
exports.checkPreRequisitesSatisfied = checkPreRequisitesSatisfied;
|
|
75
|
+
function renameIdentifiers({
|
|
76
|
+
root,
|
|
77
|
+
identifiers,
|
|
78
|
+
preRequisiteUsages,
|
|
79
|
+
j
|
|
80
|
+
}) {
|
|
81
|
+
root.find(j.Identifier).filter(path => !!identifiers[path.node.name]).replaceWith(path => {
|
|
82
|
+
if (!preRequisiteUsages || !preRequisiteUsages[path.node.name]) {
|
|
83
|
+
return j.importSpecifier(j.identifier(identifiers[path.node.name]));
|
|
84
|
+
}
|
|
85
|
+
const shouldReplace = checkPreRequisitesSatisfied(j, root, preRequisiteUsages[path.node.name]);
|
|
86
|
+
if (shouldReplace) {
|
|
87
|
+
return j.importSpecifier(j.identifier(identifiers[path.node.name]));
|
|
88
|
+
}
|
|
89
|
+
return j.importSpecifier(j.identifier(path.node.name));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = renameNestedProps;
|
|
7
|
+
function renameNestedProps({
|
|
8
|
+
root,
|
|
9
|
+
componentNames,
|
|
10
|
+
nestedProps,
|
|
11
|
+
j
|
|
12
|
+
}) {
|
|
13
|
+
return root.find(j.JSXElement).filter(path => componentNames.includes(path.value.openingElement.name.name)).find(j.JSXAttribute).filter(attribute => Object.keys(nestedProps).includes(attribute.node.name.name)).forEach(attribute => {
|
|
14
|
+
Object.entries(nestedProps).forEach(([rootPropName, props]) => {
|
|
15
|
+
if (attribute.node.name.name === rootPropName && attribute.node.value?.type === 'JSXExpressionContainer' && attribute.node.value?.expression.type === 'ObjectExpression') {
|
|
16
|
+
const existingProperties = attribute.node.value.expression.properties;
|
|
17
|
+
existingProperties.forEach(property => {
|
|
18
|
+
if (property.type === 'Property' && property.key.type === 'Identifier' && props[property.key.name]) {
|
|
19
|
+
property.key.name = props[property.key.name];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -9,12 +9,20 @@ var _columnMenuComponentsRename = _interopRequireDefault(require("../column-menu
|
|
|
9
9
|
var _rowSelectionPropsRename = _interopRequireDefault(require("../row-selection-props-rename"));
|
|
10
10
|
var _renameRowsPerPageOptionsProp = _interopRequireDefault(require("../rename-rowsPerPageOptions-prop"));
|
|
11
11
|
var _removeDisableExtendRowFullWidthProp = _interopRequireDefault(require("../remove-disableExtendRowFullWidth-prop"));
|
|
12
|
+
var _renameLinkOperatorsLogicOperators = _interopRequireDefault(require("../rename-linkOperators-logicOperators"));
|
|
13
|
+
var _renameFilterItemProps = _interopRequireDefault(require("../rename-filter-item-props"));
|
|
12
14
|
var _renameSelectorsAndEvents = _interopRequireDefault(require("../rename-selectors-and-events"));
|
|
15
|
+
var _removeStabilizedExperimentalFeatures = _interopRequireDefault(require("../remove-stabilized-experimentalFeatures"));
|
|
16
|
+
var _replaceOnCellFocusOutProp = _interopRequireDefault(require("../replace-onCellFocusOut-prop"));
|
|
13
17
|
function transformer(file, api, options) {
|
|
14
18
|
file.source = (0, _columnMenuComponentsRename.default)(file, api, options);
|
|
15
19
|
file.source = (0, _rowSelectionPropsRename.default)(file, api, options);
|
|
16
20
|
file.source = (0, _renameRowsPerPageOptionsProp.default)(file, api, options);
|
|
17
21
|
file.source = (0, _removeDisableExtendRowFullWidthProp.default)(file, api, options);
|
|
22
|
+
file.source = (0, _renameLinkOperatorsLogicOperators.default)(file, api, options);
|
|
23
|
+
file.source = (0, _renameFilterItemProps.default)(file, api, options);
|
|
18
24
|
file.source = (0, _renameSelectorsAndEvents.default)(file, api, options);
|
|
25
|
+
file.source = (0, _removeStabilizedExperimentalFeatures.default)(file, api, options);
|
|
26
|
+
file.source = (0, _replaceOnCellFocusOutProp.default)(file, api, options);
|
|
19
27
|
return file.source;
|
|
20
28
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 _removeObjectProperty = _interopRequireDefault(require("../../../util/removeObjectProperty"));
|
|
9
|
+
const componentsNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
10
|
+
const propName = 'experimentalFeatures';
|
|
11
|
+
const propKey = 'newEditingApi';
|
|
12
|
+
function transformer(file, api, options) {
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const printOptions = options.printOptions || {
|
|
16
|
+
quote: 'single',
|
|
17
|
+
trailingComma: true
|
|
18
|
+
};
|
|
19
|
+
(0, _removeObjectProperty.default)({
|
|
20
|
+
root,
|
|
21
|
+
j,
|
|
22
|
+
propName,
|
|
23
|
+
componentsNames,
|
|
24
|
+
propKey
|
|
25
|
+
});
|
|
26
|
+
return root.toSource(printOptions);
|
|
27
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 _renameIdentifiers = _interopRequireDefault(require("../../../util/renameIdentifiers"));
|
|
9
|
+
const renamedIdentifiers = {
|
|
10
|
+
columnField: 'field',
|
|
11
|
+
operatorValue: 'operator'
|
|
12
|
+
};
|
|
13
|
+
const PACKAGE_REGEXP = /@mui\/x-data-grid(-pro|-premium)?/;
|
|
14
|
+
const GridComponents = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
15
|
+
const preRequisiteUsages = {
|
|
16
|
+
columnField: {
|
|
17
|
+
possiblePaths: ['initialState', 'filterModel', 'onFilterModelChange'],
|
|
18
|
+
components: GridComponents,
|
|
19
|
+
packageRegex: PACKAGE_REGEXP
|
|
20
|
+
},
|
|
21
|
+
operatorValue: {
|
|
22
|
+
possiblePaths: ['initialState', 'filterModel', 'onFilterModelChange'],
|
|
23
|
+
components: GridComponents,
|
|
24
|
+
packageRegex: PACKAGE_REGEXP
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function transformer(file, api, options) {
|
|
28
|
+
const j = api.jscodeshift;
|
|
29
|
+
const root = j(file.source);
|
|
30
|
+
const printOptions = options.printOptions || {
|
|
31
|
+
quote: 'single',
|
|
32
|
+
trailingComma: true
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// <DataGrid(Pro|Premium)
|
|
36
|
+
// filterModel={{
|
|
37
|
+
// items: [{
|
|
38
|
+
// - columnField: 'name',
|
|
39
|
+
// + field: 'name',
|
|
40
|
+
// - operatorValue: 'contains',
|
|
41
|
+
// + operator: 'contains',
|
|
42
|
+
// value: 'a'
|
|
43
|
+
// }]
|
|
44
|
+
// }}
|
|
45
|
+
// />
|
|
46
|
+
(0, _renameIdentifiers.default)({
|
|
47
|
+
root,
|
|
48
|
+
j,
|
|
49
|
+
preRequisiteUsages,
|
|
50
|
+
identifiers: renamedIdentifiers
|
|
51
|
+
});
|
|
52
|
+
return root.toSource(printOptions);
|
|
53
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transform;
|
|
8
|
+
var _renameCSSClasses = _interopRequireDefault(require("packages/x-codemod/src/util/renameCSSClasses"));
|
|
9
|
+
var _renameIdentifiers = _interopRequireWildcard(require("../../../util/renameIdentifiers"));
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
+
const renamedIdentifiers = {
|
|
13
|
+
GridLinkOperator: 'GridLogicOperator',
|
|
14
|
+
linkOperatorInputProps: 'logicOperatorInputProps',
|
|
15
|
+
linkOperator: 'logicOperator',
|
|
16
|
+
linkOperators: 'logicOperators',
|
|
17
|
+
setFilterLinkOperator: 'setFilterLogicOperator'
|
|
18
|
+
};
|
|
19
|
+
const PACKAGE_REGEXP = /@mui\/x-data-grid(-pro|-premium)?/;
|
|
20
|
+
const GridComponents = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
21
|
+
const preRequisiteUsages = {
|
|
22
|
+
GridLinkOperator: {
|
|
23
|
+
possiblePaths: ['initialState.filter', 'filterModel', 'componentsProps.filter'],
|
|
24
|
+
components: GridComponents,
|
|
25
|
+
packageRegex: PACKAGE_REGEXP
|
|
26
|
+
},
|
|
27
|
+
linkOperatorInputProps: {
|
|
28
|
+
possiblePaths: ['componentsProps.filter'],
|
|
29
|
+
components: GridComponents,
|
|
30
|
+
packageRegex: PACKAGE_REGEXP
|
|
31
|
+
},
|
|
32
|
+
linkOperator: {
|
|
33
|
+
possiblePaths: ['initialState.filter', 'filterModel', 'componentsProps.filter'],
|
|
34
|
+
components: GridComponents,
|
|
35
|
+
packageRegex: PACKAGE_REGEXP
|
|
36
|
+
},
|
|
37
|
+
linkOperators: {
|
|
38
|
+
possiblePaths: ['componentsProps.filter'],
|
|
39
|
+
components: GridComponents,
|
|
40
|
+
packageRegex: PACKAGE_REGEXP
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const renamedLiterals = {
|
|
44
|
+
filterPanelLinkOperator: 'filterPanelLogicOperator'
|
|
45
|
+
};
|
|
46
|
+
const renamedClasses = {
|
|
47
|
+
'MuiDataGrid-filterFormLinkOperatorInput': 'MuiDataGrid-filterFormLogicOperatorInput',
|
|
48
|
+
'MuiDataGrid-withBorder': 'MuiDataGrid-withBorderColor'
|
|
49
|
+
};
|
|
50
|
+
function transform(file, api, options) {
|
|
51
|
+
const j = api.jscodeshift;
|
|
52
|
+
const root = j(file.source);
|
|
53
|
+
const printOptions = options.printOptions || {
|
|
54
|
+
quote: 'single',
|
|
55
|
+
trailingComma: true
|
|
56
|
+
};
|
|
57
|
+
const matchingImports = root.find(j.ImportDeclaration).filter(path => !!(0, _renameIdentifiers.matchImport)(path, PACKAGE_REGEXP));
|
|
58
|
+
if (matchingImports.length > 0) {
|
|
59
|
+
// Rename the identifiers
|
|
60
|
+
// <DataGrid
|
|
61
|
+
// componentsProps={{
|
|
62
|
+
// filter: {
|
|
63
|
+
// - linkOperators: [GridLinkOperator.And],
|
|
64
|
+
// + logicOperators: [GridLogicOperator.And],
|
|
65
|
+
// filterFormProps: {
|
|
66
|
+
// - linkOperatorInputProps: {
|
|
67
|
+
// + logicOperatorInputProps: {
|
|
68
|
+
// variant: 'outlined',
|
|
69
|
+
// size: 'small',
|
|
70
|
+
// },
|
|
71
|
+
// },
|
|
72
|
+
// },
|
|
73
|
+
// }}
|
|
74
|
+
// />
|
|
75
|
+
(0, _renameIdentifiers.default)({
|
|
76
|
+
j,
|
|
77
|
+
root,
|
|
78
|
+
identifiers: renamedIdentifiers,
|
|
79
|
+
preRequisiteUsages
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Rename the literals
|
|
83
|
+
// - apiRef.current.getLocaleText('filterPanelLinkOperator')
|
|
84
|
+
// + apiRef.current.getLocaleText('filterPanelLogicOperator')
|
|
85
|
+
root.find(j.Literal).filter(path => !!renamedLiterals[path.node.value]).replaceWith(path => j.literal(renamedLiterals[path.node.value]));
|
|
86
|
+
|
|
87
|
+
// Rename the classes
|
|
88
|
+
// - 'MuiDataGrid-filterFormLinkOperatorInput'
|
|
89
|
+
// + 'MuiDataGrid-filterFormLogicOperatorInput'
|
|
90
|
+
(0, _renameCSSClasses.default)({
|
|
91
|
+
j,
|
|
92
|
+
root,
|
|
93
|
+
renamedClasses
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return root.toSource(printOptions);
|
|
97
|
+
}
|
|
@@ -4,18 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = transformer;
|
|
7
|
+
var _renameIdentifiers = require("../../../util/renameIdentifiers");
|
|
7
8
|
const renamedSelectors = {
|
|
8
9
|
gridSelectionStateSelector: 'gridRowSelectionStateSelector',
|
|
9
10
|
gridVisibleSortedRowIdsSelector: 'gridExpandedSortedRowIdsSelector',
|
|
10
11
|
gridVisibleSortedRowEntriesSelector: 'gridExpandedSortedRowEntriesSelector',
|
|
11
12
|
gridVisibleRowCountSelector: 'gridExpandedRowCountSelector',
|
|
12
13
|
gridVisibleSortedTopLevelRowEntriesSelector: 'gridFilteredSortedTopLevelRowEntriesSelector',
|
|
13
|
-
gridVisibleTopLevelRowCountSelector: 'gridFilteredTopLevelRowCountSelector'
|
|
14
|
+
gridVisibleTopLevelRowCountSelector: 'gridFilteredTopLevelRowCountSelector',
|
|
15
|
+
allGridColumnsFieldsSelector: 'gridColumnFieldsSelector',
|
|
16
|
+
allGridColumnsSelector: 'gridColumnDefinitionsSelector',
|
|
17
|
+
visibleGridColumnsSelector: 'gridVisibleColumnDefinitionsSelector',
|
|
18
|
+
filterableGridColumnsSelector: 'gridFilterableColumnDefinitionsSelector',
|
|
19
|
+
getGridNumericColumnOperators: 'getGridNumericOperators'
|
|
14
20
|
};
|
|
15
21
|
const renamedEvents = {
|
|
16
22
|
selectionChange: 'rowSelectionChange',
|
|
17
23
|
rowsScroll: 'scrollPositionChange'
|
|
18
24
|
};
|
|
25
|
+
const preRequisites = {
|
|
26
|
+
components: ['DataGrid', 'DataGridPro', 'DataGridPremium'],
|
|
27
|
+
packageRegex: /@mui\/x-data-grid(-pro|-premium)?/
|
|
28
|
+
};
|
|
19
29
|
function transformer(file, api, options) {
|
|
20
30
|
const j = api.jscodeshift;
|
|
21
31
|
const root = j(file.source);
|
|
@@ -23,17 +33,19 @@ function transformer(file, api, options) {
|
|
|
23
33
|
quote: 'single',
|
|
24
34
|
trailingComma: true
|
|
25
35
|
};
|
|
36
|
+
const isGridUsed = (0, _renameIdentifiers.checkPreRequisitesSatisfied)(j, root, preRequisites);
|
|
37
|
+
if (isGridUsed) {
|
|
38
|
+
// Rename the import and usage of renamed selectors
|
|
39
|
+
// - import { gridSelectionStateSelector } from '@mui/x-data-grid'
|
|
40
|
+
// + import { gridRowSelectionStateSelector } from '@mui/x-data-grid'
|
|
41
|
+
root.find(j.Identifier).filter(path => !!renamedSelectors[path.node.name]).replaceWith(path => j.identifier(renamedSelectors[path.node.name]));
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// - apiRef.current.subscribeEvent('selectionChange', handleEvent);
|
|
35
|
-
// + useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
36
|
-
// + apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
37
|
-
root.find(j.CallExpression).find(j.Literal).filter(path => !!renamedEvents[path.node.value]).replaceWith(path => j.literal(renamedEvents[path.node.value]));
|
|
43
|
+
// Rename the usage of renamed event literals
|
|
44
|
+
// - useGridApiEventHandler('selectionChange', handleEvent);
|
|
45
|
+
// - apiRef.current.subscribeEvent('selectionChange', handleEvent);
|
|
46
|
+
// + useGridApiEventHandler('rowSelectionChange', handleEvent);
|
|
47
|
+
// + apiRef.current.subscribeEvent('rowSelectionChange', handleEvent);
|
|
48
|
+
root.find(j.CallExpression).find(j.Literal).filter(path => !!renamedEvents[path.node.value]).replaceWith(path => j.literal(renamedEvents[path.node.value]));
|
|
49
|
+
}
|
|
38
50
|
return root.toSource(printOptions);
|
|
39
51
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
|
|
9
|
+
var _addComponentsSlots = require("../../../util/addComponentsSlots");
|
|
10
|
+
const componentNames = ['DataGrid', 'DataGridPro', 'DataGridPremium'];
|
|
11
|
+
const propsToRename = {
|
|
12
|
+
onCellFocusOut: {
|
|
13
|
+
prop: 'componentsProps',
|
|
14
|
+
path: 'cell.onBlur'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function transformer(file, api, options) {
|
|
18
|
+
const j = api.jscodeshift;
|
|
19
|
+
const root = j(file.source);
|
|
20
|
+
const printOptions = options.printOptions || {
|
|
21
|
+
quote: 'single',
|
|
22
|
+
trailingComma: true
|
|
23
|
+
};
|
|
24
|
+
root.find(j.JSXElement).filter(path => {
|
|
25
|
+
return componentNames.includes(path.value.openingElement.name.name);
|
|
26
|
+
}).forEach(path => {
|
|
27
|
+
const attributesToTransform = j(path).find(j.JSXAttribute).filter(attribute => Object.keys(propsToRename).includes(attribute.value.name.name));
|
|
28
|
+
attributesToTransform.forEach(attribute => {
|
|
29
|
+
const attributeName = attribute.value.name.name;
|
|
30
|
+
const value = attribute.value.value?.type === 'JSXExpressionContainer' ? attribute.value.value.expression : attribute.value.value;
|
|
31
|
+
(0, _addComponentsSlots.transformNestedProp)(path, propsToRename[attributeName].prop, propsToRename[attributeName].path, value, j);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return (0, _removeProps.default)({
|
|
35
|
+
root,
|
|
36
|
+
j,
|
|
37
|
+
props: Object.keys(propsToRename),
|
|
38
|
+
componentNames
|
|
39
|
+
}).toSource(printOptions);
|
|
40
|
+
}
|
|
@@ -15,6 +15,8 @@ var _replaceToolbarPropsBySlot = _interopRequireDefault(require("../replace-tool
|
|
|
15
15
|
var _migrateToComponentsComponentsProps = _interopRequireDefault(require("../migrate-to-components-componentsProps"));
|
|
16
16
|
var _replaceArrowsButtonSlot = _interopRequireDefault(require("../replace-arrows-button-slot"));
|
|
17
17
|
var _renameShouldDisableTime = _interopRequireDefault(require("../rename-should-disable-time"));
|
|
18
|
+
var _renameInputFormatProp = _interopRequireDefault(require("../rename-inputFormat-prop"));
|
|
19
|
+
var _renameDefaultToolbarTitleLocaleText = _interopRequireDefault(require("../rename-default-toolbar-title-localeText"));
|
|
18
20
|
function transformer(file, api, options) {
|
|
19
21
|
file.source = (0, _localizationProviderRenameLocale.default)(file, api, options);
|
|
20
22
|
|
|
@@ -28,5 +30,7 @@ function transformer(file, api, options) {
|
|
|
28
30
|
file.source = (0, _migrateToComponentsComponentsProps.default)(file, api, options);
|
|
29
31
|
file.source = (0, _replaceArrowsButtonSlot.default)(file, api, options);
|
|
30
32
|
file.source = (0, _renameShouldDisableTime.default)(file, api, options);
|
|
33
|
+
file.source = (0, _renameInputFormatProp.default)(file, api, options);
|
|
34
|
+
file.source = (0, _renameDefaultToolbarTitleLocaleText.default)(file, api, options);
|
|
31
35
|
return file.source;
|
|
32
36
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 _renameNestedProps = _interopRequireDefault(require("../../../util/renameNestedProps"));
|
|
9
|
+
const propsToRename = {
|
|
10
|
+
localeText: {
|
|
11
|
+
datePickerDefaultToolbarTitle: 'datePickerToolbarTitle',
|
|
12
|
+
timePickerDefaultToolbarTitle: 'timePickerToolbarTitle',
|
|
13
|
+
dateTimePickerDefaultToolbarTitle: 'dateTimePickerToolbarTitle',
|
|
14
|
+
dateRangePickerDefaultToolbarTitle: 'dateRangePickerToolbarTitle'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function transformer(file, api, options) {
|
|
18
|
+
const j = api.jscodeshift;
|
|
19
|
+
const root = j(file.source);
|
|
20
|
+
const printOptions = options.printOptions || {
|
|
21
|
+
quote: 'single',
|
|
22
|
+
trailingComma: true
|
|
23
|
+
};
|
|
24
|
+
(0, _renameNestedProps.default)({
|
|
25
|
+
root,
|
|
26
|
+
componentNames: ['LocalizationProvider'],
|
|
27
|
+
nestedProps: propsToRename,
|
|
28
|
+
j
|
|
29
|
+
});
|
|
30
|
+
return root.toSource(printOptions);
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
* @param {import('jscodeshift').API} api
|
|
10
|
+
*/
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const printOptions = options.printOptions;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
root.find(j.ImportDeclaration).filter(({
|
|
16
|
+
node
|
|
17
|
+
}) => {
|
|
18
|
+
return node.source.value.startsWith('@mui/x-date-pickers');
|
|
19
|
+
}).forEach(path => {
|
|
20
|
+
path.node.specifiers.forEach(node => {
|
|
21
|
+
// Process only date-pickers components
|
|
22
|
+
root.findJSXElements(node.local.name).forEach(elementPath => {
|
|
23
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
elementPath.node.openingElement.attributes.forEach(elementNode => {
|
|
27
|
+
if (elementNode.type !== 'JSXAttribute') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (elementNode.name.name === 'inputFormat') {
|
|
31
|
+
elementNode.name.name = 'format';
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const transformed = root.findJSXElements();
|
|
38
|
+
return transformed.toSource(printOptions);
|
|
39
|
+
}
|
package/util/renameClassKey.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = renameClassKey;
|
|
7
|
-
function renameClassKey({
|
|
8
|
-
root,
|
|
9
|
-
componentName,
|
|
10
|
-
classes,
|
|
11
|
-
printOptions
|
|
12
|
-
}) {
|
|
13
|
-
const source = root.findJSXElements(componentName).forEach(path => {
|
|
14
|
-
path.node.openingElement.attributes?.forEach(node => {
|
|
15
|
-
if (node.type === 'JSXAttribute' && node.name.name === 'classes') {
|
|
16
|
-
// @ts-expect-error
|
|
17
|
-
node.value?.expression?.properties?.forEach(subNode => {
|
|
18
|
-
if (Object.keys(classes).includes(subNode.key.name)) {
|
|
19
|
-
subNode.key.name = classes[subNode.key.name];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}).toSource(printOptions);
|
|
25
|
-
return Object.entries(classes).reduce((result, [currentKey, newKey]) => {
|
|
26
|
-
const regex = new RegExp(`.Mui${componentName}-${currentKey}`, 'gm');
|
|
27
|
-
return result.replace(regex, `.Mui${componentName}-${newKey}`);
|
|
28
|
-
}, source);
|
|
29
|
-
}
|