diff --git a/src/pages/Organizations/components/OrganizationForm.jsx b/src/pages/Organizations/components/OrganizationForm.jsx index c848b34e61..1411bc2b4e 100644 --- a/src/pages/Organizations/components/OrganizationForm.jsx +++ b/src/pages/Organizations/components/OrganizationForm.jsx @@ -1,10 +1,13 @@ -import React, { Component } from 'react'; +import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; +import { QuestionCircleIcon } from '@patternfly/react-icons'; + import { withRouter } from 'react-router-dom'; import { Formik, Field } from 'formik'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { + Tooltip, Form, FormGroup, } from '@patternfly/react-core'; @@ -16,8 +19,8 @@ import FormField from '../../../components/FormField'; import FormActionGroup from '../../../components/FormActionGroup/FormActionGroup'; import AnsibleSelect from '../../../components/AnsibleSelect'; import InstanceGroupsLookup from './InstanceGroupsLookup'; -import { required } from '../../../util/validators'; -import { OrganizationsAPI } from '../../../api'; + +import { required, minMaxValue } from '../../../util/validators'; class OrganizationForm extends Component { constructor (props) { @@ -25,7 +28,9 @@ class OrganizationForm extends Component { this.getRelatedInstanceGroups = this.getRelatedInstanceGroups.bind(this); this.handleInstanceGroupsChange = this.handleInstanceGroupsChange.bind(this); + this.maxHostsChange = this.maxHostsChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); + this.readUsers = this.readUsers.bind(this); this.state = { instanceGroups: [], @@ -59,6 +64,14 @@ class OrganizationForm extends Component { return data.results; } + async readUsers (queryParams) { + const { api } = this.props; + console.log(api.readUsers((queryParams, is_superuser))); + console.log(api.readUsers((queryParams))); + return true; + // return api.readUsers((queryParams)); + } + isEditingNewOrganization () { const { organization } = this.props; return !organization.id; @@ -68,6 +81,10 @@ class OrganizationForm extends Component { this.setState({ instanceGroups }); } + maxHostsChange (event) { + console.log('boop'); + } + handleSubmit (values) { const { handleSubmit } = this.props; const { instanceGroups, initialInstanceGroups } = this.state; @@ -83,16 +100,19 @@ class OrganizationForm extends Component { } render () { - const { organization, handleCancel, i18n } = this.props; + const { organization, handleCancel, i18n, is_superuser } = this.props; const { instanceGroups, formIsValid, error } = this.state; const defaultVenv = '/venv/ansible/'; + console.log(organization); + return ( ( @@ -112,6 +132,29 @@ class OrganizationForm extends Component { type="text" label={i18n._(t`Description`)} /> + + {i18n._(t`Max Hosts`)} + {' '} + {( + + + + ) + } + } + validate={minMaxValue(0, 2147483647, i18n)} + onChange={(evt) => this.maxHostsChange(evt)} + // isDisabled={!is_superuser + console.log(is_superuser)} + // isDisabled={this.readUsers} + isDisabled={this.readUsers? true: false} + /> {({ custom_virtualenvs }) => ( custom_virtualenvs && custom_virtualenvs.length > 1 && ( @@ -153,16 +196,27 @@ class OrganizationForm extends Component { } } +FormField.propTypes = { + //consider changing this in FormField.jsx, as many fields may need tooltips in the label + label: PropTypes.oneOfType ([ + PropTypes.object, + PropTypes.string + ]) +} + +console.log() + OrganizationForm.propTypes = { organization: PropTypes.shape(), handleSubmit: PropTypes.func.isRequired, handleCancel: PropTypes.func.isRequired, -}; + }; OrganizationForm.defaultProps = { organization: { name: '', description: '', + max_hosts: '0', custom_virtualenv: '', } }; diff --git a/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx b/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx index a0c7b21ba1..b7ec979a9a 100644 --- a/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx +++ b/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx @@ -56,6 +56,7 @@ class OrganizationDetail extends Component { name, description, custom_virtualenv, + max_hosts, created, modified, summary_fields @@ -75,6 +76,10 @@ class OrganizationDetail extends Component { label={i18n._(t`Description`)} value={description} /> + { + if (typeof value !== 'number' || value > max || value < min) { + return i18n._(t`This field must be a number and have a value between ${min} and ${max}`); + } + return undefined; + }; +}