Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI support for management jobs in workflows #10572

Merged
merged 7 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions awx/ui_next/src/api/models/SystemJobTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class SystemJobTemplates extends Mixins {
this.baseUrl = '/api/v2/system_job_templates/';
}

readDetail(id) {
const path = `${this.baseUrl}${id}/`;

return this.http.get(path).then(({ data }) => data);
}

launch(id, data) {
return this.http.post(`${this.baseUrl}${id}/launch/`, data);
}
Expand Down
244 changes: 127 additions & 117 deletions awx/ui_next/src/components/PromptDetail/PromptDetail.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import 'styled-components/macro';
import React from 'react';
import { shape } from 'prop-types';

import { t, Trans } from '@lingui/macro';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { Chip, Divider, Title } from '@patternfly/react-core';
import { toTitleCase } from 'util/strings';

import CredentialChip from '../CredentialChip';
import ChipGroup from '../ChipGroup';
import { DetailList, Detail, UserDateDetail } from '../DetailList';
import { VariablesDetail } from '../CodeEditor';

import PromptProjectDetail from './PromptProjectDetail';
import PromptInventorySourceDetail from './PromptInventorySourceDetail';
import PromptJobTemplateDetail from './PromptJobTemplateDetail';
Expand Down Expand Up @@ -139,123 +136,136 @@ function PromptDetail({ resource, launchConfig = {}, overrides = {} }) {
user={details?.summary_fields?.modified_by}
/>
)}
{details?.type === 'system_job_template' && (
<VariablesDetail
label={t`Variables`}
rows={4}
value={overrides.extra_vars}
name="extra_vars"
/>
)}
</DetailList>

