mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
add FormSubmitError to existing forms
This commit is contained in:
@@ -21,15 +21,8 @@ const ActionGroup = styled(PFActionGroup)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const FormActionGroup = ({
|
const FormActionGroup = ({ onSubmit, submitDisabled, onCancel, i18n }) => (
|
||||||
onSubmit,
|
|
||||||
submitDisabled,
|
|
||||||
onCancel,
|
|
||||||
errorMessage,
|
|
||||||
i18n,
|
|
||||||
}) => (
|
|
||||||
<ActionGroup>
|
<ActionGroup>
|
||||||
{errorMessage}
|
|
||||||
<Button
|
<Button
|
||||||
aria-label={i18n._(t`Save`)}
|
aria-label={i18n._(t`Save`)}
|
||||||
variant="primary"
|
variant="primary"
|
||||||
@@ -54,12 +47,10 @@ FormActionGroup.propTypes = {
|
|||||||
onCancel: PropTypes.func.isRequired,
|
onCancel: PropTypes.func.isRequired,
|
||||||
onSubmit: PropTypes.func.isRequired,
|
onSubmit: PropTypes.func.isRequired,
|
||||||
submitDisabled: PropTypes.bool,
|
submitDisabled: PropTypes.bool,
|
||||||
errorMessage: PropTypes.node,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FormActionGroup.defaultProps = {
|
FormActionGroup.defaultProps = {
|
||||||
submitDisabled: false,
|
submitDisabled: false,
|
||||||
errorMessage: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(FormActionGroup);
|
export default withI18n()(FormActionGroup);
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import styled from 'styled-components';
|
import { Alert } from '@patternfly/react-core';
|
||||||
|
|
||||||
const ErrorMessage = styled('div')`
|
|
||||||
color: var(--pf-global--danger-color--200);
|
|
||||||
font-weight: var(--pf-global--FontWeight--bold);
|
|
||||||
`;
|
|
||||||
ErrorMessage.displayName = 'ErrorMessage';
|
|
||||||
|
|
||||||
function FormSubmitError({ error }) {
|
function FormSubmitError({ error }) {
|
||||||
const [errorMessage, setErrorMessage] = useState(null);
|
const [errorMessage, setErrorMessage] = useState(null);
|
||||||
@@ -36,7 +30,7 @@ function FormSubmitError({ error }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <ErrorMessage>{errorMessage}</ErrorMessage>;
|
return <Alert variant="danger" isInline title={errorMessage} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FormSubmitError;
|
export default FormSubmitError;
|
||||||
|
|||||||
@@ -31,15 +31,9 @@ function HostEdit({ host }) {
|
|||||||
await HostsAPI.update(host.id, values);
|
await HostsAPI.update(host.id, values);
|
||||||
history.push(detailsUrl);
|
history.push(detailsUrl);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('caught:', error);
|
|
||||||
// // check for field-specific errors from API
|
|
||||||
// if (error.response?.data && typeof error.response.data === 'object') {
|
|
||||||
// throw error.response.data;
|
|
||||||
// }
|
|
||||||
setFormError(error);
|
setFormError(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log('render:', formError);
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
history.push(detailsUrl);
|
history.push(detailsUrl);
|
||||||
|
|||||||
@@ -85,10 +85,10 @@ function HostForm({ handleSubmit, handleCancel, host, submitError, i18n }) {
|
|||||||
label={i18n._(t`Variables`)}
|
label={i18n._(t`Variables`)}
|
||||||
/>
|
/>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
errorMessage={<FormSubmitError error={submitError} />}
|
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -69,17 +69,6 @@ function InventoryAdd() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return (
|
|
||||||
<PageSection>
|
|
||||||
<Card>
|
|
||||||
<CardBody>
|
|
||||||
<ContentError error={error} />
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
</PageSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <ContentLoading />;
|
return <ContentLoading />;
|
||||||
}
|
}
|
||||||
@@ -91,6 +80,7 @@ function InventoryAdd() {
|
|||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
credentialTypeId={credentialTypeId}
|
credentialTypeId={credentialTypeId}
|
||||||
|
submitError={error}
|
||||||
/>
|
/>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -105,10 +105,6 @@ function InventoryEdit({ inventory }) {
|
|||||||
return <ContentLoading />;
|
return <ContentLoading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return <ContentError />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<InventoryForm
|
<InventoryForm
|
||||||
@@ -117,6 +113,7 @@ function InventoryEdit({ inventory }) {
|
|||||||
inventory={inventory}
|
inventory={inventory}
|
||||||
instanceGroups={associatedInstanceGroups}
|
instanceGroups={associatedInstanceGroups}
|
||||||
credentialTypeId={credentialTypeId}
|
credentialTypeId={credentialTypeId}
|
||||||
|
submitError={error}
|
||||||
/>
|
/>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { func, number, shape } from 'prop-types';
|
|||||||
|
|
||||||
import { VariablesField } from '@components/CodeMirrorInput';
|
import { VariablesField } from '@components/CodeMirrorInput';
|
||||||
import { Form } from '@patternfly/react-core';
|
import { Form } from '@patternfly/react-core';
|
||||||
import FormField from '@components/FormField';
|
import FormField, { FormSubmitError } from '@components/FormField';
|
||||||
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
||||||
import FormRow from '@components/FormRow';
|
import FormRow from '@components/FormRow';
|
||||||
import { required } from '@util/validators';
|
import { required } from '@util/validators';
|
||||||
@@ -21,6 +21,7 @@ function InventoryForm({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
instanceGroups,
|
instanceGroups,
|
||||||
credentialTypeId,
|
credentialTypeId,
|
||||||
|
submitError,
|
||||||
}) {
|
}) {
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
name: inventory.name || '',
|
name: inventory.name || '',
|
||||||
@@ -129,6 +130,7 @@ function InventoryForm({
|
|||||||
/>
|
/>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
<FormRow>
|
<FormRow>
|
||||||
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
@@ -146,11 +148,13 @@ InventoryForm.proptype = {
|
|||||||
instanceGroups: shape(),
|
instanceGroups: shape(),
|
||||||
inventory: shape(),
|
inventory: shape(),
|
||||||
credentialTypeId: number.isRequired,
|
credentialTypeId: number.isRequired,
|
||||||
|
submitError: shape(),
|
||||||
};
|
};
|
||||||
|
|
||||||
InventoryForm.defaultProps = {
|
InventoryForm.defaultProps = {
|
||||||
inventory: {},
|
inventory: {},
|
||||||
instanceGroups: [],
|
instanceGroups: [],
|
||||||
|
submitError: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(InventoryForm);
|
export default withI18n()(InventoryForm);
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ function OrganizationAdd() {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
me={me || {}}
|
me={me || {}}
|
||||||
|
submitError={formError}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Config>
|
</Config>
|
||||||
{formError ? <div>error</div> : ''}
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ function OrganizationEdit({ organization }) {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
me={me || {}}
|
me={me || {}}
|
||||||
|
submitError={formError}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Config>
|
</Config>
|
||||||
{formError ? <div>error</div> : null}
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,20 @@ import AnsibleSelect from '@components/AnsibleSelect';
|
|||||||
import ContentError from '@components/ContentError';
|
import ContentError from '@components/ContentError';
|
||||||
import ContentLoading from '@components/ContentLoading';
|
import ContentLoading from '@components/ContentLoading';
|
||||||
import FormRow from '@components/FormRow';
|
import FormRow from '@components/FormRow';
|
||||||
import FormField from '@components/FormField';
|
import FormField, { FormSubmitError } from '@components/FormField';
|
||||||
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
||||||
import { InstanceGroupsLookup } from '@components/Lookup/';
|
import { InstanceGroupsLookup } from '@components/Lookup/';
|
||||||
import { getAddedAndRemoved } from '@util/lists';
|
import { getAddedAndRemoved } from '@util/lists';
|
||||||
import { required, minMaxValue } from '@util/validators';
|
import { required, minMaxValue } from '@util/validators';
|
||||||
|
|
||||||
function OrganizationForm({ organization, i18n, me, onCancel, onSubmit }) {
|
function OrganizationForm({
|
||||||
|
organization,
|
||||||
|
i18n,
|
||||||
|
me,
|
||||||
|
onCancel,
|
||||||
|
onSubmit,
|
||||||
|
submitError,
|
||||||
|
}) {
|
||||||
const defaultVenv = {
|
const defaultVenv = {
|
||||||
label: i18n._(t`Use Default Ansible Environment`),
|
label: i18n._(t`Use Default Ansible Environment`),
|
||||||
value: '/venv/ansible/',
|
value: '/venv/ansible/',
|
||||||
@@ -161,6 +168,7 @@ function OrganizationForm({ organization, i18n, me, onCancel, onSubmit }) {
|
|||||||
t`Select the Instance Groups for this Organization to run on.`
|
t`Select the Instance Groups for this Organization to run on.`
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
@@ -179,6 +187,7 @@ OrganizationForm.propTypes = {
|
|||||||
organization: PropTypes.shape(),
|
organization: PropTypes.shape(),
|
||||||
onSubmit: PropTypes.func.isRequired,
|
onSubmit: PropTypes.func.isRequired,
|
||||||
onCancel: PropTypes.func.isRequired,
|
onCancel: PropTypes.func.isRequired,
|
||||||
|
submitError: PropTypes.shape(),
|
||||||
};
|
};
|
||||||
|
|
||||||
OrganizationForm.defaultProps = {
|
OrganizationForm.defaultProps = {
|
||||||
@@ -188,6 +197,7 @@ OrganizationForm.defaultProps = {
|
|||||||
max_hosts: '0',
|
max_hosts: '0',
|
||||||
custom_virtualenv: '',
|
custom_virtualenv: '',
|
||||||
},
|
},
|
||||||
|
submitError: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
OrganizationForm.contextTypes = {
|
OrganizationForm.contextTypes = {
|
||||||
|
|||||||
@@ -388,10 +388,10 @@ function ProjectForm({ project, submitError, ...props }) {
|
|||||||
}
|
}
|
||||||
</Config>
|
</Config>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
errorMessage={<FormSubmitError error={submitError} />}
|
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ class TeamAdd extends React.Component {
|
|||||||
handleSubmit={this.handleSubmit}
|
handleSubmit={this.handleSubmit}
|
||||||
handleCancel={this.handleCancel}
|
handleCancel={this.handleCancel}
|
||||||
me={me || {}}
|
me={me || {}}
|
||||||
|
submitError={error}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Config>
|
</Config>
|
||||||
{error ? <div>error</div> : ''}
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ function TeamEdit({ team }) {
|
|||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
me={me || {}}
|
me={me || {}}
|
||||||
|
submitError={error}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Config>
|
</Config>
|
||||||
{error ? <div>error</div> : null}
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import { t } from '@lingui/macro';
|
|||||||
import { Formik, Field } from 'formik';
|
import { Formik, Field } from 'formik';
|
||||||
import { Form } from '@patternfly/react-core';
|
import { Form } from '@patternfly/react-core';
|
||||||
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
||||||
import FormField from '@components/FormField';
|
import FormField, { FormSubmitError } from '@components/FormField';
|
||||||
import FormRow from '@components/FormRow';
|
import FormRow from '@components/FormRow';
|
||||||
import OrganizationLookup from '@components/Lookup/OrganizationLookup';
|
import OrganizationLookup from '@components/Lookup/OrganizationLookup';
|
||||||
import { required } from '@util/validators';
|
import { required } from '@util/validators';
|
||||||
|
|
||||||
function TeamForm(props) {
|
function TeamForm(props) {
|
||||||
const { team, handleCancel, handleSubmit, i18n } = props;
|
const { team, handleCancel, handleSubmit, submitError, i18n } = props;
|
||||||
const [organization, setOrganization] = useState(
|
const [organization, setOrganization] = useState(
|
||||||
team.summary_fields ? team.summary_fields.organization : null
|
team.summary_fields ? team.summary_fields.organization : null
|
||||||
);
|
);
|
||||||
@@ -70,6 +70,7 @@ function TeamForm(props) {
|
|||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
@@ -84,10 +85,12 @@ TeamForm.propTypes = {
|
|||||||
handleCancel: PropTypes.func.isRequired,
|
handleCancel: PropTypes.func.isRequired,
|
||||||
handleSubmit: PropTypes.func.isRequired,
|
handleSubmit: PropTypes.func.isRequired,
|
||||||
team: PropTypes.shape({}),
|
team: PropTypes.shape({}),
|
||||||
|
submitError: PropTypes.shape(),
|
||||||
};
|
};
|
||||||
|
|
||||||
TeamForm.defaultProps = {
|
TeamForm.defaultProps = {
|
||||||
team: {},
|
team: {},
|
||||||
|
submitError: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(TeamForm);
|
export default withI18n()(TeamForm);
|
||||||
|
|||||||
@@ -593,11 +593,8 @@ class JobTemplateForm extends Component {
|
|||||||
</FormRow>
|
</FormRow>
|
||||||
</div>
|
</div>
|
||||||
</AdvancedFieldsWrapper>
|
</AdvancedFieldsWrapper>
|
||||||
<FormActionGroup
|
<FormSubmitError error={submitError} />
|
||||||
onCancel={handleCancel}
|
<FormActionGroup onCancel={handleCancel} onSubmit={handleSubmit} />
|
||||||
onSubmit={handleSubmit}
|
|
||||||
errorMessage={<FormSubmitError error={submitError} />}
|
|
||||||
/>
|
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,13 +35,12 @@ function UserAdd() {
|
|||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<Card>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<UserForm handleCancel={handleCancel} handleSubmit={handleSubmit} />
|
<UserForm
|
||||||
|
handleCancel={handleCancel}
|
||||||
|
handleSubmit={handleSubmit}
|
||||||
|
submitError={formSubmitError}
|
||||||
|
/>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
{formSubmitError ? (
|
|
||||||
<div className="formSubmitError">formSubmitError</div>
|
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ function UserEdit({ user, history }) {
|
|||||||
user={user}
|
user={user}
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
|
submitError={formSubmitError}
|
||||||
/>
|
/>
|
||||||
{formSubmitError ? <div> error </div> : null}
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,15 @@ import { Formik, Field } from 'formik';
|
|||||||
import { Form, FormGroup } from '@patternfly/react-core';
|
import { Form, FormGroup } from '@patternfly/react-core';
|
||||||
import AnsibleSelect from '@components/AnsibleSelect';
|
import AnsibleSelect from '@components/AnsibleSelect';
|
||||||
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
||||||
import FormField, { PasswordField } from '@components/FormField';
|
import FormField, {
|
||||||
|
PasswordField,
|
||||||
|
FormSubmitError,
|
||||||
|
} from '@components/FormField';
|
||||||
import FormRow from '@components/FormRow';
|
import FormRow from '@components/FormRow';
|
||||||
import OrganizationLookup from '@components/Lookup/OrganizationLookup';
|
import OrganizationLookup from '@components/Lookup/OrganizationLookup';
|
||||||
import { required, requiredEmail } from '@util/validators';
|
import { required, requiredEmail } from '@util/validators';
|
||||||
|
|
||||||
function UserForm(props) {
|
function UserForm({ user, handleCancel, handleSubmit, submitError, i18n }) {
|
||||||
const { user, handleCancel, handleSubmit, i18n } = props;
|
|
||||||
const [organization, setOrganization] = useState(null);
|
const [organization, setOrganization] = useState(null);
|
||||||
|
|
||||||
const userTypeOptions = [
|
const userTypeOptions = [
|
||||||
@@ -183,6 +185,7 @@ function UserForm(props) {
|
|||||||
}}
|
}}
|
||||||
</Field>
|
</Field>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
|
|||||||
Reference in New Issue
Block a user