Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(charts): import charts from @patternfly/react-charts/victory #779

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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%
```
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,
});
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
),
};
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,3 @@
import {
Chart
} from '@patternfly/react-charts/victory';
20 changes: 20 additions & 0 deletions packages/pf-codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ export const CardUpdatedClickableMarkupInput = () => {
};
```

### 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
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
Loading