From aec3d5433830530aa83a192d98ce9d1a8cd6cf40 Mon Sep 17 00:00:00 2001 From: Filip Hlavac Date: Wed, 2 Oct 2019 13:20:03 +0200 Subject: [PATCH] Added PropTypes and sorted component definitions --- .../components/top-navbar/configuration.jsx | 5 ++++ app/javascript/components/top-navbar/help.jsx | 9 ++++++ .../components/top-navbar/recursive-props.js | 5 ++++ .../components/top-navbar/right-section.jsx | 7 +---- .../components/top-navbar/user-options.jsx | 29 +++++++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/app/javascript/components/top-navbar/configuration.jsx b/app/javascript/components/top-navbar/configuration.jsx index b893859868a7..084ec4dcae31 100644 --- a/app/javascript/components/top-navbar/configuration.jsx +++ b/app/javascript/components/top-navbar/configuration.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; const Configuration = ({ opsExplorerAllowed, @@ -16,4 +17,8 @@ const Configuration = ({ ) ); +Configuration.propTypes = { + opsExplorerAllowed: PropTypes.bool.isRequired, +}; + export default Configuration; diff --git a/app/javascript/components/top-navbar/help.jsx b/app/javascript/components/top-navbar/help.jsx index bee02009bb08..a7cc5e043511 100644 --- a/app/javascript/components/top-navbar/help.jsx +++ b/app/javascript/components/top-navbar/help.jsx @@ -2,6 +2,8 @@ import React from 'react'; import { Dropdown, Icon, MenuItem } from 'patternfly-react'; +import PropTypes from 'prop-types'; +import { helpMenuProps, recursiveHelpMenuProps } from './recursive-props'; const Help = ({ helpMenu, @@ -57,4 +59,11 @@ const Help = ({ ))) ); +Help.propTypes = { + helpMenu: PropTypes.arrayOf(PropTypes.shape({ + ...helpMenuProps, + items: PropTypes.arrayOf(PropTypes.shape(recursiveHelpMenuProps)), + })).isRequired, +}; + export default Help; diff --git a/app/javascript/components/top-navbar/recursive-props.js b/app/javascript/components/top-navbar/recursive-props.js index 7ba3c5cebc94..395f5b9793e1 100644 --- a/app/javascript/components/top-navbar/recursive-props.js +++ b/app/javascript/components/top-navbar/recursive-props.js @@ -1,5 +1,10 @@ import PropTypes from 'prop-types'; +export const groupProps = { + description: PropTypes.string.isRequired, + id: PropTypes.number.isRequired, +}; + export const helpMenuProps = { id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, diff --git a/app/javascript/components/top-navbar/right-section.jsx b/app/javascript/components/top-navbar/right-section.jsx index 1dc561600d1c..407ae059019b 100644 --- a/app/javascript/components/top-navbar/right-section.jsx +++ b/app/javascript/components/top-navbar/right-section.jsx @@ -6,7 +6,7 @@ import Help from './help'; import Configuration from './configuration'; import UserOptions from './user-options'; import { - helpMenuProps, recursiveHelpMenuProps, userMenuProps, recursiveUserMenuProps, + groupProps, helpMenuProps, recursiveHelpMenuProps, userMenuProps, recursiveUserMenuProps, } from './recursive-props'; const RightSection = ({ @@ -25,11 +25,6 @@ const RightSection = ({ ); -const groupProps = { - description: PropTypes.string.isRequired, - id: PropTypes.number.isRequired, -}; - RightSection.defaultProps = { currentUser: null, }; diff --git a/app/javascript/components/top-navbar/user-options.jsx b/app/javascript/components/top-navbar/user-options.jsx index b1da40d0b9ce..9e032326aa7d 100644 --- a/app/javascript/components/top-navbar/user-options.jsx +++ b/app/javascript/components/top-navbar/user-options.jsx @@ -2,6 +2,11 @@ import React from 'react'; import { Dropdown, Icon, MenuItem } from 'patternfly-react'; +import PropTypes from 'prop-types'; +import { + groupProps, recursiveUserMenuProps, userMenuProps, +} from './recursive-props'; + const UserOptions = ({ currentUser, applianceName, miqGroups, currentGroup, userMenu, @@ -107,4 +112,28 @@ const UserOptions = ({ ); +UserOptions.defaultProps = { + currentUser: null, +}; + +UserOptions.propTypes = { + currentUser: PropTypes.shape({ + name: PropTypes.string.isRequired, + userid: PropTypes.string.isRequired, + }), + applianceName: PropTypes.string.isRequired, + miqGroups: PropTypes.arrayOf( + PropTypes.shape({ + ...groupProps, + }).isRequired, + ).isRequired, + currentGroup: PropTypes.shape({ + ...groupProps, + }).isRequired, + userMenu: PropTypes.arrayOf(PropTypes.shape({ + ...userMenuProps, + items: PropTypes.arrayOf(PropTypes.shape(recursiveUserMenuProps)), + })).isRequired, +}; + export default UserOptions;