From e7fead0f2c0945470752302daa60ba16628a6aaf Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Thu, 16 Jan 2020 16:46:13 -0800 Subject: [PATCH] update Formik formatting to remove warnings --- .../CodeMirrorInput/VariablesField.jsx | 7 +- .../CodeMirrorInput/VariablesField.test.jsx | 30 +++----- .../components/FormField/CheckboxField.jsx | 8 +- .../components/FormField/PasswordField.jsx | 8 +- .../FormField/PasswordField.test.jsx | 10 ++- .../src/screens/Host/shared/HostForm.jsx | 11 +-- .../Inventory/shared/InventoryForm.jsx | 20 +++-- .../Inventory/shared/InventoryGroupForm.jsx | 8 +- .../Inventory/shared/InventoryHostForm.jsx | 5 +- .../Organization/shared/OrganizationForm.jsx | 12 +-- .../screens/Project/shared/ProjectForm.jsx | 22 +++--- .../ProjectSubForms/InsightsSubForm.jsx | 5 +- .../shared/ProjectSubForms/ManualSubForm.jsx | 5 +- .../shared/ProjectSubForms/SharedFields.jsx | 7 +- .../src/screens/Team/shared/TeamForm.jsx | 10 ++- .../Template/shared/JobTemplateForm.jsx | 74 +++++++++---------- .../src/screens/User/shared/UserForm.jsx | 17 +++-- 17 files changed, 126 insertions(+), 133 deletions(-) diff --git a/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx b/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx index 97c35c1871..44b9e0d45d 100644 --- a/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx +++ b/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx @@ -13,9 +13,8 @@ function VariablesField({ id, name, label, readOnly }) { const [mode, setMode] = useState(YAML_MODE); return ( - ( + + {({ field, form }) => (
@@ -60,7 +59,7 @@ function VariablesField({ id, name, label, readOnly }) { ) : null}
)} - /> +
); } VariablesField.propTypes = { diff --git a/awx/ui_next/src/components/CodeMirrorInput/VariablesField.test.jsx b/awx/ui_next/src/components/CodeMirrorInput/VariablesField.test.jsx index 675212c023..dc21b91dae 100644 --- a/awx/ui_next/src/components/CodeMirrorInput/VariablesField.test.jsx +++ b/awx/ui_next/src/components/CodeMirrorInput/VariablesField.test.jsx @@ -2,7 +2,6 @@ import React from 'react'; import { act } from 'react-dom/test-utils'; import { mount } from 'enzyme'; import { Formik } from 'formik'; -import { sleep } from '../../../testUtils/testUtils'; import VariablesField from './VariablesField'; describe('VariablesField', () => { @@ -13,12 +12,11 @@ describe('VariablesField', () => { it('should render code mirror input', () => { const value = '---\n'; const wrapper = mount( - ( + + {() => ( )} - /> + ); const codemirror = wrapper.find('Controlled'); expect(codemirror.prop('value')).toEqual(value); @@ -27,12 +25,11 @@ describe('VariablesField', () => { it('should render yaml/json toggles', async () => { const value = '---\n'; const wrapper = mount( - ( + + {() => ( )} - /> + ); const buttons = wrapper.find('Button'); expect(buttons).toHaveLength(2); @@ -56,12 +53,11 @@ describe('VariablesField', () => { it('should set Formik error if yaml is invalid', async () => { const value = '---\nfoo bar\n'; const wrapper = mount( - ( + + {() => ( )} - /> + ); wrapper .find('Button') @@ -78,10 +74,8 @@ describe('VariablesField', () => { const value = '---\nfoo: bar\n'; const handleSubmit = jest.fn(); const wrapper = mount( - ( + + {formik => (
)} - /> +
); await act(async () => { wrapper.find('CodeMirrorInput').invoke('onChange')( diff --git a/awx/ui_next/src/components/FormField/CheckboxField.jsx b/awx/ui_next/src/components/FormField/CheckboxField.jsx index 185a40347f..9e854d803a 100644 --- a/awx/ui_next/src/components/FormField/CheckboxField.jsx +++ b/awx/ui_next/src/components/FormField/CheckboxField.jsx @@ -11,10 +11,8 @@ const QuestionCircleIcon = styled(PFQuestionCircleIcon)` function CheckboxField({ id, name, label, tooltip, validate, ...rest }) { return ( - ( + + {({ field }) => ( )} - /> + ); } CheckboxField.propTypes = { diff --git a/awx/ui_next/src/components/FormField/PasswordField.jsx b/awx/ui_next/src/components/FormField/PasswordField.jsx index 5ea33884ad..6e81590bfb 100644 --- a/awx/ui_next/src/components/FormField/PasswordField.jsx +++ b/awx/ui_next/src/components/FormField/PasswordField.jsx @@ -22,10 +22,8 @@ function PasswordField(props) { }; return ( - { + + {({ field, form }) => { const isValid = form && (!form.touched[field.name] || !form.errors[field.name]); return ( @@ -65,7 +63,7 @@ function PasswordField(props) { ); }} - /> + ); } diff --git a/awx/ui_next/src/components/FormField/PasswordField.test.jsx b/awx/ui_next/src/components/FormField/PasswordField.test.jsx index 5fb2ec434a..65fdd55501 100644 --- a/awx/ui_next/src/components/FormField/PasswordField.test.jsx +++ b/awx/ui_next/src/components/FormField/PasswordField.test.jsx @@ -11,10 +11,11 @@ describe('PasswordField', () => { initialValues={{ password: '', }} - render={() => ( + > + {() => ( )} - /> +
); expect(wrapper).toHaveLength(1); }); @@ -25,10 +26,11 @@ describe('PasswordField', () => { initialValues={{ password: '', }} - render={() => ( + > + {() => ( )} - /> +
); expect(wrapper.find('input').prop('type')).toBe('password'); expect(wrapper.find('EyeSlashIcon').length).toBe(1); diff --git a/awx/ui_next/src/screens/Host/shared/HostForm.jsx b/awx/ui_next/src/screens/Host/shared/HostForm.jsx index 837f1edc7e..b9eb44d61b 100644 --- a/awx/ui_next/src/screens/Host/shared/HostForm.jsx +++ b/awx/ui_next/src/screens/Host/shared/HostForm.jsx @@ -19,7 +19,6 @@ function HostForm({ handleSubmit, handleCancel, host, i18n }) { const [inventory, setInventory] = useState( host ? host.summary_fields.inventory : '' ); - console.log('render'); return ( ( + > + {formik => (
( + > + {({ form }) => ( form.setFieldTouched('inventory')} @@ -72,7 +73,7 @@ function HostForm({ handleSubmit, handleCancel, host, i18n }) { error={form.errors.inventory} /> )} - /> + )} @@ -88,7 +89,7 @@ function HostForm({ handleSubmit, handleCancel, host, i18n }) { /> )} - /> +
); } diff --git a/awx/ui_next/src/screens/Inventory/shared/InventoryForm.jsx b/awx/ui_next/src/screens/Inventory/shared/InventoryForm.jsx index d2e858484f..79dd3023bf 100644 --- a/awx/ui_next/src/screens/Inventory/shared/InventoryForm.jsx +++ b/awx/ui_next/src/screens/Inventory/shared/InventoryForm.jsx @@ -41,7 +41,8 @@ function InventoryForm({ onSubmit={values => { onSubmit(values); }} - render={formik => ( + > + {formik => (
( + > + {({ form, field }) => ( )} - /> + ( + > + {({ field, form }) => ( )} - /> + ( + > + {({ field, form }) => ( { @@ -112,7 +116,7 @@ function InventoryForm({ }} /> )} - /> + )} - /> +
); } diff --git a/awx/ui_next/src/screens/Inventory/shared/InventoryGroupForm.jsx b/awx/ui_next/src/screens/Inventory/shared/InventoryGroupForm.jsx index ec138d3b12..e1ae21f64d 100644 --- a/awx/ui_next/src/screens/Inventory/shared/InventoryGroupForm.jsx +++ b/awx/ui_next/src/screens/Inventory/shared/InventoryGroupForm.jsx @@ -28,10 +28,8 @@ function InventoryGroupForm({ return ( - ( + + {formik => (
error : null} )} - /> +
); diff --git a/awx/ui_next/src/screens/Inventory/shared/InventoryHostForm.jsx b/awx/ui_next/src/screens/Inventory/shared/InventoryHostForm.jsx index 23965bdc8b..f51e2abee9 100644 --- a/awx/ui_next/src/screens/Inventory/shared/InventoryHostForm.jsx +++ b/awx/ui_next/src/screens/Inventory/shared/InventoryHostForm.jsx @@ -19,7 +19,8 @@ function InventoryHostForm({ handleSubmit, handleCancel, host, i18n }) { variables: host.variables, }} onSubmit={handleSubmit} - render={formik => ( + > + {formik => (
)} - /> +
); } diff --git a/awx/ui_next/src/screens/Organization/shared/OrganizationForm.jsx b/awx/ui_next/src/screens/Organization/shared/OrganizationForm.jsx index fea386879f..2d1cc69347 100644 --- a/awx/ui_next/src/screens/Organization/shared/OrganizationForm.jsx +++ b/awx/ui_next/src/screens/Organization/shared/OrganizationForm.jsx @@ -91,7 +91,8 @@ function OrganizationForm({ organization, i18n, me, onCancel, onSubmit }) { max_hosts: organization.max_hosts || '0', }} onSubmit={handleSubmit} - render={formik => ( + > + {formik => (
{custom_virtualenvs && custom_virtualenvs.length > 1 && ( - ( + + {({ field }) => ( )} - /> + )} )} - /> + ); } diff --git a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx index 2d41ead48f..ae72bd0896 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx @@ -201,7 +201,8 @@ function ProjectForm({ project, ...props }) { scm_url: project.scm_url || '', }} onSubmit={handleSubmit} - render={formik => ( + > + {formik => (
( + > + {({ form }) => ( )} - /> + ( + > + {({ field, form }) => ( )} - /> + {formik.values.scm_type !== '' && ( @@ -345,9 +348,8 @@ function ProjectForm({ project, ...props }) { {({ custom_virtualenvs }) => custom_virtualenvs && custom_virtualenvs.length > 1 && ( - ( + + {({ field }) => ( )} - /> + ) } @@ -389,7 +391,7 @@ function ProjectForm({ project, ...props }) { /> )} - /> + )} ); diff --git a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/InsightsSubForm.jsx b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/InsightsSubForm.jsx index d0193076ff..503fbf4cf4 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/InsightsSubForm.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/InsightsSubForm.jsx @@ -16,7 +16,8 @@ const InsightsSubForm = ({ ( + > + {({ form }) => ( )} - /> + ); diff --git a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/ManualSubForm.jsx b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/ManualSubForm.jsx index f8caaedf5d..94a624b380 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/ManualSubForm.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/ManualSubForm.jsx @@ -76,7 +76,8 @@ const ManualSubForm = ({ ( + > + {({ field, form }) => ( )} - /> + )} ); diff --git a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx index 5a7e1434c1..1268cd7230 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx @@ -42,9 +42,8 @@ export const BranchFormField = withI18n()(({ i18n, label }) => ( export const ScmCredentialFormField = withI18n()( ({ i18n, credential, onCredentialSelection }) => ( - ( + + {({ form }) => ( )} - /> + ) ); diff --git a/awx/ui_next/src/screens/Team/shared/TeamForm.jsx b/awx/ui_next/src/screens/Team/shared/TeamForm.jsx index 65a3a12cbd..e3414950f2 100644 --- a/awx/ui_next/src/screens/Team/shared/TeamForm.jsx +++ b/awx/ui_next/src/screens/Team/shared/TeamForm.jsx @@ -24,7 +24,8 @@ function TeamForm(props) { organization: team.organization || '', }} onSubmit={handleSubmit} - render={formik => ( + > + {formik => (
( + > + {({ form }) => ( )} - /> + )} - /> + ); } diff --git a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx index 1b2b25df11..b62f7603ec 100644 --- a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx +++ b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx @@ -146,7 +146,6 @@ class JobTemplateForm extends Component { setFieldValue, i18n, template, - values, } = this.props; const jobTypeOptions = [ { @@ -206,7 +205,8 @@ class JobTemplateForm extends Component { name="job_type" validate={required(null, i18n)} onBlur={handleBlur} - render={({ form, field }) => { + > + {({ form, field }) => { const isValid = !form.touched.job_type || !form.errors.job_type; return ( ); }} - /> +
( + > + {({ form }) => ( form.setFieldTouched('inventory')} @@ -253,11 +254,9 @@ class JobTemplateForm extends Component { error={form.errors.inventory} /> )} - /> - ( + + + {({ form }) => ( form.setFieldTouched('project')} @@ -269,12 +268,13 @@ class JobTemplateForm extends Component { required /> )} - /> + { + > + {({ field, form }) => { const isValid = !form.touched.playbook || !form.errors.playbook; return ( ); }} - /> + - ( + + {({ field }) => ( )} - /> + - ( + + {({ field }) => ( @@ -337,7 +334,7 @@ class JobTemplateForm extends Component { )} /> )} - /> + @@ -370,9 +367,8 @@ class JobTemplateForm extends Component { playbook. Multiple patterns are allowed. Refer to Ansible documentation for more information and examples on patterns.`)} /> - ( + + {({ field }) => ( )} - /> + - ( + + {({ field, form }) => ( )} - /> + - ( + + {({ field, form }) => ( )} - /> - ( + + + {({ field, form }) => ( )} - /> - ( + + + {({ field, form }) => ( )} - /> + ( + > + {formik => (
( + > + {({ form }) => ( )} - /> + )} - { + + {({ form, field }) => { const isValid = !form.touched.user_type || !form.errors.user_type; return ( @@ -180,7 +181,7 @@ function UserForm(props) { ); }} - /> + )} - /> + ); }