-
-
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.
[charts] Add codemod for removing ResponsiveChartContainer (#15323)
Signed-off-by: Jose C Quintas Jr <[email protected]> Co-authored-by: Jose C Quintas Jr <[email protected]>
- Loading branch information
1 parent
3e82743
commit 7062bbb
Showing
11 changed files
with
205 additions
and
4 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
5 changes: 5 additions & 0 deletions
5
packages/x-codemod/src/v8.0.0/charts/preset-safe/actual.spec.tsx
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,9 +1,14 @@ | ||
// @ts-nocheck | ||
import * as React from 'react'; | ||
import { PieChart } from '@mui/x-charts/PieChart'; | ||
import { BarPlot } from '@mui/x-charts/BarChart'; | ||
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer'; | ||
|
||
// prettier-ignore | ||
<div> | ||
<PieChart legend={{ hidden: true }} /> | ||
<PieChart legend={{ hidden: true }} slotProps={{ tooltip: { trigger: 'axis' } }} /> | ||
<ResponsiveChartContainer> | ||
<BarPlot /> | ||
</ResponsiveChartContainer> | ||
</div>; |
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,9 +1,11 @@ | ||
import transformLegendToSlots from '../rename-legend-to-slots-legend'; | ||
import transformRemoveResponsiveContainer from '../rename-responsive-chart-container'; | ||
|
||
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
|
||
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { | ||
file.source = transformLegendToSlots(file, api, options); | ||
file.source = transformRemoveResponsiveContainer(file, api, options); | ||
|
||
return file.source; | ||
} |
14 changes: 14 additions & 0 deletions
14
...odemod/src/v8.0.0/charts/rename-responsive-chart-container/actual-nested-imports.spec.tsx
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,14 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import * as React from 'react'; | ||
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer'; | ||
import { ResponsiveChartContainerPro } from '@mui/x-charts-pro/ResponsiveChartContainerPro'; | ||
import { BarPlot } from '@mui/x-charts-pro'; | ||
|
||
<div> | ||
<ResponsiveChartContainer series={[]}> | ||
<BarPlot /> | ||
</ResponsiveChartContainer> | ||
<ResponsiveChartContainerPro series={[]}> | ||
<BarPlot /> | ||
</ResponsiveChartContainerPro> | ||
</div>; |
13 changes: 13 additions & 0 deletions
13
...-codemod/src/v8.0.0/charts/rename-responsive-chart-container/actual-root-imports.spec.tsx
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,13 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import * as React from 'react'; | ||
import { ResponsiveChartContainer } from '@mui/x-charts'; | ||
import { BarPlot, ResponsiveChartContainerPro } from '@mui/x-charts-pro'; | ||
|
||
<div> | ||
<ResponsiveChartContainer series={[]}> | ||
<BarPlot /> | ||
</ResponsiveChartContainer> | ||
<ResponsiveChartContainerPro series={[]}> | ||
<BarPlot /> | ||
</ResponsiveChartContainerPro> | ||
</div>; |
14 changes: 14 additions & 0 deletions
14
...emod/src/v8.0.0/charts/rename-responsive-chart-container/expected-nested-imports.spec.tsx
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,14 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import * as React from 'react'; | ||
import { ChartContainer } from '@mui/x-charts/ChartContainer'; | ||
import { ChartContainerPro } from '@mui/x-charts-pro/ChartContainerPro'; | ||
import { BarPlot } from '@mui/x-charts-pro'; | ||
|
||
<div> | ||
<ChartContainer series={[]}> | ||
<BarPlot /> | ||
</ChartContainer> | ||
<ChartContainerPro series={[]}> | ||
<BarPlot /> | ||
</ChartContainerPro> | ||
</div>; |
13 changes: 13 additions & 0 deletions
13
...odemod/src/v8.0.0/charts/rename-responsive-chart-container/expected-root-imports.spec.tsx
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,13 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import * as React from 'react'; | ||
import { ChartContainer } from '@mui/x-charts'; | ||
import { BarPlot, ChartContainerPro } from '@mui/x-charts-pro'; | ||
|
||
<div> | ||
<ChartContainer series={[]}> | ||
<BarPlot /> | ||
</ChartContainer> | ||
<ChartContainerPro series={[]}> | ||
<BarPlot /> | ||
</ChartContainerPro> | ||
</div>; |
37 changes: 37 additions & 0 deletions
37
packages/x-codemod/src/v8.0.0/charts/rename-responsive-chart-container/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,37 @@ | ||
import type { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
import { renameImports } from '../../../util/renameImports'; | ||
|
||
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, | ||
wrapColumn: 40, | ||
}; | ||
|
||
renameImports({ | ||
j, | ||
root, | ||
packageNames: ['@mui/x-charts', '@mui/x-charts-pro'], | ||
imports: [ | ||
{ | ||
oldEndpoint: 'ResponsiveChartContainer', | ||
newEndpoint: 'ChartContainer', | ||
importsMapping: { | ||
ResponsiveChartContainer: 'ChartContainer', | ||
}, | ||
}, | ||
{ | ||
oldEndpoint: 'ResponsiveChartContainerPro', | ||
newEndpoint: 'ChartContainerPro', | ||
importsMapping: { | ||
ResponsiveChartContainerPro: 'ChartContainerPro', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
44 changes: 44 additions & 0 deletions
44
...v8.0.0/charts/rename-responsive-chart-container/rename-responsive-chart-container.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,44 @@ | ||
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)); | ||
} | ||
|
||
const TEST_FILES = ['nested-imports', 'root-imports']; | ||
|
||
describe('v8.0.0/charts', () => { | ||
describe('rename-responsive-chart-container.test', () => { | ||
TEST_FILES.forEach((testFile) => { | ||
const actualPath = `./actual-${testFile}.spec.tsx`; | ||
const expectedPath = `./expected-${testFile}.spec.tsx`; | ||
|
||
describe(`${testFile.replace(/-/g, ' ')}`, () => { | ||
it('transforms imports as needed', () => { | ||
const actual = transform( | ||
{ source: read(actualPath) }, | ||
{ jscodeshift: jscodeshift.withParser('tsx') }, | ||
{}, | ||
); | ||
|
||
const expected = read(expectedPath); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
|
||
it('should be idempotent', () => { | ||
const actual = transform( | ||
{ source: read(expectedPath) }, | ||
{ jscodeshift: jscodeshift.withParser('tsx') }, | ||
{}, | ||
); | ||
|
||
const expected = read(expectedPath); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |