mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
Fixes navigation bug in InventoryAdd Adds SCM Branch field on JTForm
This commit is contained in:
@@ -57,7 +57,9 @@ function InventoryAdd() {
|
|||||||
);
|
);
|
||||||
await Promise.all(associatePromises);
|
await Promise.all(associatePromises);
|
||||||
}
|
}
|
||||||
const url = history.location.pathname.search('smart')
|
const url = history.location.pathname.startsWith(
|
||||||
|
'/inventories/smart_inventory'
|
||||||
|
)
|
||||||
? `/inventories/smart_inventory/${inventoryId}/details`
|
? `/inventories/smart_inventory/${inventoryId}/details`
|
||||||
: `/inventories/inventory/${inventoryId}/details`;
|
: `/inventories/inventory/${inventoryId}/details`;
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ describe('<InventoryAdd />', () => {
|
|||||||
test('Initially renders successfully', () => {
|
test('Initially renders successfully', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
test('handleSubmit should call the api and redirect to details page', async () => {
|
||||||
test('handleSubmit should call the api', async () => {
|
|
||||||
const instanceGroups = [{ name: 'Bizz', id: 1 }, { name: 'Buzz', id: 2 }];
|
const instanceGroups = [{ name: 'Bizz', id: 1 }, { name: 'Buzz', id: 2 }];
|
||||||
await waitForElement(wrapper, 'isLoading', el => el.length === 0);
|
await waitForElement(wrapper, 'isLoading', el => el.length === 0);
|
||||||
|
|
||||||
@@ -64,6 +63,7 @@ describe('<InventoryAdd />', () => {
|
|||||||
IG.id
|
IG.id
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
expect(history.location.pathname).toBe('/inventories/inventory/13/details');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handleCancel should return the user back to the inventories list', async () => {
|
test('handleCancel should return the user back to the inventories list', async () => {
|
||||||
|
|||||||
@@ -196,6 +196,12 @@ 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`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} />
|
||||||
|
|||||||
@@ -143,4 +143,19 @@ describe('<JobTemplateDetail />', () => {
|
|||||||
template.summary_fields.credentials[0]
|
template.summary_fields.credentials[0]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
test('should render SCM_Branch', async () => {
|
||||||
|
const mockTemplate = { ...template };
|
||||||
|
mockTemplate.scm_branch = 'Foo branch';
|
||||||
|
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<JobTemplateDetail template={mockTemplate} />
|
||||||
|
);
|
||||||
|
await waitForElement(
|
||||||
|
wrapper,
|
||||||
|
'JobTemplateDetail',
|
||||||
|
el => el.state('hasContentLoading') === false
|
||||||
|
);
|
||||||
|
const SCMBranch = wrapper.find('Detail[label="SCM Branch"]');
|
||||||
|
expect(SCMBranch.prop('value')).toBe('Foo branch');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -124,6 +124,9 @@ class JobTemplateForm extends Component {
|
|||||||
handleProjectUpdate(project) {
|
handleProjectUpdate(project) {
|
||||||
const { setFieldValue } = this.props;
|
const { setFieldValue } = this.props;
|
||||||
setFieldValue('project', project.id);
|
setFieldValue('project', project.id);
|
||||||
|
if (!project.allow_override) {
|
||||||
|
setFieldValue('scm_branch', null);
|
||||||
|
}
|
||||||
this.setState({ project });
|
this.setState({ project });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,6 +272,14 @@ class JobTemplateForm extends Component {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
{project && project.allow_override && (
|
||||||
|
<FormField
|
||||||
|
id="scm_branch"
|
||||||
|
name="scm_branch"
|
||||||
|
type="text"
|
||||||
|
label={i18n._(t`SCM Branch`)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Field
|
<Field
|
||||||
name="playbook"
|
name="playbook"
|
||||||
validate={required(i18n._(t`Select a value for this field`), i18n)}
|
validate={required(i18n._(t`Select a value for this field`), i18n)}
|
||||||
@@ -583,6 +594,7 @@ const FormikApp = withFormik({
|
|||||||
job_type: template.job_type || 'run',
|
job_type: template.job_type || 'run',
|
||||||
inventory: template.inventory || '',
|
inventory: template.inventory || '',
|
||||||
project: template.project || '',
|
project: template.project || '',
|
||||||
|
scm_branch: template.scm_branch || '',
|
||||||
playbook: template.playbook || '',
|
playbook: template.playbook || '',
|
||||||
labels: summary_fields.labels.results || [],
|
labels: summary_fields.labels.results || [],
|
||||||
forks: template.forks || 0,
|
forks: template.forks || 0,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ describe('<JobTemplateForm />', () => {
|
|||||||
project: 3,
|
project: 3,
|
||||||
playbook: 'Baz',
|
playbook: 'Baz',
|
||||||
type: 'job_template',
|
type: 'job_template',
|
||||||
|
scm_branch: 'Foo',
|
||||||
summary_fields: {
|
summary_fields: {
|
||||||
inventory: {
|
inventory: {
|
||||||
id: 2,
|
id: 2,
|
||||||
@@ -26,6 +27,7 @@ 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: [
|
||||||
@@ -145,6 +147,7 @@ describe('<JobTemplateForm />', () => {
|
|||||||
wrapper.find('ProjectLookup').invoke('onChange')({
|
wrapper.find('ProjectLookup').invoke('onChange')({
|
||||||
id: 4,
|
id: 4,
|
||||||
name: 'project',
|
name: 'project',
|
||||||
|
allow_override: true,
|
||||||
});
|
});
|
||||||
wrapper.find('AnsibleSelect[name="playbook"]').simulate('change', {
|
wrapper.find('AnsibleSelect[name="playbook"]').simulate('change', {
|
||||||
target: { value: 'new baz type', name: 'playbook' },
|
target: { value: 'new baz type', name: 'playbook' },
|
||||||
|
|||||||
Reference in New Issue
Block a user