Skip to content

Convert Preferences into a function component #2335

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
merged 7 commits into from
Aug 11, 2023

Conversation

lindapaiste
Copy link
Collaborator

Progress on issue #824

Continue breaking up PR #2054 into more manageable pieces. Here I am converting Preferences from a class component to a function component while keeping all the logic the same. I'm not including the improvements to the font size input which were causing tests to fail. I will submit those separately.

Should be merged after #2329

Changes:

  • Preferences
    • Convert to a function component.
    • Use Redux hooks useSelector and useDispatch instead of connect HOC.
    • Use useTranslate hook instead of withTranslation HOC.
    • Use a useRef hook instead of property this.fontSizeInput.
    • Use a useState hook for the fontSize state. I tried to keep this as similar to before as possible so I made the state be an object even though this is silly.
  • Preferences.unit.test.jsx
    • The component has no more props.
    • Helper function subject now takes the initial state as an argument.
      • Remove all beforeAll effects, which were used to set props.
      • Call subject with the relevant initial state for each test, ie. subject({ lintWarning: false }).
    • Remove mocks of functions setLintWarning etc. and spy on on the action creator instead.
      • I'm calling this object of spied-on action creators props so that tests like expect(props.setFontSize).toHaveBeenCalledTimes(1); will work the same as before, even though it's not actually a prop.
    • No changes to any expect conditions as there is no change to behavior.
  • IDEView
    • Remove all props passed to <Preferences/>.
    • Remove unused or unecessary propTypes.

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

@raclim raclim merged commit d2f5832 into processing:develop Aug 11, 2023
@lindapaiste lindapaiste deleted the refactor/prefs-fc branch August 11, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants