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(UnavailableContent): update props to use bodyText #737

Merged
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 @@
### component-groups-unavailableContent-bodyText-props-update [(react-component-groups/#244)](https://github.com/patternfly/react-component-groups/pull/244)

In react-component-groups, we have replaced UnavailableContent's props `unavailableBodyPreStatusLinkText` and `unavailableBodyPostStatusLinkText` with one `bodyText` prop.
Also status page link button has changed to a primary button. Consider capitalizing the `statusPageLinkText` prop.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
const ruleTester = require("../../ruletester");
import * as rule from "./component-groups-unavailableContent-bodyText-props-update";

const renameMessage =
"In react-component-groups, we have replaced UnavailableContent's props `unavailableBodyPreStatusLinkText` and `unavailableBodyPostStatusLinkText` with one `bodyText` prop.";
const statusPageMessage =
"In react-component-groups, UnavailableContent's status page link button has changed to a primary button. Consider capitalizing the `statusPageLinkText` prop.";

const defaultPreStatusText =
"Try refreshing the page. If the problem persists, contact your organization administrator or visit our";
const defaultPostStatusText = "for known outages.";
const defaultStatusText = "status page";

ruleTester.run("componentGroupsUnavailableContentBodyTextPropsUpdate", rule, {
valid: [
{
code: `<UnavailableContent unavailableBodyPreStatusLinkText="Visit our" statusPageLinkText="custom status page" unavailableBodyPostStatusLinkText="for more info." />`,
},
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups'; <UnavailableContent someOtherProp />`,
},
// default import but folder not specified
{
code: `import UnavailableContent from '@patternfly/react-component-groups'; <UnavailableContent statusPageLinkText="custom status page" />`,
},
],
invalid: [
// with both pre and post status link text, default statusPageLinkText
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent
unavailableBodyPreStatusLinkText="Visit our"
unavailableBodyPostStatusLinkText="for more info."
/>`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent
bodyText="Visit our ${defaultStatusText} for more info."

/>`,
errors: [
{
message: renameMessage,
type: "JSXOpeningElement",
},
],
},
// with only pre status link text, default statusPageLinkText
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent unavailableBodyPreStatusLinkText="Visit our" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent bodyText="Visit our ${defaultStatusText} ${defaultPostStatusText}" />`,
errors: [
{
message: renameMessage,
type: "JSXOpeningElement",
},
],
},
// with only post status link text, default statusPageLinkText
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent unavailableBodyPostStatusLinkText="for more info." />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent bodyText="${defaultPreStatusText} ${defaultStatusText} for more info." />`,
errors: [
{
message: renameMessage,
type: "JSXOpeningElement",
},
],
},
// with custom statusPageLinkText
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent statusPageLinkText="custom status page" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent statusPageLinkText="Custom status page" />`,
errors: [
{
message: statusPageMessage,
type: "JSXOpeningElement",
},
],
},
// with custom statusPageLinkText in a variable
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups';
const statusPageLinkText = "custom status page";
<UnavailableContent statusPageLinkText={statusPageLinkText} />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups';
const statusPageLinkText = "custom status page";
<UnavailableContent statusPageLinkText="Custom status page" />`,
errors: [
{
message: statusPageMessage,
type: "JSXOpeningElement",
},
],
},
// with both pre and post status link text, custom statusPageLinkText
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent
unavailableBodyPreStatusLinkText="Visit our"
unavailableBodyPostStatusLinkText="for more info."
statusPageLinkText="custom status page"
/>`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups';
<UnavailableContent
bodyText="Visit our custom status page for more info."

statusPageLinkText="Custom status page"
/>`,
errors: [
{
message: statusPageMessage,
type: "JSXOpeningElement",
},
{
message: renameMessage,
type: "JSXOpeningElement",
},
],
},
// default import
{
code: `import UC from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent';
<UC statusPageLinkText="custom status page" />`,
output: `import UC from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent';
<UC statusPageLinkText="Custom status page" />`,
errors: [
{
message: statusPageMessage,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Rule } from "eslint";
import { JSXAttribute, JSXOpeningElement } from "estree-jsx";
import {
getAllImportsFromPackage,
checkMatchingJSXOpeningElement,
getAttribute,
getAttributeValue,
} from "../../helpers";

// https://github.com/patternfly/react-component-groups/pull/244
module.exports = {
meta: { fixable: "code" },
create: function (context: Rule.RuleContext) {
const basePackage = "@patternfly/react-component-groups";
const componentImports = getAllImportsFromPackage(context, basePackage, [
"UnavailableContent",
]);

return !componentImports.length
? {}
: {
JSXOpeningElement(node: JSXOpeningElement) {
if (!checkMatchingJSXOpeningElement(node, componentImports)) {
return;
}

const statusPageLinkTextProp = getAttribute(
node,
"statusPageLinkText"
);
const statusPageLinkTextString: string =
getAttributeValue(context, statusPageLinkTextProp?.value) ??
"status page";

if (statusPageLinkTextProp && statusPageLinkTextString.length) {
const firstChar = statusPageLinkTextString.charAt(0);

if (firstChar !== firstChar.toUpperCase()) {
context.report({
node,
message:
"In react-component-groups, UnavailableContent's status page link button has changed to a primary button. Consider capitalizing the `statusPageLinkText` prop.",
fix(fixer) {
return fixer.replaceText(
statusPageLinkTextProp.value!,
`"${firstChar.toUpperCase()}${statusPageLinkTextString.slice(
1
)}"`
);
},
});
}
}

const preStatusLinkTextProp = getAttribute(
node,
"unavailableBodyPreStatusLinkText"
);
const postStatusLinkTextProp = getAttribute(
node,
"unavailableBodyPostStatusLinkText"
);

if (!preStatusLinkTextProp && !postStatusLinkTextProp) {
return;
}

const preStatusLinkTextString =
getAttributeValue(context, preStatusLinkTextProp?.value) ??
"Try refreshing the page. If the problem persists, contact your organization administrator or visit our";
const postStatusLinkTextString =
getAttributeValue(context, postStatusLinkTextProp?.value) ??
"for known outages.";

const bodyTextAttribute = `bodyText="${preStatusLinkTextString} ${statusPageLinkTextString} ${postStatusLinkTextString}"`;

context.report({
node,
message:
"In react-component-groups, we have replaced UnavailableContent's props `unavailableBodyPreStatusLinkText` and `unavailableBodyPostStatusLinkText` with one `bodyText` prop.",
fix(fixer) {
if (preStatusLinkTextProp && postStatusLinkTextProp) {
return [
fixer.replaceText(preStatusLinkTextProp, bodyTextAttribute),
fixer.remove(postStatusLinkTextProp),
];
}

return fixer.replaceText(
(preStatusLinkTextProp ||
postStatusLinkTextProp) as JSXAttribute,
bodyTextAttribute
);
},
});
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { UnavailableContent } from "@patternfly/react-component-groups";

export const ComponentGroupsUnavailableContentBodyTextPropsUpdateInput = () => (
<>
<UnavailableContent
unavailableBodyPreStatusLinkText="Visit our"
unavailableBodyPostStatusLinkText="for more info."
statusPageLinkText="custom status page"
/>
<UnavailableContent unavailableBodyPreStatusLinkText="Visit our" />
<UnavailableContent unavailableBodyPostStatusLinkText="for more info." />
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { UnavailableContent } from "@patternfly/react-component-groups";

export const ComponentGroupsUnavailableContentBodyTextPropsUpdateInput = () => (
<>
<UnavailableContent
bodyText="Visit our custom status page for more info."
statusPageLinkText="Custom status page"
/>
<UnavailableContent bodyText="Visit our status page for known outages." />
<UnavailableContent bodyText="Try refreshing the page. If the problem persists, contact your organization administrator or visit our status page for more info." />
</>
);
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
### component-groups-unavailable-content-rename-props [(react-component-groups/#145)](https://github.com/patternfly/react-component-groups/pull/145)

The UnavailableContent component of React Component Groups has had the following props renamed:

| Old prop name | New prop name |
| ----------------------------------- | ------------------ |
| `unavailableTitleText` | `titleText` |
| `unavailableBodyPreStatusLinkText` | `preLinkBodyText` |
| `unavailableBodyPostStatusLinkText` | `postLinkBodyText` |
The UnavailableContent component of React Component Groups has had the `unavailableTitleText` prop renamed to `titleText`.

#### Examples

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
const ruleTester = require("../../ruletester");
import * as rule from "./component-groups-unavailable-content-rename-props";

const renames = [
{ oldName: "unavailableTitleText", newName: "titleText" },
{ oldName: "unavailableBodyPreStatusLinkText", newName: "preLinkBodyText" },
{ oldName: "unavailableBodyPostStatusLinkText", newName: "postLinkBodyText" },
];

const errors = renames.map(
({ oldName, newName }: { oldName: string; newName: string }) => ({
message: `The \`${oldName}\` prop for UnavailableContent has been renamed to \`${newName}\`.`,
const errors = [
{
message:
"The unavailableTitleText prop for UnavailableContent has been renamed to titleText.",
type: "JSXOpeningElement",
})
);
},
];

ruleTester.run("component-groups-unavailable-content-rename-props", rule, {
valid: [
Expand All @@ -25,33 +20,33 @@ ruleTester.run("component-groups-unavailable-content-rename-props", rule, {
],
invalid: [
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups'; <UnavailableContent unavailableTitleText="foo" unavailableBodyPreStatusLinkText="bar" unavailableBodyPostStatusLinkText="bash" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups'; <UnavailableContent titleText="foo" preLinkBodyText="bar" postLinkBodyText="bash" />`,
code: `import { UnavailableContent } from '@patternfly/react-component-groups'; <UnavailableContent unavailableTitleText="foo" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups'; <UnavailableContent titleText="foo" />`,
errors,
},
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups'; const foo = "foo"; const bar = "bar"; const bash = "bash"; <UnavailableContent unavailableTitleText={foo} unavailableBodyPreStatusLinkText={bar} unavailableBodyPostStatusLinkText={bash} />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups'; const foo = "foo"; const bar = "bar"; const bash = "bash"; <UnavailableContent titleText={foo} preLinkBodyText={bar} postLinkBodyText={bash} />`,
code: `import { UnavailableContent } from '@patternfly/react-component-groups'; const foo = "foo"; <UnavailableContent unavailableTitleText={foo} />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups'; const foo = "foo"; <UnavailableContent titleText={foo} />`,
errors,
},
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/js/UnavailableContent'; <UnavailableContent unavailableTitleText="foo" unavailableBodyPreStatusLinkText="bar" unavailableBodyPostStatusLinkText="bash" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/js/UnavailableContent'; <UnavailableContent titleText="foo" preLinkBodyText="bar" postLinkBodyText="bash" />`,
code: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/js/UnavailableContent'; <UnavailableContent unavailableTitleText="foo" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/js/UnavailableContent'; <UnavailableContent titleText="foo" />`,
errors,
},
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/esm/UnavailableContent'; <UnavailableContent unavailableTitleText="foo" unavailableBodyPreStatusLinkText="bar" unavailableBodyPostStatusLinkText="bash" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/esm/UnavailableContent'; <UnavailableContent titleText="foo" preLinkBodyText="bar" postLinkBodyText="bash" />`,
code: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/esm/UnavailableContent'; <UnavailableContent unavailableTitleText="foo" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/esm/UnavailableContent'; <UnavailableContent titleText="foo" />`,
errors,
},
{
code: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UnavailableContent unavailableTitleText="foo" unavailableBodyPreStatusLinkText="bar" unavailableBodyPostStatusLinkText="bash" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UnavailableContent titleText="foo" preLinkBodyText="bar" postLinkBodyText="bash" />`,
code: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UnavailableContent unavailableTitleText="foo" />`,
output: `import { UnavailableContent } from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UnavailableContent titleText="foo" />`,
errors,
},
{
code: `import UC from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UC unavailableTitleText="foo" unavailableBodyPreStatusLinkText="bar" unavailableBodyPostStatusLinkText="bash" />`,
output: `import UC from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UC titleText="foo" preLinkBodyText="bar" postLinkBodyText="bash" />`,
code: `import UC from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UC unavailableTitleText="foo" />`,
output: `import UC from '@patternfly/react-component-groups/dist/dynamic/UnavailableContent'; <UC titleText="foo" />`,
errors,
},
],
Expand Down
Loading
Loading