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

Add React PropTypes for Array and Object Props #9751

Merged
merged 1 commit into from
Jun 10, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Jun 7, 2021

Part of a React rewrite of the comment system, see #9365.

See React docs on PropTypes. This PR adds PropType checking for array and object data that's passed down as props throughout the App.

BEFORE: check to see if currentUser is an object.

App.propTypes = {
  currentUser: PropTypes.object
};

AFTER: check to see if currentUser is an object AND typecheck its properties:

App.propTypes = {
  currentUser: PropTypes.shape({
    canModerate: PropTypes.bool,
    id: PropTypes.number,
    role: PropTypes.string,
    status: PropTypes.number
  })
};

This increases the long-term maintainability of this project. PropTypes help with debugging and ensure that the data the app receives is valid.

@jywarren mentioned writing functional tests to make sure the controller is sending valid data to the client... IMO PropTypes can easily substitute for functional tests! 😄

(Example: PropTypes logs an error to the console if data doesn't match expectations:)
Screen Shot 2021-06-06 at 8 20 55 PM


(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)

@gitpod-io
Copy link

gitpod-io bot commented Jun 7, 2021

@codeclimate
Copy link

codeclimate bot commented Jun 7, 2021

Analysis results are not available for those commits

View more on Code Climate.

@codecov
Copy link

codecov bot commented Jun 7, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@9c43a77). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9751   +/-   ##
=======================================
  Coverage        ?   82.06%           
=======================================
  Files           ?       98           
  Lines           ?     5932           
  Branches        ?        0           
=======================================
  Hits            ?     4868           
  Misses          ?     1064           
  Partials        ?        0           

Copy link
Contributor

@RuthNjeri RuthNjeri left a comment

Choose a reason for hiding this comment

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

Great job @noi5e, it looks good to me!

@jywarren jywarren merged commit c1c64c2 into publiclab:main Jun 10, 2021
@jywarren
Copy link
Member

Thank you so much @noi5e - great work!

@noi5e noi5e deleted the react-nested-proptypes branch June 10, 2021 23:29
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants