-
Notifications
You must be signed in to change notification settings - Fork 20
fixes to hasAnimations codemod #845
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
Merged
wise-king-sullyman
merged 2 commits into
patternfly:main
from
gitdallas:fix/animation-tweaks
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,48 +2,30 @@ | |
|
|
||
| This rule adds the `hasAnimations` prop to PatternFly components that support animations. This is an optional enhancement that enables smoother transitions and animations in your UI components. | ||
|
|
||
| **⚠️ Important:** Enabling animations may change the DOM structure of some components. This could affect CSS selectors, testing queries, or other code that relies on the specific DOM structure. Review your code after enabling animations to ensure compatibility. | ||
|
|
||
| The following components will have `hasAnimations` added: | ||
| - AlertGroup | ||
| - DualListSelector | ||
| - DualListSelector (only when `isTree` prop has a truthy value) | ||
| - FormFieldGroupExpandable | ||
| - SearchInput | ||
| - SearchInputExpandable | ||
| - TreeView | ||
| - Table (from @patternfly/react-table) | ||
|
|
||
| **Note:** For DualListSelector, the `hasAnimations` prop will only be added when the `isTree` prop is present and has a truthy value (e.g., `isTree`, `isTree={true}`, `isTree="yes"`, `isTree={1}`). It will not be added when `isTree` is falsy (e.g., `isTree={false}`, `isTree=""`, `isTree={0}`) or when the `isTree` prop is not present at all. | ||
|
|
||
| This rule can only run using the `--only enable-animations` option. | ||
|
|
||
| #### Examples | ||
|
|
||
| In: | ||
|
|
||
| ```jsx | ||
| import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| import { Table } from '@patternfly/react-table'; | ||
|
|
||
| export const Example = () => ( | ||
| <> | ||
| <AlertGroup isLiveRegion> | ||
| {/* alerts */} | ||
| </AlertGroup> | ||
| <TreeView /> | ||
| <Table /> | ||
| </> | ||
| ); | ||
| %inputExample% | ||
| ``` | ||
|
|
||
| Out: | ||
|
|
||
| ```jsx | ||
| import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| import { Table } from '@patternfly/react-table'; | ||
|
|
||
| export const Example = () => ( | ||
| <> | ||
| <AlertGroup hasAnimations isLiveRegion> | ||
| {/* alerts */} | ||
| </AlertGroup> | ||
| <TreeView hasAnimations /> | ||
| <Table hasAnimations /> | ||
| </> | ||
| ); | ||
| %outputExample% | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here as well |
||
| ``` | ||
270 changes: 123 additions & 147 deletions
270
packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enable-animations.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,152 +1,128 @@ | ||
| const ruleTester = require("../../ruletester"); | ||
| import * as rule from "./enable-animations"; | ||
|
|
||
| const valid = [ | ||
| // Components not in target list should be ignored | ||
| "<AlertGroup />", | ||
| "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />", | ||
| "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations={true} />", | ||
| "import { Table } from '@patternfly/react-table'; <Table hasAnimations />", | ||
| // Component not in target components | ||
| "import { Button } from '@patternfly/react-core'; <Button />", | ||
| // DualListSelector without isTree should not get hasAnimations | ||
| "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector />", | ||
| // DualListSelector with isTree={false} should not get hasAnimations | ||
| "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree={false} />", | ||
| // DualListSelector with isTree and hasAnimations already present | ||
| "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree hasAnimations />", | ||
| ]; | ||
|
|
||
| const invalid = [ | ||
| { | ||
| code: "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup />", | ||
| output: "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree />", | ||
| output: "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree={true} />", | ||
| output: "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree={true} hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { TreeView } from '@patternfly/react-core'; <TreeView />", | ||
| output: "import { TreeView } from '@patternfly/react-core'; <TreeView hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { SearchInputExpandable } from '@patternfly/react-core'; <SearchInputExpandable />", | ||
| output: "import { SearchInputExpandable } from '@patternfly/react-core'; <SearchInputExpandable hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable />", | ||
| output: "import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { Table } from '@patternfly/react-table'; <Table />", | ||
| output: "import { Table } from '@patternfly/react-table'; <Table hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: `import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| <> | ||
| <AlertGroup /> | ||
| <TreeView /> | ||
| </>`, | ||
| output: `import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| <> | ||
| <AlertGroup hasAnimations /> | ||
| <TreeView hasAnimations /> | ||
| </>`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| }, | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion />", | ||
| output: "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion hasAnimations />", | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement" | ||
| } | ||
| ] | ||
| } | ||
| ]; | ||
|
|
||
| ruleTester.run("enable-animations", rule, { | ||
| valid: [ | ||
| // No imports, should not trigger | ||
| { | ||
| code: `<AlertGroup />`, | ||
| }, | ||
| // Already has hasAnimations prop | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />`, | ||
| }, | ||
| // Already has hasAnimations with value | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations={true} />`, | ||
| }, | ||
| // Table already has hasAnimations | ||
| { | ||
| code: `import { Table } from '@patternfly/react-table'; <Table hasAnimations />`, | ||
| }, | ||
| // Non-target component should not be affected | ||
| { | ||
| code: `import { Button } from '@patternfly/react-core'; <Button />`, | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| // AlertGroup without hasAnimations | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup />`, | ||
| output: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // DualListSelector without hasAnimations | ||
| { | ||
| code: `import { DualListSelector } from '@patternfly/react-core'; <DualListSelector />`, | ||
| output: `import { DualListSelector } from '@patternfly/react-core'; <DualListSelector hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // TreeView without hasAnimations | ||
| { | ||
| code: `import { TreeView } from '@patternfly/react-core'; <TreeView />`, | ||
| output: `import { TreeView } from '@patternfly/react-core'; <TreeView hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // SearchInput without hasAnimations | ||
| { | ||
| code: `import { SearchInput } from '@patternfly/react-core'; <SearchInput />`, | ||
| output: `import { SearchInput } from '@patternfly/react-core'; <SearchInput hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // FormFieldGroupExpandable without hasAnimations | ||
| { | ||
| code: `import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable />`, | ||
| output: `import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Table from react-table without hasAnimations | ||
| { | ||
| code: `import { Table } from '@patternfly/react-table'; <Table />`, | ||
| output: `import { Table } from '@patternfly/react-table'; <Table hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Multiple components in one file | ||
| { | ||
| code: `import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| <> | ||
| <AlertGroup /> | ||
| <TreeView /> | ||
| </>`, | ||
| output: `import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| <> | ||
| <AlertGroup hasAnimations /> | ||
| <TreeView hasAnimations /> | ||
| </>`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Component with existing props | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion />`, | ||
| output: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations isLiveRegion />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Self-closing and regular tags | ||
| { | ||
| code: `import { DualListSelector } from '@patternfly/react-core'; | ||
| <> | ||
| <DualListSelector /> | ||
| <DualListSelector></DualListSelector> | ||
| </>`, | ||
| output: `import { DualListSelector } from '@patternfly/react-core'; | ||
| <> | ||
| <DualListSelector hasAnimations /> | ||
| <DualListSelector hasAnimations></DualListSelector> | ||
| </>`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| valid: valid, | ||
| invalid: invalid, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick question on this syntax - is this expected? Or would this need to be updated to include examples of the components updated in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, I've got a script that compiles all of these separate readme's together for the "real" readme and inserts the associated tsx files into these spots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super cool - thank you for the context here @wise-king-sullyman