-
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
- Loading branch information
Showing
7 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/eslint-plugin-pf-codemods/src/rules/v6/chartPromoted/chart-promoted.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,31 @@ | ||
import { Rule } from "eslint"; | ||
import { JSXOpeningElement } from "estree-jsx"; | ||
import { getAllImportsFromPackage, checkMatchingJSXOpeningElement, getAttribute } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/1234 | ||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: function (context: Rule.RuleContext) { | ||
const basePackage = "@patternfly/react-core"; | ||
const componentImports = getAllImportsFromPackage(context, basePackage, ["Chart"]); | ||
|
||
return !componentImports.length | ||
? {} | ||
: { | ||
JSXOpeningElement(node: JSXOpeningElement) { | ||
if (checkMatchingJSXOpeningElement(node, componentImports)) { | ||
const Prop = getAttribute(node, ""); | ||
if (Prop) { | ||
context.report({ | ||
node, | ||
message: "this is a test", | ||
fix(fixer) { | ||
return fixer.replaceText(Prop, ""); | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
...plugin-pf-codemods/src/rules/v6/chartsVictoryPromoted/chartsVictory-promoted.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,17 @@ | ||
### chartsVictory-promoted [(#11091)](https://github.com/patternfly/patternfly-react/pull/11091) | ||
|
||
In order to support multiple chart libraries, Victory has become a peer dependency. This rule will update existing import paths to our victory directory. | ||
|
||
#### Examples | ||
|
||
In: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
Out: | ||
|
||
```jsx | ||
%outputExample% | ||
``` |
106 changes: 106 additions & 0 deletions
106
...lint-plugin-pf-codemods/src/rules/v6/chartsVictoryPromoted/chartsVictory-promoted.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,106 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./chartsVictory-promoted"; | ||
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 promoted. 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/Chart/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/victory';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-charts/dist/dynamic/components/index.js';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-charts/victory';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
}); | ||
|
||
ruleTester.run("chartVictory-promoted", rule, { | ||
valid: validTests, | ||
invalid: invalidTests, | ||
}); |
62 changes: 62 additions & 0 deletions
62
...es/eslint-plugin-pf-codemods/src/rules/v6/chartsVictoryPromoted/chartsVictory-promoted.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 promoted. This rule will update import paths."; | ||
|
||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: moveSpecifiers( | ||
specifiersToMove, | ||
fromPackage, | ||
toPackage, | ||
messageAfterImportNameChange | ||
), | ||
}; |
1 change: 1 addition & 0 deletions
1
...lint-plugin-pf-codemods/src/rules/v6/chartsVictoryPromoted/chartsVictoryPromotedInput.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"; |
1 change: 1 addition & 0 deletions
1
...int-plugin-pf-codemods/src/rules/v6/chartsVictoryPromoted/chartsVictoryPromotedOutput.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/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