From 4814676257ad95c466c2749027fb252652c01322 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 14 Apr 2023 15:15:45 -0400 Subject: [PATCH] feat(expandableSection): Add event to onToggle --- packages/eslint-plugin-pf-codemods/index.js | 2 +- .../expandableSection-onToggle-event-added.js | 7 +++++ .../expandableSection-onToggle-event-added.js | 5 ++++ packages/pf-codemods/README.md | 29 +++++++++++++++++++ test/test.tsx | 2 ++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 packages/eslint-plugin-pf-codemods/lib/rules/v5/expandableSection-onToggle-event-added.js create mode 100644 packages/eslint-plugin-pf-codemods/test/rules/v5/expandableSection-onToggle-event-added.js diff --git a/packages/eslint-plugin-pf-codemods/index.js b/packages/eslint-plugin-pf-codemods/index.js index 8c438c602..e90fd1476 100644 --- a/packages/eslint-plugin-pf-codemods/index.js +++ b/packages/eslint-plugin-pf-codemods/index.js @@ -1,5 +1,5 @@ // if you want your rule to only run when explicitly called for using the --only flag, add the rule name to the below array -const betaRuleNames = ["fileUploadField-cb-param-updates"]; +const betaRuleNames = ["expandableSection-onToggle-event-added", "fileUploadField-cb-param-updates"]; const createListOfRules = (version, includeBeta = false) => { const rules = {}; diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/v5/expandableSection-onToggle-event-added.js b/packages/eslint-plugin-pf-codemods/lib/rules/v5/expandableSection-onToggle-event-added.js new file mode 100644 index 000000000..7a490e395 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/lib/rules/v5/expandableSection-onToggle-event-added.js @@ -0,0 +1,7 @@ +const { addCallbackParam } = require("../../helpers"); + +// https://github.com/patternfly/patternfly-react/pull/8880 +module.exports = { + meta: { fixable: "code" }, + create: addCallbackParam(["ExpandableSection"], { onToggle: "_event" }), +}; diff --git a/packages/eslint-plugin-pf-codemods/test/rules/v5/expandableSection-onToggle-event-added.js b/packages/eslint-plugin-pf-codemods/test/rules/v5/expandableSection-onToggle-event-added.js new file mode 100644 index 000000000..2cfc0ae3d --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/test/rules/v5/expandableSection-onToggle-event-added.js @@ -0,0 +1,5 @@ +const { addCallbackParamTester } = require("../../testHelpers"); + +addCallbackParamTester('expandableSection-onToggle-event-added', 'ExpandableSection', 'onToggle') + + \ No newline at end of file diff --git a/packages/pf-codemods/README.md b/packages/pf-codemods/README.md index fa23ba88b..eec9d4532 100644 --- a/packages/pf-codemods/README.md +++ b/packages/pf-codemods/README.md @@ -968,6 +968,35 @@ Out: ``` +### expandableSection-onToggle-event-added [(#8880)](https://github.com/patternfly/patternfly-react/pull/8880) + +**Not yet included in pf-react** + +We've updated the `onToggle` prop for ExpandableSection so that the `event` parameter is the first parameter. Handlers may require an update. + +#### Examples + +In: + +```jsx + handler(id)} /> +const handler1 = (id) => {}; + +function handler2(id) {}; + +``` + +Out: + +```jsx + handler(id)} /> +const handler1 = (_event, id) => {}; + +function handler2(_event, id) {}; + +``` + + ### fileUpload-remove-onChange [(#8155)](https://github.com/patternfly/patternfly-react/pull/8155) We've removed the deprecated `onChange` prop. This rule will remove the prop from the FileUpload component and suggest replacing it with the `onFileInputChange`, `onTextChange`, `onDataChange`, and `onClearClick` props as needed. diff --git a/test/test.tsx b/test/test.tsx index eb8f3b5c0..5e8d9ff97 100644 --- a/test/test.tsx +++ b/test/test.tsx @@ -40,6 +40,7 @@ import { EmptyStatePrimary as ESP, EmptyStateSecondaryActions, EmptyStateVariant, + ExpandableSection, FileUpload, FileUploadField, KebabToggle, @@ -126,6 +127,7 @@ const myVariant = EmptyStateVariant.small; + handler(foo)} /> textHandler(bar)} />