From 5790aa97803d0b9cf7efd6822ee9ed842e7657a1 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Wed, 29 Jan 2020 11:01:57 -0500 Subject: [PATCH 1/4] Adds TemplateList of Project --- .../ProjectJobTemplates.jsx | 13 ++++--- .../Template/TemplateList/TemplateList.jsx | 17 +++++---- .../TemplateList/TemplatesList.test.jsx | 36 +++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/awx/ui_next/src/screens/Project/ProjectJobTemplates/ProjectJobTemplates.jsx b/awx/ui_next/src/screens/Project/ProjectJobTemplates/ProjectJobTemplates.jsx index b80f1a4c61..72b9af7989 100644 --- a/awx/ui_next/src/screens/Project/ProjectJobTemplates/ProjectJobTemplates.jsx +++ b/awx/ui_next/src/screens/Project/ProjectJobTemplates/ProjectJobTemplates.jsx @@ -1,10 +1,9 @@ -import React, { Component } from 'react'; -import { CardBody } from '@components/Card'; +import React from 'react'; +import { withRouter } from 'react-router-dom'; +import TemplateList from '../../Template/TemplateList/TemplateList'; -class ProjectJobTemplates extends Component { - render() { - return Coming soon :); - } +function ProjectJobTemplates() { + return ; } -export default ProjectJobTemplates; +export default withRouter(ProjectJobTemplates); diff --git a/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx b/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx index 8c99916999..9406866468 100644 --- a/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx +++ b/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx @@ -109,12 +109,14 @@ class TemplatesList extends Component { } async loadTemplates() { - const { location } = this.props; + const { location, match } = this.props; const { jtActions: cachedJTActions, wfjtActions: cachedWFJTActions, } = this.state; - const params = parseQueryString(QS_CONFIG, location.search); + const params = { + ...parseQueryString(QS_CONFIG, location.search), + }; let jtOptionsPromise; if (cachedJTActions) { @@ -133,6 +135,9 @@ class TemplatesList extends Component { } else { wfjtOptionsPromise = WorkflowJobTemplatesAPI.readOptions(); } + if (match.url.startsWith('/projects') && match.params.id) { + params.jobtemplate__project = match.params.id; + } const promises = Promise.all([ UnifiedJobTemplatesAPI.read(params), @@ -189,13 +194,13 @@ class TemplatesList extends Component { if (canAddJT) { addButtonOptions.push({ label: i18n._(t`Template`), - url: `${match.url}/job_template/add/`, + url: `/templates/job_template/add/`, }); } if (canAddWFJT) { addButtonOptions.push({ label: i18n._(t`Workflow Template`), - url: `${match.url}/workflow_job_template/add/`, + url: `/templates/workflow_job_template/add/`, }); } const isAllSelected = @@ -204,7 +209,7 @@ class TemplatesList extends Component { ); return ( - + <> - + ); } } diff --git a/awx/ui_next/src/screens/Template/TemplateList/TemplatesList.test.jsx b/awx/ui_next/src/screens/Template/TemplateList/TemplatesList.test.jsx index ab923d471d..108caece3a 100644 --- a/awx/ui_next/src/screens/Template/TemplateList/TemplatesList.test.jsx +++ b/awx/ui_next/src/screens/Template/TemplateList/TemplatesList.test.jsx @@ -1,4 +1,6 @@ import React from 'react'; +import { createMemoryHistory } from 'history'; +import { Route } from 'react-router-dom'; import { JobTemplatesAPI, UnifiedJobTemplatesAPI, @@ -229,4 +231,38 @@ describe('', () => { done(); }); + test('Calls API with jobtemplate__project id', async () => { + const history = createMemoryHistory({ + initialEntries: ['/projects/6/job_templates'], + }); + const wrapper = mountWithContexts( + } + />, + { + 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', + }); + }); }); From bbea43b1fe559dc53632dbdf208a9804fd07fb34 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Wed, 29 Jan 2020 12:31:22 -0500 Subject: [PATCH 2/4] Addresses needed styling changes to Card and Page Section These changes were necessary to remove an additional page section to ProjectJobTemplateList. --- .../JobTemplateAdd/JobTemplateAdd.jsx | 22 ++- awx/ui_next/src/screens/Template/Template.jsx | 138 +++++++++--------- .../Template/TemplateList/TemplateList.jsx | 14 +- .../src/screens/Template/Templates.jsx | 87 +++++------ .../screens/Template/WorkflowJobTemplate.jsx | 102 +++++++------ 5 files changed, 183 insertions(+), 180 deletions(-) diff --git a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx index f55d25bbdd..7aecba1eb2 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; -import { Card, PageSection } from '@patternfly/react-core'; +import { Card } from '@patternfly/react-core'; import { CardBody } from '@components/Card'; import JobTemplateForm from '../shared/JobTemplateForm'; import { JobTemplatesAPI } from '@api'; @@ -61,17 +61,15 @@ function JobTemplateAdd() { } return ( - - - - - - {formSubmitError ?
formSubmitError
: ''} -
-
+ + + + + {formSubmitError ?
formSubmitError
: ''} +
); } diff --git a/awx/ui_next/src/screens/Template/Template.jsx b/awx/ui_next/src/screens/Template/Template.jsx index 00e052e101..8e22494524 100644 --- a/awx/ui_next/src/screens/Template/Template.jsx +++ b/awx/ui_next/src/screens/Template/Template.jsx @@ -150,78 +150,76 @@ class Template extends Component { } return ( - - - {cardHeader} - - - {template && ( - ( - - )} - /> - )} - {template && ( - } - /> - )} - {template && ( - ( - - )} - /> - )} - {canSeeNotificationsTab && ( - ( - - )} - /> - )} + + {cardHeader} + + + {template && ( - !hasContentLoading && ( - - {match.params.id && ( - - {i18n._(`View Template Details`)} - - )} - - ) - } + key="details" + path="/templates/:templateType/:id/details" + render={() => ( + + )} /> - - - + )} + {template && ( + } + /> + )} + {template && ( + ( + + )} + /> + )} + {canSeeNotificationsTab && ( + ( + + )} + /> + )} + + !hasContentLoading && ( + + {match.params.id && ( + + {i18n._(`View Template Details`)} + + )} + + ) + } + /> + + ); } } diff --git a/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx b/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx index 9406866468..0543587ceb 100644 --- a/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx +++ b/awx/ui_next/src/screens/Template/TemplateList/TemplateList.jsx @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import { withRouter } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; -import { Card, PageSection } from '@patternfly/react-core'; +import { Card } from '@patternfly/react-core'; import { JobTemplatesAPI, @@ -109,7 +109,13 @@ class TemplatesList extends Component { } async loadTemplates() { - const { location, match } = this.props; + const { + location, + match: { + params: { id: projectId }, + url, + }, + } = this.props; const { jtActions: cachedJTActions, wfjtActions: cachedWFJTActions, @@ -135,8 +141,8 @@ class TemplatesList extends Component { } else { wfjtOptionsPromise = WorkflowJobTemplatesAPI.readOptions(); } - if (match.url.startsWith('/projects') && match.params.id) { - params.jobtemplate__project = match.params.id; + if (url.startsWith('/projects') && projectId) { + params.jobtemplate__project = projectId; } const promises = Promise.all([ diff --git a/awx/ui_next/src/screens/Template/Templates.jsx b/awx/ui_next/src/screens/Template/Templates.jsx index 904c7cbc3b..6b93604667 100644 --- a/awx/ui_next/src/screens/Template/Templates.jsx +++ b/awx/ui_next/src/screens/Template/Templates.jsx @@ -1,7 +1,8 @@ -import React, { Component, Fragment } from 'react'; +import React, { Component } from 'react'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { Route, withRouter, Switch } from 'react-router-dom'; +import { PageSection } from '@patternfly/react-core'; import { Config } from '@contexts/Config'; import Breadcrumbs from '@components/Breadcrumbs/Breadcrumbs'; @@ -50,48 +51,50 @@ class Templates extends Component { const { match, history, location } = this.props; const { breadcrumbConfig } = this.state; return ( - + <> - - } - /> - ( - - {({ me }) => ( -