mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 01:17:35 -02:30
Merge pull request #6104 from mabashian/6086-proj-form-org
Fixes issues with organization when saving the project form. Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { bool, func, number, string, oneOfType } from 'prop-types';
|
import { bool, func, node, number, string, oneOfType } from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -113,7 +113,7 @@ function CredentialLookup({
|
|||||||
|
|
||||||
CredentialLookup.propTypes = {
|
CredentialLookup.propTypes = {
|
||||||
credentialTypeId: oneOfType([number, string]).isRequired,
|
credentialTypeId: oneOfType([number, string]).isRequired,
|
||||||
helperTextInvalid: string,
|
helperTextInvalid: node,
|
||||||
isValid: bool,
|
isValid: bool,
|
||||||
label: string.isRequired,
|
label: string.isRequired,
|
||||||
onBlur: func,
|
onBlur: func,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { string, func, bool } from 'prop-types';
|
import { node, func, bool } from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -103,7 +103,7 @@ function OrganizationLookup({
|
|||||||
}
|
}
|
||||||
|
|
||||||
OrganizationLookup.propTypes = {
|
OrganizationLookup.propTypes = {
|
||||||
helperTextInvalid: string,
|
helperTextInvalid: node,
|
||||||
isValid: bool,
|
isValid: bool,
|
||||||
onBlur: func,
|
onBlur: func,
|
||||||
onChange: func.isRequired,
|
onChange: func.isRequired,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { string, func, bool } from 'prop-types';
|
import { node, string, func, bool } from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -125,7 +125,7 @@ function ProjectLookup({
|
|||||||
|
|
||||||
ProjectLookup.propTypes = {
|
ProjectLookup.propTypes = {
|
||||||
value: Project,
|
value: Project,
|
||||||
helperTextInvalid: string,
|
helperTextInvalid: node,
|
||||||
isValid: bool,
|
isValid: bool,
|
||||||
onBlur: func,
|
onBlur: func,
|
||||||
onChange: func.isRequired,
|
onChange: func.isRequired,
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ function ProjectAdd() {
|
|||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { id },
|
data: { id },
|
||||||
} = await ProjectsAPI.create(values);
|
} = await ProjectsAPI.create({
|
||||||
|
...values,
|
||||||
|
organization: values.organization.id,
|
||||||
|
});
|
||||||
history.push(`/projects/${id}/details`);
|
history.push(`/projects/${id}/details`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFormSubmitError(error);
|
setFormSubmitError(error);
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ function ProjectEdit({ project }) {
|
|||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { id },
|
data: { id },
|
||||||
} = await ProjectsAPI.update(project.id, values);
|
} = await ProjectsAPI.update(project.id, {
|
||||||
|
...values,
|
||||||
|
organization: values.organization.id,
|
||||||
|
});
|
||||||
history.push(`/projects/${id}/details`);
|
history.push(`/projects/${id}/details`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFormSubmitError(error);
|
setFormSubmitError(error);
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ describe('<ProjectEdit />', () => {
|
|||||||
credential_type_id: 5,
|
credential_type_id: 5,
|
||||||
kind: 'insights',
|
kind: 'insights',
|
||||||
},
|
},
|
||||||
|
organization: {
|
||||||
|
id: 2,
|
||||||
|
name: 'Default',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,6 @@ function ProjectFormFields({
|
|||||||
scmTypeOptions,
|
scmTypeOptions,
|
||||||
setScmSubFormState,
|
setScmSubFormState,
|
||||||
scmSubFormState,
|
scmSubFormState,
|
||||||
setOrganization,
|
|
||||||
organization,
|
|
||||||
}) {
|
}) {
|
||||||
const scmFormFields = {
|
const scmFormFields = {
|
||||||
scm_url: '',
|
scm_url: '',
|
||||||
@@ -94,12 +92,10 @@ function ProjectFormFields({
|
|||||||
validate: required(i18n._(t`Set a value for this field`), i18n),
|
validate: required(i18n._(t`Set a value for this field`), i18n),
|
||||||
});
|
});
|
||||||
const [venvField] = useField('custom_virtualenv');
|
const [venvField] = useField('custom_virtualenv');
|
||||||
const orgFieldArr = useField({
|
const [organizationField, organizationMeta, organizationHelpers] = useField({
|
||||||
name: 'organization',
|
name: 'organization',
|
||||||
validate: required(i18n._(t`Select a value for this field`), i18n),
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
});
|
});
|
||||||
const organizationMeta = orgFieldArr[1];
|
|
||||||
const organizationHelpers = orgFieldArr[2];
|
|
||||||
|
|
||||||
/* Save current scm subform field values to state */
|
/* Save current scm subform field values to state */
|
||||||
const saveSubFormState = form => {
|
const saveSubFormState = form => {
|
||||||
@@ -164,10 +160,9 @@ function ProjectFormFields({
|
|||||||
isValid={!organizationMeta.touched || !organizationMeta.error}
|
isValid={!organizationMeta.touched || !organizationMeta.error}
|
||||||
onBlur={() => organizationHelpers.setTouched()}
|
onBlur={() => organizationHelpers.setTouched()}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
organizationHelpers.setValue(value.id);
|
organizationHelpers.setValue(value);
|
||||||
setOrganization(value);
|
|
||||||
}}
|
}}
|
||||||
value={organization}
|
value={organizationField.value}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
@@ -293,7 +288,6 @@ function ProjectForm({ i18n, project, submitError, ...props }) {
|
|||||||
const { summary_fields = {} } = project;
|
const { summary_fields = {} } = project;
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [organization, setOrganization] = useState(null);
|
|
||||||
const [scmSubFormState, setScmSubFormState] = useState(null);
|
const [scmSubFormState, setScmSubFormState] = useState(null);
|
||||||
const [scmTypeOptions, setScmTypeOptions] = useState(null);
|
const [scmTypeOptions, setScmTypeOptions] = useState(null);
|
||||||
const [credentials, setCredentials] = useState({
|
const [credentials, setCredentials] = useState({
|
||||||
@@ -347,7 +341,7 @@ function ProjectForm({ i18n, project, submitError, ...props }) {
|
|||||||
description: project.description || '',
|
description: project.description || '',
|
||||||
local_path: project.local_path || '',
|
local_path: project.local_path || '',
|
||||||
name: project.name || '',
|
name: project.name || '',
|
||||||
organization: project.organization || '',
|
organization: project.summary_fields?.organization || null,
|
||||||
scm_branch: project.scm_branch || '',
|
scm_branch: project.scm_branch || '',
|
||||||
scm_clean: project.scm_clean || false,
|
scm_clean: project.scm_clean || false,
|
||||||
scm_delete_on_update: project.scm_delete_on_update || false,
|
scm_delete_on_update: project.scm_delete_on_update || false,
|
||||||
@@ -377,8 +371,6 @@ function ProjectForm({ i18n, project, submitError, ...props }) {
|
|||||||
scmTypeOptions={scmTypeOptions}
|
scmTypeOptions={scmTypeOptions}
|
||||||
setScmSubFormState={setScmSubFormState}
|
setScmSubFormState={setScmSubFormState}
|
||||||
scmSubFormState={scmSubFormState}
|
scmSubFormState={scmSubFormState}
|
||||||
setOrganization={setOrganization}
|
|
||||||
organization={organization}
|
|
||||||
/>
|
/>
|
||||||
<FormSubmitError error={submitError} />
|
<FormSubmitError error={submitError} />
|
||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ describe('<ProjectForm />', () => {
|
|||||||
kind: 'scm',
|
kind: 'scm',
|
||||||
name: 'Foo',
|
name: 'Foo',
|
||||||
},
|
},
|
||||||
|
organization: {
|
||||||
|
id: 2,
|
||||||
|
name: 'Default',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user