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 d7e0d27
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
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 existing import paths to our victory directory.`;
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-chart";
const toPackage = "@patternfly/react-chart/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 d7e0d27

Please sign in to comment.