Skip to content

Commit

Permalink
feat(charts): import charts from @patternfly/react-charts/victory
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Sep 30, 2024
1 parent 3d91910 commit 4859eea
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 0 deletions.
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, "");
},
});
}
}
},
};
},
};
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%
```
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,
});
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
),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { Chart } from "@patternfly/react-charts";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { Chart } from '@patternfly/react-charts/victory';
18 changes: 18 additions & 0 deletions packages/pf-codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,24 @@ export const CardUpdatedClickableMarkupInput = () => {
};
```

### 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
import { Chart } from "@patternfly/react-charts";
```

Out:

```jsx
import { Chart } from '@patternfly/react-charts/victory';
```

### checkbox-radio-replace-isLabelBeforeButton [(#10016)](https://github.com/patternfly/patternfly-react/pull/10016)

The `isLabelBeforeButton` prop in Checkbox and Radio has been replaced with `labelPosition="start"`
Expand Down

0 comments on commit 4859eea

Please sign in to comment.