Skip to content

Commit

Permalink
feat(CG - NotAuthorized): rename props
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora committed Jul 25, 2024
1 parent d8e33d8 commit f6cdf48
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### component-groups-notAuthorized-rename-props [(react-component-groups/#145)](https://github.com/patternfly/react-component-groups/pull/145)

In react-component-groups, we've renamed NotAuthorized's props `description` to `bodyText` and `title` to `titleText`.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const ruleTester = require("../../ruletester");
import * as rule from "./component-groups-notAuthorized-rename-props";

const renameMap = {
description: "bodyText",
title: "titleText",
};

const errors = Object.entries(renameMap).map(([oldName, newName]) => ({
message: `The ${oldName} prop for NotAuthorized has been renamed to ${newName}.`,
type: "JSXOpeningElement",
}));

ruleTester.run("component-groups-notAuthorized-rename-props", rule, {
valid: [
{
code: `<NotAuthorized description="" />`,
},
{
code: `<NotAuthorized title="" />`,
},
{
code: `import { NotAuthorized } from '@patternfly/react-component-groups'; <NotAuthorized someOtherProp />`,
},
],
invalid: [
{
code: `import { NotAuthorized } from '@patternfly/react-component-groups';
<NotAuthorized
description="Description text"
title="Title text"
/>`,
output: `import { NotAuthorized } from '@patternfly/react-component-groups';
<NotAuthorized
bodyText="Description text"
titleText="Title text"
/>`,
errors,
},
{
code: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index';
<NotAuthorized
description="Description text"
title="Title text"
/>`,
output: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index';
<NotAuthorized
bodyText="Description text"
titleText="Title text"
/>`,
errors,
},
{
code: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index';
<NotAuthorized
description="Description text"
title="Title text"
/>`,
output: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index';
<NotAuthorized
bodyText="Description text"
titleText="Title text"
/>`,
errors,
},
{
code: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
<NotAuthorized
description="Description text"
title="Title text"
/>`,
output: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
<NotAuthorized
bodyText="Description text"
titleText="Title text"
/>`,
errors,
},
{
code: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
<NotAuth
description="Description text"
title="Title text"
/>`,
output: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
<NotAuth
bodyText="Description text"
titleText="Title text"
/>`,
errors,
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 NotAuthorized has been renamed to ${newPropName}.`;

const renames: Renames = {
NotAuthorized: {
description: {
newName: "bodyText",
message: formatMessage("description", "bodyText"),
},
title: {
newName: "titleText",
message: formatMessage("title", "titleText"),
},
},
};

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,5 @@
import { NotAuthorized } from "@patternfly/react-component-groups";

export const ComponentGroupsNotAuthorizedRenamePropsInput = () => (
<NotAuthorized description="Description text" title="Title text" />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NotAuthorized } from "@patternfly/react-component-groups";

export const ComponentGroupsNotAuthorizedRenamePropsInput = () => (
<NotAuthorized bodyText="Description text" titleText="Title text" />
);

0 comments on commit f6cdf48

Please sign in to comment.