-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[codemod] Add a codemod and update the grid migration guide (#12488)
- Loading branch information
1 parent
51952b6
commit 84b4e02
Showing
10 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import transformRenameComponentsToSlots from '../rename-components-to-slots'; | ||
import renameCellSelectionProps from '../rename-cell-selection-props'; | ||
import removeExperimentalFeatures from '../remove-stabilized-experimentalFeatures'; | ||
|
||
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
|
||
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { | ||
file.source = transformRenameComponentsToSlots(file, api, options); | ||
file.source = renameCellSelectionProps(file, api, options); | ||
file.source = removeExperimentalFeatures(file, api, options); | ||
|
||
return file.source; | ||
} |
34 changes: 34 additions & 0 deletions
34
...ages/x-codemod/src/v7.0.0/data-grid/remove-stabilized-experimentalFeatures/actual.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { DataGridPremium } from '@mui/x-data-grid-premium'; | ||
|
||
function App() { | ||
return ( | ||
<React.Fragment> | ||
<DataGrid | ||
experimentalFeatures={{ | ||
columnGrouping: true, | ||
clipboardPaste: true, | ||
}} | ||
/> | ||
<DataGridPro | ||
experimentalFeatures={{ | ||
lazyLoading: true, | ||
ariaV7: true, | ||
}} | ||
/> | ||
<DataGridPremium | ||
experimentalFeatures={{ | ||
columnGrouping: true, | ||
clipboardPaste: true, | ||
lazyLoading: true, | ||
ariaV7: true, | ||
}} | ||
/> | ||
<DataGridPro {...props} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default App; |
17 changes: 17 additions & 0 deletions
17
...es/x-codemod/src/v7.0.0/data-grid/remove-stabilized-experimentalFeatures/expected.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { DataGridPremium } from '@mui/x-data-grid-premium'; | ||
|
||
function App() { | ||
return ( | ||
<React.Fragment> | ||
<DataGrid /> | ||
<DataGridPro /> | ||
<DataGridPremium /> | ||
<DataGridPro {...props} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default App; |
22 changes: 22 additions & 0 deletions
22
packages/x-codemod/src/v7.0.0/data-grid/remove-stabilized-experimentalFeatures/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import removeObjectProperty from '../../../util/removeObjectProperty'; | ||
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
|
||
const componentsNames = ['DataGrid', 'DataGridPro', 'DataGridPremium']; | ||
const propName = 'experimentalFeatures'; | ||
const propKeys = ['columnGrouping', 'clipboardPaste', 'lazyLoading', 'ariaV7']; | ||
|
||
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
|
||
const printOptions = options.printOptions || { | ||
quote: 'single', | ||
trailingComma: true, | ||
}; | ||
|
||
propKeys.forEach((propKey) => { | ||
removeObjectProperty({ root, j, propName, componentsNames, propKey }); | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
27 changes: 27 additions & 0 deletions
27
...rid/remove-stabilized-experimentalFeatures/remove-stabilized-experimentalFeatures.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/data-grid', () => { | ||
describe('remove-stabilized-experimentalFeatures', () => { | ||
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'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters