mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
Removes code from serializer in favor to api call of Project.readDetails
Adds necessary tests.
This commit is contained in:
@@ -196,12 +196,7 @@ class JobTemplateDetail extends Component {
|
|||||||
) : (
|
) : (
|
||||||
renderMissingDataDetail(i18n._(t`Project`))
|
renderMissingDataDetail(i18n._(t`Project`))
|
||||||
)}
|
)}
|
||||||
{template.scm_branch && (
|
<Detail label={i18n._(t`SCM Branch`)} value={template.scm_branch} />
|
||||||
<Detail
|
|
||||||
label={i18n._(t`SCM Branch`)}
|
|
||||||
value={template.scm_branch}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Detail label={i18n._(t`Playbook`)} value={playbook} />
|
<Detail label={i18n._(t`Playbook`)} value={playbook} />
|
||||||
<Detail label={i18n._(t`Forks`)} value={forks || '0'} />
|
<Detail label={i18n._(t`Forks`)} value={forks || '0'} />
|
||||||
<Detail label={i18n._(t`Limit`)} value={limit} />
|
<Detail label={i18n._(t`Limit`)} value={limit} />
|
||||||
|
|||||||
@@ -161,6 +161,11 @@ describe('<JobTemplateEdit />', () => {
|
|||||||
JobTemplatesAPI.readInstanceGroups.mockReturnValue({
|
JobTemplatesAPI.readInstanceGroups.mockReturnValue({
|
||||||
data: { results: mockInstanceGroups },
|
data: { results: mockInstanceGroups },
|
||||||
});
|
});
|
||||||
|
ProjectsAPI.readDetail.mockReturnValue({
|
||||||
|
id: 1,
|
||||||
|
allow_override: true,
|
||||||
|
name: 'foo',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
ProjectLookup,
|
ProjectLookup,
|
||||||
MultiCredentialsLookup,
|
MultiCredentialsLookup,
|
||||||
} from '@components/Lookup';
|
} from '@components/Lookup';
|
||||||
import { JobTemplatesAPI } from '@api';
|
import { JobTemplatesAPI, ProjectsAPI } from '@api';
|
||||||
import LabelSelect from './LabelSelect';
|
import LabelSelect from './LabelSelect';
|
||||||
import PlaybookSelect from './PlaybookSelect';
|
import PlaybookSelect from './PlaybookSelect';
|
||||||
|
|
||||||
@@ -81,16 +81,31 @@ class JobTemplateForm extends Component {
|
|||||||
this.loadRelatedInstanceGroups = this.loadRelatedInstanceGroups.bind(this);
|
this.loadRelatedInstanceGroups = this.loadRelatedInstanceGroups.bind(this);
|
||||||
this.handleProjectUpdate = this.handleProjectUpdate.bind(this);
|
this.handleProjectUpdate = this.handleProjectUpdate.bind(this);
|
||||||
this.setContentError = this.setContentError.bind(this);
|
this.setContentError = this.setContentError.bind(this);
|
||||||
|
this.fetchProject = this.fetchProject.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { validateField } = this.props;
|
const { validateField } = this.props;
|
||||||
this.setState({ contentError: null, hasContentLoading: true });
|
this.setState({ contentError: null, hasContentLoading: true });
|
||||||
// TODO: determine when LabelSelect has finished loading labels
|
// TODO: determine when LabelSelect has finished loading labels
|
||||||
Promise.all([this.loadRelatedInstanceGroups()]).then(() => {
|
Promise.all([this.loadRelatedInstanceGroups(), this.fetchProject()]).then(
|
||||||
this.setState({ hasContentLoading: false });
|
() => {
|
||||||
validateField('project');
|
this.setState({ hasContentLoading: false });
|
||||||
});
|
validateField('project');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchProject() {
|
||||||
|
const { project } = this.state;
|
||||||
|
if (project && project.id) {
|
||||||
|
try {
|
||||||
|
const { data } = await ProjectsAPI.readDetail(project.id);
|
||||||
|
this.setState({ project: data });
|
||||||
|
} catch (err) {
|
||||||
|
this.setState({ contentError: err });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadRelatedInstanceGroups() {
|
async loadRelatedInstanceGroups() {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ describe('<JobTemplateForm />', () => {
|
|||||||
project: {
|
project: {
|
||||||
id: 3,
|
id: 3,
|
||||||
name: 'qux',
|
name: 'qux',
|
||||||
allow_override: true,
|
|
||||||
},
|
},
|
||||||
labels: { results: [{ name: 'Sushi', id: 1 }, { name: 'Major', id: 2 }] },
|
labels: { results: [{ name: 'Sushi', id: 1 }, { name: 'Major', id: 2 }] },
|
||||||
credentials: [
|
credentials: [
|
||||||
@@ -90,6 +89,11 @@ describe('<JobTemplateForm />', () => {
|
|||||||
ProjectsAPI.readPlaybooks.mockReturnValue({
|
ProjectsAPI.readPlaybooks.mockReturnValue({
|
||||||
data: ['debug.yml'],
|
data: ['debug.yml'],
|
||||||
});
|
});
|
||||||
|
ProjectsAPI.readDetail.mockReturnValue({
|
||||||
|
name: 'foo',
|
||||||
|
id: 1,
|
||||||
|
allow_override: true,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user