{hasPromptData(launchConfig) && hasOverrides && (
<>
<PromptTitle headingLevel="h2">{t`Prompted Values`}</PromptTitle>
<PromptDivider />
<PromptDetailList aria-label={t`Prompt Overrides`}>
{launchConfig.ask_job_type_on_launch && (
<Detail
label={t`Job Type`}
value={toTitleCase(overrides.job_type)}
/>
)}
{launchConfig.ask_credential_on_launch && (
<Detail
fullWidth
label={t`Credentials`}
rows={4}
value={
<ChipGroup
numChips={5}
totalChips={overrides.credentials.length}
>
{overrides.credentials.map((cred) => (
<CredentialChip
key={cred.id}
credential={cred}
isReadOnly
/>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_inventory_on_launch && (
<Detail label={t`Inventory`} value={overrides.inventory?.name} />
)}
{launchConfig.ask_scm_branch_on_launch && (
<Detail
label={t`Source Control Branch`}
value={overrides.scm_branch}
/>
)}
{launchConfig.ask_limit_on_launch && (
<Detail label={t`Limit`} value={overrides.limit} />
)}
{Object.prototype.hasOwnProperty.call(overrides, 'verbosity') &&
launchConfig.ask_verbosity_on_launch ? (
<Detail
label={t`Verbosity`}
value={VERBOSITY[overrides.verbosity]}
/>
) : null}
{launchConfig.ask_tags_on_launch && (
<Detail
fullWidth
label={t`Job Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.job_tags || overrides.job_tags === ''
? 0
: overrides.job_tags.split(',').length
}
>
{overrides.job_tags.length > 0 &&
overrides.job_tags.split(',').map((jobTag) => (
<Chip key={jobTag} isReadOnly>
{jobTag}
</Chip>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_skip_tags_on_launch && (
<Detail
fullWidth
label={t`Skip Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.skip_tags || overrides.skip_tags === ''
? 0
: overrides.skip_tags.split(',').length
}
>
{overrides.skip_tags.length > 0 &&
overrides.skip_tags.split(',').map((skipTag) => (
<Chip key={skipTag} isReadOnly>
{skipTag}
</Chip>
{details?.type !== 'system_job_template' &&
hasPromptData(launchConfig) &&
hasOverrides && (
<>
<PromptTitle headingLevel="h2">{t`Prompted Values`}</PromptTitle>
<PromptDivider />
<PromptDetailList aria-label={t`Prompt Overrides`}>
{launchConfig.ask_job_type_on_launch && (
<Detail
label={t`Job Type`}
value={toTitleCase(overrides.job_type)}
/>
)}
{launchConfig.ask_credential_on_launch && (
<Detail
fullWidth
label={t`Credentials`}
rows={4}
value={
<ChipGroup
numChips={5}
totalChips={overrides.credentials.length}
>
{overrides.credentials.map((cred) => (
<CredentialChip
key={cred.id}
credential={cred}
isReadOnly
/>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_diff_mode_on_launch && (
<Detail
label={t`Show Changes`}
value={overrides.diff_mode === true ? t`On` : t`Off`}
/>
)}
{(launchConfig.survey_enabled ||
launchConfig.ask_variables_on_launch) && (
<VariablesDetail
label={t`Variables`}
rows={4}
value={overrides.extra_vars}
name="extra_vars"
/>
)}
</PromptDetailList>
</>
)}
</ChipGroup>
}
/>
)}
{launchConfig.ask_inventory_on_launch && (
<Detail
label={t`Inventory`}
value={overrides.inventory?.name}
/>
)}
{launchConfig.ask_scm_branch_on_launch && (
<Detail
label={t`Source Control Branch`}
value={overrides.scm_branch}
/>
)}
{launchConfig.ask_limit_on_launch && (
<Detail label={t`Limit`} value={overrides.limit} />
)}
{Object.prototype.hasOwnProperty.call(overrides, 'verbosity') &&
launchConfig.ask_verbosity_on_launch ? (
<Detail
label={t`Verbosity`}
value={VERBOSITY[overrides.verbosity]}
/>
) : null}
{launchConfig.ask_tags_on_launch && (
<Detail
fullWidth
label={t`Job Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.job_tags || overrides.job_tags === ''
? 0
: overrides.job_tags.split(',').length
}
>
{overrides.job_tags.length > 0 &&
overrides.job_tags.split(',').map((jobTag) => (
<Chip key={jobTag} isReadOnly>
{jobTag}
</Chip>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_skip_tags_on_launch && (
<Detail
fullWidth
label={t`Skip Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.skip_tags || overrides.skip_tags === ''
? 0
: overrides.skip_tags.split(',').length
}
>
{overrides.skip_tags.length > 0 &&
overrides.skip_tags.split(',').map((skipTag) => (
<Chip key={skipTag} isReadOnly>
{skipTag}
</Chip>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_diff_mode_on_launch && (
<Detail
label={t`Show Changes`}
value={overrides.diff_mode === true ? t`On` : t`Off`}
/>
)}
{(launchConfig.survey_enabled ||
launchConfig.ask_variables_on_launch) && (
<VariablesDetail
label={t`Variables`}
rows={4}
value={overrides.extra_vars}
name="extra_vars"
/>
)}
</PromptDetailList>
</>
)}
</>
);
}
Expand Down
4 changes: 4 additions & 0 deletions awx/ui_next/src/components/Workflow/WorkflowLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ function WorkflowLegend() {
<NodeTypeLetter>P</NodeTypeLetter>
<span>{t`Project Sync`}</span>
</li>
<li>
<NodeTypeLetter>M</NodeTypeLetter>
<span>{t`Management Job`}</span>
</li>
<li>
<NodeTypeLetter>
<PauseIcon />
Expand Down
4 changes: 4 additions & 0 deletions awx/ui_next/src/components/Workflow/WorkflowNodeHelp.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function WorkflowNodeHelp({ node }) {
case 'workflow_approval':
nodeType = t`Workflow Approval`;
break;
case 'system_job_template':
case 'system_job':
nodeType = t`Management Job`;
break;
default:
nodeType = '';
}
Expand Down
4 changes: 4 additions & 0 deletions awx/ui_next/src/components/Workflow/WorkflowNodeTypeLetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function WorkflowNodeTypeLetter({ node }) {
case 'inventory_update':
nodeTypeLetter = 'I';
break;
case 'system_job_template':
case 'system_job':
nodeTypeLetter = 'M';
break;
case 'workflow_job_template':
case 'workflow_job':
nodeTypeLetter = 'W';
Expand Down
2 changes: 1 addition & 1 deletion awx/ui_next/src/screens/ManagementJob/ManagementJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function ManagementJob({ setBreadcrumb }) {
page_size: 1,
role_level: 'notification_admin_role',
}),
]).then(([systemJobTemplate, notificationRoles]) => ({
]).then(([{ data: systemJobTemplate }, notificationRoles]) => ({
systemJobTemplate,
notificationRoles,
})),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { t } from '@lingui/macro';
import { Form } from '@patternfly/react-core';
import { useField } from 'formik';
import {
required,
minMaxValue,
integer,
combine,
} from '../../../../../util/validators';
import FormField from '../../../../../components/FormField';

function DaysToKeepStep() {
const [, meta] = useField('daysToKeep');
const validators = [required(null), minMaxValue(0), integer()];
return (
<Form
onSubmit={(e) => {
e.preventDefault();
}}
>
<FormField
name="daysToKeep"
id="days-to-keep"
isRequired
validate={combine(validators)}
validated={!(meta.touched && meta.error) ? 'default' : 'error'}
label={t`Days of data to be retained`}
/>
</Form>
);
}

export default DaysToKeepStep;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { Formik } from 'formik';
import { mountWithContexts } from '../../../../../../testUtils/enzymeHelpers';
import DaysToKeepStep from './DaysToKeepStep';

let wrapper;

describe('DaysToKeepStep', () => {
beforeAll(() => {
wrapper = mountWithContexts(
<Formik initialValues={{ daysToKeep: 30 }}>
<DaysToKeepStep />
</Formik>
);
});

afterAll(() => {
wrapper.unmount();
});

test('Days to keep field rendered correctly', () => {
expect(wrapper.find('FormField#days-to-keep').length).toBe(1);
expect(wrapper.find('FormField#days-to-keep').prop('isRequired')).toBe(
true
);
expect(wrapper.find('input#days-to-keep').prop('value')).toBe(30);
});
});
Loading