From b8ce6ee29c7ceb8edac394d7ac4545efcf6543ed Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Sat, 12 May 2018 14:05:23 -0400 Subject: [PATCH] Implemented PropTypes on all components --- package.json | 1 + src/components/annotationModal.js | 5 ++ src/components/button.js | 92 +++++++++++++++++++----- src/components/chooseAnnotationModal.js | 8 +++ src/components/contentBottomBar.js | 9 ++- src/components/contentTopBar.js | 20 +++++- src/components/deleteConfirmModal.js | 5 ++ src/components/documentTitle.js | 7 ++ src/components/dropdown.js | 8 ++- src/components/list.js | 24 ++++++- src/components/loadingSpinner.js | 5 ++ src/components/searchResultSnippet.js | 5 ++ src/components/searchResultsBox.js | 12 ++++ src/containers/editorContentContainer.js | 40 ++++++++++- src/containers/editorPageContainer.js | 27 ++++++- src/containers/editorSidebarContainer.js | 21 +++++- src/containers/linkContainer.js | 9 ++- src/containers/readerContentContainer.js | 16 ++++- src/containers/readerPageContainer.js | 13 +++- src/containers/readerSidebarContainer.js | 21 +++++- src/containers/searchContentContainer.js | 15 +++- src/modules/helpers.js | 13 ++++ 22 files changed, 348 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index eb1af05..02fd6a9 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "font-awesome": "^4.7.0", "history": "^4.7.2", "popper.js": "^1.12.6", + "prop-types": "^15.6.1", "react": "^16.0.0", "react-dom": "^16.0.0", "react-redux": "^5.0.6", diff --git a/src/components/annotationModal.js b/src/components/annotationModal.js index d2dbf9e..2633815 100644 --- a/src/components/annotationModal.js +++ b/src/components/annotationModal.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { EditorSubmitButton, EditorCancelButton } from './button' import { DocumentList } from './list' @@ -24,4 +25,8 @@ const AnnotateModal = ({annotationNote}) => +AnnotateModal.propTypes = { + annotationNote: PropTypes.object +} + export default AnnotateModal \ No newline at end of file diff --git a/src/components/button.js b/src/components/button.js index d3c722b..1b40ba0 100644 --- a/src/components/button.js +++ b/src/components/button.js @@ -1,7 +1,9 @@ import React from 'react' +import PropTypes from 'prop-types' import { Link } from 'react-router-dom' import romanize from '../modules/romanize' +import helpers from '../modules/helpers' export const ReaderEditButton = ({onClick}) =>
@@ -51,32 +53,20 @@ export const SearchButton = ({searchInput, onClick}) =>
-export const NewChapterButton = ({onNewChapterClick}) => +export const NewChapterButton = ({onClick}) =>
-
-const documentName = docType => { - switch(docType) { - case 'chapters': - return 'Chapter' - break - case 'notes': - return 'Note' - break - } -} - - export const NewDocumentButton = ({onClick, docType}) =>
@@ -124,4 +114,74 @@ export const EditorDeleteButton = ({onClick}) => \ No newline at end of file + + +ReaderEditButton.propTypes = { + onClick: PropTypes.func, +} + +ReaderAnnotateButton.propTypes = { + onClick: PropTypes.func, +} + +ChapterButton.propTypes = { + chapters: PropTypes.arrayOf(PropTypes.object), + currentChapter: PropTypes.object, + onClick: PropTypes.func, +} + +NoteButton.propTypes = { + notes: PropTypes.arrayOf(PropTypes.object), + currentNotes: PropTypes.object, + onClick: PropTypes.func, +} + +HighlightButton.propTypes = { + highlightToggle: PropTypes.bool, + onClick: PropTypes.func, +} + +SearchButton.propTypes = { + searchInput: PropTypes.string, + onClick: PropTypes.func, +} + +NewChapterButton.propTypes = { + onClick: PropTypes.func, +} + +NewDocumentButton.propTypes = { + docType: PropTypes.string, + onClick: PropTypes.func, +} + +AnnotatorNewButton.propTypes = { + disabled: PropTypes.bool, + onClick: PropTypes.func, +} + +AnnotatorRemoveButton.propTypes = { + disabled: PropTypes.bool, + onClick: PropTypes.func, +} + +EditorToolButton.propTypes = { + glyph: PropTypes.string, + onClick: PropTypes.func, +} + +EditorDeleteToolButton.propTypes = { + disabled: PropTypes.bool, +} + +EditorCancelButton.propTypes = { + onClick: PropTypes.func, +} + +EditorSubmitButton.propTypes = { + onClick: PropTypes.func, +} + +EditorDeleteButton.propTypes = { + onClick: PropTypes.func, +} \ No newline at end of file diff --git a/src/components/chooseAnnotationModal.js b/src/components/chooseAnnotationModal.js index b25114a..a40f090 100644 --- a/src/components/chooseAnnotationModal.js +++ b/src/components/chooseAnnotationModal.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { EditorSubmitButton, EditorCancelButton } from './button' import { DocumentList } from './list' @@ -28,4 +29,11 @@ const ChooseAnnotationModal = ({notes, annotationNote, onSubmitClick, selectAnno
+ChooseAnnotationModal.propTypes = { + notes: PropTypes.arrayOf(PropTypes.object), + annotationNote: PropTypes.object, + onSubmitClick: PropTypes.func, + selectAnnotationNote: PropTypes.func, +} + export default ChooseAnnotationModal \ No newline at end of file diff --git a/src/components/contentBottomBar.js b/src/components/contentBottomBar.js index 0833960..9b77de9 100644 --- a/src/components/contentBottomBar.js +++ b/src/components/contentBottomBar.js @@ -1,4 +1,6 @@ import React from 'react' +import PropTypes from 'prop-types' + import { EditorCancelButton, EditorSubmitButton } from '../components/button' export const EditModeBottomBar = ({cancelEdit, onSubmitClick}) => @@ -9,4 +11,9 @@ export const EditModeBottomBar = ({cancelEdit, onSubmitClick}) =>
- \ No newline at end of file + + +EditModeBottomBar.propTypes = { + cancelEdit: PropTypes.func, + onSubmitClick: PropTypes.func, +} \ No newline at end of file diff --git a/src/components/contentTopBar.js b/src/components/contentTopBar.js index d14fd15..0046402 100644 --- a/src/components/contentTopBar.js +++ b/src/components/contentTopBar.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { ReaderAnnotateButton, ReaderEditButton, EditorToolButton, EditorDeleteToolButton, AnnotatorNewButton, AnnotatorRemoveButton } from './button' @@ -35,4 +36,21 @@ export const AnnotateModeTopBar = ({onNewAnnotationClick, onRemoveAnnotationClic
- \ No newline at end of file + + +ReadModeTopBar.propTypes = { + setMode: PropTypes.func, +} + +EditModeTopBar.propTypes = { + editorState: PropTypes.object, + onToolButtonClick: PropTypes.func, + disabled: PropTypes.bool, +} + +AnnotateModeTopBar.propTypes = { + onNewAnnotationClick: PropTypes.func, + onRemoveAnnotationClick: PropTypes.func, + onAddDisabled: PropTypes.bool, + removeDisabled: PropTypes.bool, +} \ No newline at end of file diff --git a/src/components/deleteConfirmModal.js b/src/components/deleteConfirmModal.js index cf880ae..d57ef9b 100644 --- a/src/components/deleteConfirmModal.js +++ b/src/components/deleteConfirmModal.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { EditorDeleteButton, EditorCancelButton } from './button' @@ -20,4 +21,8 @@ const DeleteConfirmModal = ({onDeleteConfirm}) => +DeleteConfirmModal.propTypes = { + onDeleteConfirm: PropTypes.func, +} + export default DeleteConfirmModal \ No newline at end of file diff --git a/src/components/documentTitle.js b/src/components/documentTitle.js index b811c73..2e14958 100644 --- a/src/components/documentTitle.js +++ b/src/components/documentTitle.js @@ -1,4 +1,6 @@ import React from 'react' +import PropTypes from 'prop-types' + import romanize from '../modules/romanize' const DocumentTitle = ({docType, currentDocument}) => @@ -9,4 +11,9 @@ const DocumentTitle = ({docType, currentDocument}) => {currentDocument.title ? currentDocument.title : ''} +DocumentTitle.propTypes = { + docType: PropTypes.string, + currentDocument: PropTypes.object +} + export default DocumentTitle \ No newline at end of file diff --git a/src/components/dropdown.js b/src/components/dropdown.js index 6de7f2b..132450c 100644 --- a/src/components/dropdown.js +++ b/src/components/dropdown.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' export const DocTypeDropdown = ({docType, setDocType}) =>
@@ -10,4 +11,9 @@ export const DocTypeDropdown = ({docType, setDocType}) => setDocType('notes')}>Notes setDocType('tags')}>Tags
- \ No newline at end of file + + +DocTypeDropdown.propTypes = { + docType: PropTypes.string, + setDocType: PropTypes.func +} \ No newline at end of file diff --git a/src/components/list.js b/src/components/list.js index ef7c9a1..8a046e2 100644 --- a/src/components/list.js +++ b/src/components/list.js @@ -1,4 +1,6 @@ import React from 'react' +import PropTypes from 'prop-types' + import { ChapterButton, NoteButton } from './button' export const DocumentList = ({notes, chapters, currentDocument, onDocumentClick, docType}) => @@ -23,4 +25,24 @@ export const NoteList = ({notes, currentNote, onNoteClick}) => {notes.map(note => onNoteClick(note.id, 'notes')} /> )} - \ No newline at end of file + + +DocumentList.propTypes = { + notes: PropTypes.arrayOf(PropTypes.object), + chapters: PropTypes.arrayOf(PropTypes.object), + currentDocument: PropTypes.object, + onDocumentClick: PropTypes.func, + docType: PropTypes.string, +} + +ChapterList.propTypes = { + chapters: PropTypes.arrayOf(PropTypes.object), + currentDocument: PropTypes.object, + onChapterClick: PropTypes.func, +} + +NoteList.propTypes = { + notes: PropTypes.arrayOf(PropTypes.object), + currentDocument: PropTypes.object, + onNoteClick: PropTypes.func, +} \ No newline at end of file diff --git a/src/components/loadingSpinner.js b/src/components/loadingSpinner.js index 961dfc9..347b693 100644 --- a/src/components/loadingSpinner.js +++ b/src/components/loadingSpinner.js @@ -1,8 +1,13 @@ import React from 'react' +import PropTypes from 'prop-types' const LoadingSpinner = ({size=2}) =>
+LoadingSpinner.propTypes = { + size: PropTypes.number, +} + export default LoadingSpinner \ No newline at end of file diff --git a/src/components/searchResultSnippet.js b/src/components/searchResultSnippet.js index b2e30f4..ace54c8 100644 --- a/src/components/searchResultSnippet.js +++ b/src/components/searchResultSnippet.js @@ -1,8 +1,13 @@ import React from 'react' +import PropTypes from 'prop-types' const SearchResultSnippet = ({snippet}) =>
{snippet}...
+SearchResultSnippet.propTypes = { + snippet: PropTypes.string, +} + export default SearchResultSnippet \ No newline at end of file diff --git a/src/components/searchResultsBox.js b/src/components/searchResultsBox.js index a005d34..2dd8f84 100644 --- a/src/components/searchResultsBox.js +++ b/src/components/searchResultsBox.js @@ -1,4 +1,6 @@ import React from 'react' +import PropTypes from 'prop-types' + import SearchResultSnippet from './searchResultSnippet' const SearchResultGroup = ({docType, docTitle, results}) => @@ -24,4 +26,14 @@ const SearchResultsBox = ({searchResults}) => } +SearchResultGroup.propType = { + docType: PropTypes.string, + docTitle: PropTypes.string, + results: PropTypes.array, +} + +SearchResultsBox.propTypes = { + searchResults: PropTypes.objectOf(PropTypes.array) +} + export default SearchResultsBox \ No newline at end of file diff --git a/src/containers/editorContentContainer.js b/src/containers/editorContentContainer.js index e2cd170..4c5e048 100644 --- a/src/containers/editorContentContainer.js +++ b/src/containers/editorContentContainer.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { connect } from 'react-redux' import { Editor } from 'draft-js' @@ -8,7 +9,24 @@ import actions from '../actions' import DocumentTitle from '../components/documentTitle' import LoadingSpinner from '../components/loadingSpinner' -const EditorContent = ({currentDocument, editorState, mode, handleKeyCommand, onChangeEditorState, onToolButtonClick, setMode, cancelEdit, onSubmitClick, documentTitleInput, onDocumentTitleChange, onNewAnnotationClick, annotateKeyBindings, onRemoveAnnotationClick, docType, loadingToggle}) => +const EditorContent = ({ + currentDocument, + editorState, + docType, + mode, + loadingToggle, + handleKeyCommand, + onChangeEditorState, + onToolButtonClick, + setMode, + cancelEdit, + onSubmitClick, + documentTitleInput, + onDocumentTitleChange, + onNewAnnotationClick, + annotateKeyBindings, + onRemoveAnnotationClick, +}) =>
{loadingToggle === true && @@ -73,6 +91,7 @@ const mapDispatchToProps = dispatch => { dispatch(actions.handleEditorKeyCommand(editorState, command)) }, annotateKeyBindings: () => { + // Prevents editor input in Annotation Mode return 'handled' }, setMode: (mode) => { @@ -96,6 +115,25 @@ const mapDispatchToProps = dispatch => { } } +EditorContent.propTypes = { + currentDocument: PropTypes.object, + editorState: PropTypes.object, + documentTitleInput: PropTypes.string, + docType: PropTypes.string, + mode: PropTypes.string, + loadingToggle: PropTypes.bool, + handleKeyCommand: PropTypes.func, + onChangeEditorState: PropTypes.func, + onToolButtonClick: PropTypes.func, + setMode: PropTypes.func, + cancelEdit: PropTypes.func, + onSubmitClick: PropTypes.func, + onDocumentTitleChange: PropTypes.func, + onNewAnnotationClick: PropTypes.func, + annotateKeyBindings: PropTypes.func, + onRemoveAnnotationClick: PropTypes.func, +} + const EditorContentContainer = connect(mapStateToProps, mapDispatchToProps)(EditorContent) export default EditorContentContainer \ No newline at end of file diff --git a/src/containers/editorPageContainer.js b/src/containers/editorPageContainer.js index 8aaf647..f52fae5 100644 --- a/src/containers/editorPageContainer.js +++ b/src/containers/editorPageContainer.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { connect } from 'react-redux' import { EditorState } from 'draft-js' @@ -12,7 +13,18 @@ import DeleteConfirmModal from '../components/deleteConfirmModal' import AnnotationModal from '../components/annotationModal' import ChooseAnnotationModal from '../components/chooseAnnotationModal' -const EditorPage = ({notes, currentDocument, docType, annotationNote, onDeleteConfirm, onSubmitAnnotationClick, selectAnnotationNote, selectionState, editorState, loadingToggle}) => +const EditorPage = ({ + notes, + currentDocument, + annotationNote, + editorState, + docType, + loadingToggle, + onDeleteConfirm, + onSubmitAnnotationClick, + selectAnnotationNote, + selectionState, +}) =>
@@ -59,6 +71,19 @@ const mapDispatchToProps = dispatch => { } } +EditorPage.propTypes = { + notes: PropTypes.arrayOf(PropTypes.object), + currentDocument: PropTypes.object, + annotationNote: PropTypes.object, + editorState: PropTypes.object, + selectionState: PropTypes.object, + docType: PropTypes.string, + loadingToggle: PropTypes.bool, + onDeleteConfirm: PropTypes.func, + onSubmitAnnotationClick: PropTypes.func, + selectAnnotationNote: PropTypes.func, +} + const EditorPageContainer = connect(mapStateToProps, mapDispatchToProps)(EditorPage) export default EditorPageContainer \ No newline at end of file diff --git a/src/containers/editorSidebarContainer.js b/src/containers/editorSidebarContainer.js index 6ecf383..9921ed3 100644 --- a/src/containers/editorSidebarContainer.js +++ b/src/containers/editorSidebarContainer.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { connect } from 'react-redux' import actions from '../actions' import { DocumentList } from '../components/list' @@ -7,7 +8,15 @@ import { DocTypeDropdown } from '../components/dropdown' import SidebarSpacer from '../components/sidebarSpacer' import { push } from 'react-router-redux' -const EditorSidebar = ({notes, chapters, docType, currentDocument, onDocumentClick, onNewDocumentClick, setDocType}) => +const EditorSidebar = ({ + chapters, + notes, + currentDocument, + docType, + onDocumentClick, + onNewDocumentClick, + setDocType, +}) =>