mirror of
https://github.com/ansible/awx.git
synced 2026-03-29 06:45:09 -02:30
Adds TemplateList of Project
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import React, { Component } from 'react';
|
import React from 'react';
|
||||||
import { CardBody } from '@components/Card';
|
import { withRouter } from 'react-router-dom';
|
||||||
|
import TemplateList from '../../Template/TemplateList/TemplateList';
|
||||||
|
|
||||||
class ProjectJobTemplates extends Component {
|
function ProjectJobTemplates() {
|
||||||
render() {
|
return <TemplateList />;
|
||||||
return <CardBody>Coming soon :)</CardBody>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ProjectJobTemplates;
|
export default withRouter(ProjectJobTemplates);
|
||||||
|
|||||||
@@ -109,12 +109,14 @@ class TemplatesList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadTemplates() {
|
async loadTemplates() {
|
||||||
const { location } = this.props;
|
const { location, match } = this.props;
|
||||||
const {
|
const {
|
||||||
jtActions: cachedJTActions,
|
jtActions: cachedJTActions,
|
||||||
wfjtActions: cachedWFJTActions,
|
wfjtActions: cachedWFJTActions,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
const params = {
|
||||||
|
...parseQueryString(QS_CONFIG, location.search),
|
||||||
|
};
|
||||||
|
|
||||||
let jtOptionsPromise;
|
let jtOptionsPromise;
|
||||||
if (cachedJTActions) {
|
if (cachedJTActions) {
|
||||||
@@ -133,6 +135,9 @@ class TemplatesList extends Component {
|
|||||||
} else {
|
} else {
|
||||||
wfjtOptionsPromise = WorkflowJobTemplatesAPI.readOptions();
|
wfjtOptionsPromise = WorkflowJobTemplatesAPI.readOptions();
|
||||||
}
|
}
|
||||||
|
if (match.url.startsWith('/projects') && match.params.id) {
|
||||||
|
params.jobtemplate__project = match.params.id;
|
||||||
|
}
|
||||||
|
|
||||||
const promises = Promise.all([
|
const promises = Promise.all([
|
||||||
UnifiedJobTemplatesAPI.read(params),
|
UnifiedJobTemplatesAPI.read(params),
|
||||||
@@ -189,13 +194,13 @@ class TemplatesList extends Component {
|
|||||||
if (canAddJT) {
|
if (canAddJT) {
|
||||||
addButtonOptions.push({
|
addButtonOptions.push({
|
||||||
label: i18n._(t`Template`),
|
label: i18n._(t`Template`),
|
||||||
url: `${match.url}/job_template/add/`,
|
url: `/templates/job_template/add/`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (canAddWFJT) {
|
if (canAddWFJT) {
|
||||||
addButtonOptions.push({
|
addButtonOptions.push({
|
||||||
label: i18n._(t`Workflow Template`),
|
label: i18n._(t`Workflow Template`),
|
||||||
url: `${match.url}/workflow_job_template/add/`,
|
url: `/templates/workflow_job_template/add/`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const isAllSelected =
|
const isAllSelected =
|
||||||
@@ -204,7 +209,7 @@ class TemplatesList extends Component {
|
|||||||
<AddDropDownButton key="add" dropdownItems={addButtonOptions} />
|
<AddDropDownButton key="add" dropdownItems={addButtonOptions} />
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<PageSection>
|
<>
|
||||||
<Card>
|
<Card>
|
||||||
<PaginatedDataList
|
<PaginatedDataList
|
||||||
contentError={contentError}
|
contentError={contentError}
|
||||||
@@ -292,7 +297,7 @@ class TemplatesList extends Component {
|
|||||||
{i18n._(t`Failed to delete one or more templates.`)}
|
{i18n._(t`Failed to delete one or more templates.`)}
|
||||||
<ErrorDetail error={deletionError} />
|
<ErrorDetail error={deletionError} />
|
||||||
</AlertModal>
|
</AlertModal>
|
||||||
</PageSection>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { createMemoryHistory } from 'history';
|
||||||
|
import { Route } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
JobTemplatesAPI,
|
JobTemplatesAPI,
|
||||||
UnifiedJobTemplatesAPI,
|
UnifiedJobTemplatesAPI,
|
||||||
@@ -229,4 +231,38 @@ describe('<TemplatesList />', () => {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
test('Calls API with jobtemplate__project id', async () => {
|
||||||
|
const history = createMemoryHistory({
|
||||||
|
initialEntries: ['/projects/6/job_templates'],
|
||||||
|
});
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<Route
|
||||||
|
path="/projects/:id/job_templates"
|
||||||
|
component={() => <TemplatesList />}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
router: {
|
||||||
|
history,
|
||||||
|
route: {
|
||||||
|
location: history.location,
|
||||||
|
match: { params: { id: 6 } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
await waitForElement(
|
||||||
|
wrapper,
|
||||||
|
'TemplatesList',
|
||||||
|
el => el.state('hasContentLoading') === true
|
||||||
|
);
|
||||||
|
expect(UnifiedJobTemplatesAPI.read).toBeCalledWith({
|
||||||
|
jobtemplate__project: '6',
|
||||||
|
order_by: 'name',
|
||||||
|
page: 1,
|
||||||
|
page_size: 20,
|
||||||
|
type: 'job_template,workflow_job_template',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user