Skip to content

Commit

Permalink
feat(ErrorState componentGroup): rename props (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora authored Jul 25, 2024
1 parent d8e33d8 commit 4f7a867
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### componentGroups-errorState-rename-props [(react-component-groups/#145)](https://github.com/patternfly/react-component-groups/pull/145)

In react-component-groups, we've renamed some ErrorState props to comply with its base component - EmptyState.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const ruleTester = require("../../ruletester");
import * as rule from "./componentGroups-errorState-rename-props";

const renameMap = {
errorTitle: "titleText",
errorDescription: "bodyText",
defaultErrorDescription: "defaultBodyText",
};

ruleTester.run("componentGroups-errorState-rename-props", rule, {
valid: [
{
code: `<ErrorState errorTitle="" />`,
},
{
code: `<ErrorState errorDescription="" />`,
},
{
code: `<ErrorState defaultErrorDescription="" />`,
},
{
code: `import { ErrorState } from '@patternfly/react-component-groups'; <ErrorState someOtherProp />`,
},
],
invalid: [
{
code: `import { ErrorState } from '@patternfly/react-component-groups';
<ErrorState
errorTitle="Sample error title"
errorDescription="Sample error description"
defaultErrorDescription="Sample default error description"
/>`,
output: `import { ErrorState } from '@patternfly/react-component-groups';
<ErrorState
titleText="Sample error title"
bodyText="Sample error description"
defaultBodyText="Sample default error description"
/>`,
errors: Object.entries(renameMap).map(([oldName, newName]) => ({
message: `The ${oldName} prop for ErrorState has been renamed to ${newName}.`,
type: "JSXOpeningElement",
})),
},
{
code: `import ErrorState from '@patternfly/react-component-groups/dist/cjs/ErrorState/index';
<ErrorState errorTitle="Sample error title" />`,
output: `import ErrorState from '@patternfly/react-component-groups/dist/cjs/ErrorState/index';
<ErrorState titleText="Sample error title" />`,
errors: [
{
message: `The errorTitle prop for ErrorState has been renamed to titleText.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import ErrorState from '@patternfly/react-component-groups/dist/esm/ErrorState/index';
<ErrorState errorTitle="Sample error title" />`,
output: `import ErrorState from '@patternfly/react-component-groups/dist/esm/ErrorState/index';
<ErrorState titleText="Sample error title" />`,
errors: [
{
message: `The errorTitle prop for ErrorState has been renamed to titleText.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import ErrorState from '@patternfly/react-component-groups/dist/dynamic/ErrorState';
<ErrorState errorTitle="Sample error title" />`,
output: `import ErrorState from '@patternfly/react-component-groups/dist/dynamic/ErrorState';
<ErrorState titleText="Sample error title" />`,
errors: [
{
message: `The errorTitle prop for ErrorState has been renamed to titleText.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { renameProps } from "../../helpers";
import { Renames } from "../../helpers/renameSinglePropOnNode";

// https://github.com/patternfly/react-component-groups/pull/145

const formatMessage = (oldPropName: string, newPropName: string) =>
`The ${oldPropName} prop for ErrorState has been renamed to ${newPropName}.`;

const renames: Renames = {
ErrorState: {
errorTitle: {
newName: "titleText",
message: formatMessage("errorTitle", "titleText"),
},
errorDescription: {
newName: "bodyText",
message: formatMessage("errorDescription", "bodyText"),
},
defaultErrorDescription: {
newName: "defaultBodyText",
message: formatMessage("defaultErrorDescription", "defaultBodyText"),
},
},
};

module.exports = {
meta: { fixable: "code" },
create: renameProps(renames, "@patternfly/react-component-groups"),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ErrorState } from "@patternfly/react-component-groups";

export const ComponentGroupsErrorStateRenamePropsInput = () => (
<ErrorState
errorTitle="Sample error title"
errorDescription="Sample error description"
defaultErrorDescription="Sample default error description"
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ErrorState } from "@patternfly/react-component-groups";

export const ComponentGroupsErrorStateRenamePropsInput = () => (
<ErrorState
titleText="Sample error title"
bodyText="Sample error description"
defaultBodyText="Sample default error description"
/>
);

0 comments on commit 4f7a867

Please sign in to comment.