mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 09:48:51 -03:30
Pull credential api request outside of ProjectEdit
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint no-nested-ternary: 0 */
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
@@ -30,6 +31,44 @@ const ScmTypeFormRow = styled(FormRow)`
|
|||||||
padding: 24px;
|
padding: 24px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const fetchCredentials = async credential => {
|
||||||
|
const [
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
results: [scmCredentialType],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
results: [insightsCredentialType],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
] = await Promise.all([
|
||||||
|
CredentialTypesAPI.read({ kind: 'scm' }),
|
||||||
|
CredentialTypesAPI.read({ name: 'Insights' }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!credential) {
|
||||||
|
return {
|
||||||
|
scm: { typeId: scmCredentialType.id },
|
||||||
|
insights: { typeId: insightsCredentialType.id },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { credential_type_id } = credential;
|
||||||
|
return {
|
||||||
|
scm: {
|
||||||
|
typeId: scmCredentialType.id,
|
||||||
|
value: credential_type_id === scmCredentialType.id ? credential : null,
|
||||||
|
},
|
||||||
|
insights: {
|
||||||
|
typeId: insightsCredentialType.id,
|
||||||
|
value:
|
||||||
|
credential_type_id === insightsCredentialType.id ? credential : null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
function ProjectForm({ project, ...props }) {
|
function ProjectForm({ project, ...props }) {
|
||||||
const { i18n, handleCancel, handleSubmit } = props;
|
const { i18n, handleCancel, handleSubmit } = props;
|
||||||
const { summary_fields = {} } = project;
|
const { summary_fields = {} } = project;
|
||||||
@@ -48,58 +87,19 @@ function ProjectForm({ project, ...props }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
try {
|
try {
|
||||||
const [
|
const credentialResponse = fetchCredentials(summary_fields.credential);
|
||||||
{
|
const {
|
||||||
data: {
|
data: {
|
||||||
results: [scmCredentialType],
|
actions: {
|
||||||
},
|
GET: {
|
||||||
},
|
scm_type: { choices },
|
||||||
{
|
|
||||||
data: {
|
|
||||||
results: [insightsCredentialType],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
actions: {
|
|
||||||
GET: {
|
|
||||||
scm_type: { choices },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
] = await Promise.all([
|
} = await ProjectsAPI.readOptions();
|
||||||
CredentialTypesAPI.read({ kind: 'scm' }),
|
|
||||||
CredentialTypesAPI.read({ name: 'Insights' }),
|
|
||||||
ProjectsAPI.readOptions(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
setCredentials(await credentialResponse);
|
||||||
setScmTypeOptions(choices);
|
setScmTypeOptions(choices);
|
||||||
|
|
||||||
const { credential } = summary_fields;
|
|
||||||
if (!credential) {
|
|
||||||
setCredentials({
|
|
||||||
scm: { typeId: scmCredentialType.id },
|
|
||||||
insights: { typeId: insightsCredentialType.id },
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { credential_type_id } = credential;
|
|
||||||
setCredentials({
|
|
||||||
scm: {
|
|
||||||
typeId: scmCredentialType.id,
|
|
||||||
value:
|
|
||||||
credential_type_id === scmCredentialType.id ? credential : null,
|
|
||||||
},
|
|
||||||
insights: {
|
|
||||||
typeId: insightsCredentialType.id,
|
|
||||||
value:
|
|
||||||
credential_type_id === insightsCredentialType.id
|
|
||||||
? credential
|
|
||||||
: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setContentError(error);
|
setContentError(error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -185,7 +185,12 @@ function ProjectForm({ project, ...props }) {
|
|||||||
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,
|
||||||
scm_refspec: project.scm_refspec || '',
|
scm_refspec: project.scm_refspec || '',
|
||||||
scm_type: project.scm_type || '',
|
scm_type:
|
||||||
|
project.scm_type === ''
|
||||||
|
? 'manual'
|
||||||
|
: project.scm_type === undefined
|
||||||
|
? ''
|
||||||
|
: project.scm_type,
|
||||||
scm_update_cache_timeout: project.scm_update_cache_timeout || 0,
|
scm_update_cache_timeout: project.scm_update_cache_timeout || 0,
|
||||||
scm_update_on_launch: project.scm_update_on_launch || false,
|
scm_update_on_launch: project.scm_update_on_launch || false,
|
||||||
scm_url: project.scm_url || '',
|
scm_url: project.scm_url || '',
|
||||||
|
|||||||
Reference in New Issue
Block a user