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(Menu): updated markup for MenuItemAction #590

Merged
merged 2 commits into from
Feb 28, 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
6 changes: 5 additions & 1 deletion packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// if you want your rule to only run when explicitly called for using the --only flag, add the rule name to the below array
export const betaRuleNames: string[] = [];
export const betaRuleNames: string[] = [
"menuItemAction-warn-update-markup",
"menuToggle-warn-iconOnly-toggle",
];

// if you want a rule to have a severity that defaults to warning rather than error, add the rule name to the below array
export const warningRules = [
Expand All @@ -21,6 +24,7 @@ export const warningRules = [
"horizontalSubnav-warn-ariaLabel",
"jumpLinksItem-warn-markup-change",
"label-warn-truncated-default",
"menuItemAction-warn-update-markup",
"menuToggle-warn-iconOnly-toggle",
"nav-warn-flyouts-now-inline",
"notificationBadge-warn-markup-change",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getFromPackage } from "../../helpers";
import { Rule } from "eslint";
import { ImportDeclaration, ImportSpecifier } from "estree-jsx";
import { ImportDeclaration } from "estree-jsx";

// https://github.com/patternfly/patternfly-react/pull/10027
module.exports = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### menuItemAction-warn-update-markup [(#10089)](https://github.com/patternfly/patternfly-react/pull/10089)

The markup for MenuItemAction has been updated. It now uses our Button component internally, has a wrapper around the action button, and no longer renders an icon wrapper inside the action button.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ruleTester = require("../../ruletester");
import * as rule from "./menuItemAction-warn-update-markup";

ruleTester.run("menuItemAction-warn-update-markup", rule, {
valid: [
{
code: `import { MenuItemAction } from '@someOtherPackage';`,
},
],
invalid: [
{
code: `import { MenuItemAction } from '@patternfly/react-core';`,
output: `import { MenuItemAction } from '@patternfly/react-core';`,
errors: [
{
message: `The markup for MenuItemAction has been updated. It now uses our Button component internally, has a wrapper around the action button, and no longer renders an icon wrapper inside the action button.`,
type: "ImportDeclaration",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getFromPackage } from "../../helpers";
import { Rule } from "eslint";
import { ImportDeclaration } from "estree-jsx";

// https://github.com/patternfly/patternfly-react/pull/10089
module.exports = {
meta: {},
create: function (context: Rule.RuleContext) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const menuItemActionImport = imports.find(
(specifier) => specifier.imported.name === "MenuItemAction"
);

return !menuItemActionImport
? {}
: {
ImportDeclaration(node: ImportDeclaration) {
if (
node.specifiers.find(
(specifier) =>
specifier.type === "ImportSpecifier" &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about what if someone imports Patternfly and uses it this way:

import * as PF from '@patternfly/react-core';

<PF.MenuItemAction></PF.MenuItemAction>

I hope nobody does it, I checked the getFromPackage helper and we don't handle this ImportNamespaceSpecifier there either. So if we don't know of any team who would do it, we don't have to worry about it, it would bring too many complications.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's an interesting point! I don't think we had any consumers bring this to our attention during the v5 release (@wise-king-sullyman do you recall if we did?), but worth keeping an eye out for with v6 alpha and beta releases

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's in the same realm as the root problem behind #541, IMO it is probably worth us properly handling all of those import cases, but I don't think ironing those edge cases out is worth holding up the alpha release of the mods.

I think TS will be a big help with these kinds of problems, typing getFromPackage made it pretty obvious that we aren't logically setup for all of the potential import declarations.

specifier.imported.name === menuItemActionImport.imported.name
)
) {
context.report({
node,
message:
"The markup for MenuItemAction has been updated. It now uses our Button component internally, has a wrapper around the action button, and no longer renders an icon wrapper inside the action button.",
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { MenuItemAction } from "@patternfly/react-core";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { MenuItemAction } from "@patternfly/react-core";
Loading