-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(charts): import charts from @patternfly/react-charts/victory (#779)
* feat(charts): import charts from @patternfly/react-charts/victory * chore(charts): added test for js
- Loading branch information
Showing
6 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
.../eslint-plugin-pf-codemods/src/rules/v6/chartsImportMoved/chartsImport-moved.md
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,19 @@ | ||
### chartsImport-moved [(#11091)](https://github.com/patternfly/patternfly-react/pull/11091) | ||
|
||
In order to support multiple chart libraries, Victory based charts have moved. This rule will update import paths to our victory directory. | ||
|
||
Additionally, Victory has become a peer dependency. | ||
|
||
#### Examples | ||
|
||
In: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
Out: | ||
|
||
```jsx | ||
%outputExample% | ||
``` |
99 changes: 99 additions & 0 deletions
99
packages/eslint-plugin-pf-codemods/src/rules/v6/chartsImportMoved/chartsImport-moved.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,99 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./chartsImport-moved"; | ||
import { | ||
ValidTests, | ||
InvalidTests, | ||
createValidTest, | ||
createInvalidTest, | ||
} from "../../helpers/testHelpers"; | ||
|
||
const specifiersToMove = [ | ||
'Chart', | ||
'ChartArea', | ||
'ChartAxis', | ||
'ChartBar', | ||
'ChartBoxPlot', | ||
'ChartBullet', | ||
'ChartBulletComparativeErrorMeasure', | ||
'ChartBulletComparativeMeasure', | ||
'ChartBulletComparativeWarningMeasure', | ||
'ChartBulletPrimaryDotMeasure', | ||
'ChartBulletPrimarySegmentedMeasure', | ||
'ChartBulletQualitativeRange', | ||
'ChartContainer', | ||
'ChartCursorContainer', | ||
'ChartCursorTooltip', | ||
'ChartCursorFlyout', | ||
'ChartDonut', | ||
'ChartDonutThreshold', | ||
'ChartDonutUtilization', | ||
'ChartGroup', | ||
'ChartLabel', | ||
'ChartLegend', | ||
'ChartLegendTooltip', | ||
'ChartLegendTooltipContent', | ||
'ChartLegendTooltipLabel', | ||
'ChartLine', | ||
'ChartPie', | ||
'ChartPoint', | ||
'ChartScatter', | ||
'ChartStack', | ||
'ChartTheme', | ||
'ChartThemeColor', | ||
'ChartThreshold', | ||
'ChartTooltip', | ||
'ChartVoronoiContainer', | ||
'createContainer', | ||
'getInteractiveLegendEvents', | ||
'getInteractiveLegendItemStyles', | ||
'getCustomTheme', | ||
'getTheme', | ||
'getThemeColors' | ||
]; | ||
|
||
const validTests: ValidTests = []; | ||
const invalidTests: InvalidTests = []; | ||
|
||
specifiersToMove.forEach((specifier) => { | ||
validTests.push(createValidTest(`<${specifier} />`)); | ||
validTests.push( | ||
createValidTest( | ||
`import { ${specifier} } from '@patternfly/react-charts/victory';` | ||
) | ||
); | ||
|
||
const errorMessage = `${specifier} has been moved. This rule will update import paths.`; | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-charts';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-charts/victory';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} as CustomSpecifier } from '@patternfly/react-charts';`, | ||
`import {\n\t${specifier} as CustomSpecifier\n} from '@patternfly/react-charts/victory';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-charts/dist/esm/components/index.js';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-charts/dist/esm/victory/components/index.js';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-charts/dist/js/components/index.js';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-charts/dist/js/victory/components/index.js';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
}); | ||
|
||
ruleTester.run("chartImport-moved", rule, { | ||
valid: validTests, | ||
invalid: invalidTests, | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/eslint-plugin-pf-codemods/src/rules/v6/chartsImportMoved/chartsImport-moved.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,62 @@ | ||
import { moveSpecifiers } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/11091 | ||
|
||
const specifiersToMove = [ | ||
'Chart', | ||
'ChartArea', | ||
'ChartAxis', | ||
'ChartBar', | ||
'ChartBoxPlot', | ||
'ChartBullet', | ||
'ChartBulletComparativeErrorMeasure', | ||
'ChartBulletComparativeMeasure', | ||
'ChartBulletComparativeWarningMeasure', | ||
'ChartBulletPrimaryDotMeasure', | ||
'ChartBulletPrimarySegmentedMeasure', | ||
'ChartBulletQualitativeRange', | ||
'ChartContainer', | ||
'ChartCursorContainer', | ||
'ChartCursorTooltip', | ||
'ChartCursorFlyout', | ||
'ChartDonut', | ||
'ChartDonutThreshold', | ||
'ChartDonutUtilization', | ||
'ChartGroup', | ||
'ChartLabel', | ||
'ChartLegend', | ||
'ChartLegendTooltip', | ||
'ChartLegendTooltipContent', | ||
'ChartLegendTooltipLabel', | ||
'ChartLine', | ||
'ChartPie', | ||
'ChartPoint', | ||
'ChartScatter', | ||
'ChartStack', | ||
'ChartTheme', | ||
'ChartThemeColor', | ||
'ChartThreshold', | ||
'ChartTooltip', | ||
'ChartVoronoiContainer', | ||
'createContainer', | ||
'getInteractiveLegendEvents', | ||
'getInteractiveLegendItemStyles', | ||
'getCustomTheme', | ||
'getTheme', | ||
'getThemeColors' | ||
]; | ||
|
||
const fromPackage = "@patternfly/react-charts"; | ||
const toPackage = "@patternfly/react-charts/victory"; | ||
const messageAfterImportNameChange = | ||
"been moved. This rule will update import paths."; | ||
|
||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: moveSpecifiers( | ||
specifiersToMove, | ||
fromPackage, | ||
toPackage, | ||
messageAfterImportNameChange | ||
), | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/eslint-plugin-pf-codemods/src/rules/v6/chartsImportMoved/chartsImportMovedInput.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 @@ | ||
import { Chart } from "@patternfly/react-charts"; |
3 changes: 3 additions & 0 deletions
3
...ages/eslint-plugin-pf-codemods/src/rules/v6/chartsImportMoved/chartsImportMovedOutput.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,3 @@ | ||
import { | ||
Chart | ||
} from '@patternfly/react-charts/victory'; |
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