Skip to content

Commit

Permalink
Added PropTypes and sorted component definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
fhlavac committed Oct 3, 2019
1 parent f5111d1 commit aec3d54
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
5 changes: 5 additions & 0 deletions app/javascript/components/top-navbar/configuration.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';

const Configuration = ({
opsExplorerAllowed,
Expand All @@ -16,4 +17,8 @@ const Configuration = ({
)
);

Configuration.propTypes = {
opsExplorerAllowed: PropTypes.bool.isRequired,
};

export default Configuration;
9 changes: 9 additions & 0 deletions app/javascript/components/top-navbar/help.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,4 +59,11 @@ const Help = ({
)))
);

Help.propTypes = {
helpMenu: PropTypes.arrayOf(PropTypes.shape({
...helpMenuProps,
items: PropTypes.arrayOf(PropTypes.shape(recursiveHelpMenuProps)),
})).isRequired,
};

export default Help;
5 changes: 5 additions & 0 deletions app/javascript/components/top-navbar/recursive-props.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
7 changes: 1 addition & 6 deletions app/javascript/components/top-navbar/right-section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand All @@ -25,11 +25,6 @@ const RightSection = ({
</React.Fragment>
);

const groupProps = {
description: PropTypes.string.isRequired,
id: PropTypes.number.isRequired,
};

RightSection.defaultProps = {
currentUser: null,
};
Expand Down
29 changes: 29 additions & 0 deletions app/javascript/components/top-navbar/user-options.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -107,4 +112,28 @@ const UserOptions = ({
</Dropdown>
);

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;

0 comments on commit aec3d54

Please sign in to comment.