From 58ed38f7b6a7967c4088ed6e23f6b763e6c76c08 Mon Sep 17 00:00:00 2001 From: Will Gutierrez Date: Sat, 5 Jun 2021 22:02:10 -0700 Subject: [PATCH] add nested propTypes for object & array props #9365 --- app/javascript/components/App.js | 37 +++++++++++++++++-- app/javascript/components/CommentReplies.js | 2 +- .../components/CommentsContainer.js | 4 +- app/javascript/components/CommentsList.js | 4 +- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/javascript/components/App.js b/app/javascript/components/App.js index 600fa7fa51..1d0ae7afe8 100644 --- a/app/javascript/components/App.js +++ b/app/javascript/components/App.js @@ -52,10 +52,39 @@ const App = ({ } App.propTypes = { - currentUser: PropTypes.object, - elementText: PropTypes.object.isRequired, - initialComments: PropTypes.array.isRequired, - node: PropTypes.object.isRequired + currentUser: PropTypes.shape({ + canModerate: PropTypes.bool, + id: PropTypes.number, + role: PropTypes.string, + status: PropTypes.number + }), + elementText: PropTypes.exact({ + commentFormPlaceholder: PropTypes.string.isRequired, + commentsHeaderText: PropTypes.string.isRequired, + commentPreviewText: PropTypes.string.isRequired, + commentPublishText: PropTypes.string.isRequired, + userCommentedText: PropTypes.string.isRequired + }).isRequired, + initialComments: PropTypes.arrayOf( + PropTypes.shape({ + authorId: PropTypes.number.isRequired, + authorPicFilename: PropTypes.string, + authorPicUrl: PropTypes.string, + authorUsername: PropTypes.string.isRequired, + commentId: PropTypes.number.isRequired, + commentName: PropTypes.string, + createdAt: PropTypes.string.isRequired, + htmlCommentText: PropTypes.string.isRequired, + rawCommentText: PropTypes.string.isRequired, + replies: PropTypes.array, + replyTo: PropTypes.number, + timeCreatedString: PropTypes.string.isRequired + }) + ).isRequired, + node: PropTypes.exact({ + nodeId: PropTypes.number.isRequired, + nodeAuthorId: PropTypes.number.isRequired + }).isRequired }; export default App; diff --git a/app/javascript/components/CommentReplies.js b/app/javascript/components/CommentReplies.js index 5a62bdde5b..eb9049148e 100644 --- a/app/javascript/components/CommentReplies.js +++ b/app/javascript/components/CommentReplies.js @@ -34,7 +34,7 @@ const CommentReplies = ({ } CommentReplies.propTypes = { - children: PropTypes.array, + children: PropTypes.arrayOf(PropTypes.element).isRequired, commentId: PropTypes.number.isRequired, isReplyFormVisible: PropTypes.bool.isRequired, handleReplyFormToggle: PropTypes.func, diff --git a/app/javascript/components/CommentsContainer.js b/app/javascript/components/CommentsContainer.js index b84ef6b4a3..082eb70f96 100644 --- a/app/javascript/components/CommentsContainer.js +++ b/app/javascript/components/CommentsContainer.js @@ -159,9 +159,9 @@ const CommentsContainer = ({ } CommentsContainer.propTypes = { - initialCommentFormToggleState: PropTypes.object.isRequired, + initialCommentFormToggleState: PropTypes.objectOf(PropTypes.bool).isRequired, initialComments: PropTypes.array.isRequired, - initialTextAreaValues: PropTypes.object.isRequired, + initialTextAreaValues: PropTypes.objectOf(PropTypes.string).isRequired, nodeId: PropTypes.number.isRequired }; diff --git a/app/javascript/components/CommentsList.js b/app/javascript/components/CommentsList.js index c38bd5d4fc..5de1e96365 100644 --- a/app/javascript/components/CommentsList.js +++ b/app/javascript/components/CommentsList.js @@ -141,7 +141,7 @@ const CommentsList = ({ }; CommentsList.propTypes = { - commentFormsVisibility: PropTypes.object.isRequired, + commentFormsVisibility: PropTypes.objectOf(PropTypes.bool).isRequired, comments: PropTypes.array.isRequired, currentUser: PropTypes.object, handleCreateComment: PropTypes.func.isRequired, @@ -150,7 +150,7 @@ CommentsList.propTypes = { handleTextAreaChange: PropTypes.func.isRequired, handleUpdateComment: PropTypes.func.isRequired, setTextAreaValues: PropTypes.func.isRequired, - textAreaValues: PropTypes.object.isRequired + textAreaValues: PropTypes.objectOf(PropTypes.string).isRequired }; export default CommentsList;