mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 13:41:28 -03:30
add 'other prompt' fields to launch API call
This commit is contained in:
parent
9c218fa5f5
commit
9cab5a5046
@ -88,8 +88,8 @@ class LaunchButton extends React.Component {
|
||||
const { history, resource } = this.props;
|
||||
const jobPromise =
|
||||
resource.type === 'workflow_job_template'
|
||||
? WorkflowJobTemplatesAPI.launch(resource.id, params)
|
||||
: JobTemplatesAPI.launch(resource.id, params);
|
||||
? WorkflowJobTemplatesAPI.launch(resource.id, params || {})
|
||||
: JobTemplatesAPI.launch(resource.id, params || {});
|
||||
|
||||
const { data: job } = await jobPromise;
|
||||
history.push(
|
||||
|
||||
@ -39,6 +39,30 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
|
||||
config.ask_scm_branch_on_launch ||
|
||||
config.ask_diff_mode_on_launch
|
||||
) {
|
||||
if (config.ask_job_type_on_launch) {
|
||||
initialValues.job_type = resource.job_type || '';
|
||||
}
|
||||
if (config.ask_limit_on_launch) {
|
||||
initialValues.limit = resource.limit || '';
|
||||
}
|
||||
if (config.ask_verbosity_on_launch) {
|
||||
initialValues.verbosity = resource.verbosity || 0;
|
||||
}
|
||||
if (config.ask_tags_on_launch) {
|
||||
initialValues.job_tags = resource.job_tags || '';
|
||||
}
|
||||
if (config.ask_skip_tags_on_launch) {
|
||||
initialValues.skip_tags = resource.skip_tags || '';
|
||||
}
|
||||
if (config.ask_variables_on_launch) {
|
||||
initialValues.extra_vars = resource.extra_vars || '---';
|
||||
}
|
||||
if (config.ask_scm_branch_on_launch) {
|
||||
initialValues.scm_branch = resource.scm_branch || '';
|
||||
}
|
||||
if (config.ask_diff_mode_on_launch) {
|
||||
initialValues.diff_mode = resource.diff_mode || false;
|
||||
}
|
||||
steps.push({
|
||||
name: i18n._(t`Other Prompts`),
|
||||
component: <OtherPromptsStep config={config} />,
|
||||
@ -58,12 +82,18 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
|
||||
|
||||
const submit = values => {
|
||||
const postValues = {};
|
||||
if (values.inventory) {
|
||||
postValues.inventory_id = values.inventory.id;
|
||||
}
|
||||
if (values.credentials) {
|
||||
postValues.credentials = values.credentials.map(c => c.id);
|
||||
}
|
||||
const setValue = (key, value) => {
|
||||
if (typeof value !== 'undefined' && value !== null) {
|
||||
postValues[key] = value;
|
||||
}
|
||||
};
|
||||
setValue('inventory_id', values.inventory?.id);
|
||||
setValue('credentials', values.credentials?.map(c => c.id));
|
||||
setValue('job_type', values.job_type);
|
||||
setValue('limit', values.limit);
|
||||
setValue('job_tags', values.job_tags);
|
||||
setValue('skip_tags', values.skip_tags);
|
||||
setValue('extra_vars', values.extra_vars);
|
||||
onLaunch(postValues);
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import { t } from '@lingui/macro';
|
||||
import { useField } from 'formik';
|
||||
import { FormGroup } from '@patternfly/react-core';
|
||||
import { Form, FormGroup, Switch } from '@patternfly/react-core';
|
||||
import FormField, { FieldTooltip } from '@components/FormField';
|
||||
import { TagMultiSelect } from '@components/MultiSelect';
|
||||
import AnsibleSelect from '@components/AnsibleSelect';
|
||||
@ -10,17 +10,8 @@ import { VariablesField } from '@components/CodeMirrorInput';
|
||||
|
||||
function OtherPromptsStep({ config, i18n }) {
|
||||
return (
|
||||
<>
|
||||
{config.ask_job_type_on_launch && (
|
||||
<FormField
|
||||
id="prompt-job-type"
|
||||
name="job_type"
|
||||
label={i18n._(t`Job Type`)}
|
||||
tooltip={i18n._(t`For job templates, select run to execute the playbook.
|
||||
Select check to only check playbook syntax, test environment setup,
|
||||
and report problems without executing the playbook.`)}
|
||||
/>
|
||||
)}
|
||||
<Form>
|
||||
{config.ask_job_type_on_launch && <JobTypeField i18n={i18n} />}
|
||||
{config.ask_limit_on_launch && (
|
||||
<FormField
|
||||
id="prompt-limit"
|
||||
@ -33,7 +24,7 @@ function OtherPromptsStep({ config, i18n }) {
|
||||
/>
|
||||
)}
|
||||
{config.ask_verbosity_on_launch && <VerbosityField i18n={i18n} />}
|
||||
{/* TODO: Show Changes toggle? */}
|
||||
{config.ask_diff_mode_on_launch && <ShowChangesToggle i18n={i18n} />}
|
||||
{config.ask_tags_on_launch && (
|
||||
<TagField
|
||||
id="prompt-job-tags"
|
||||
@ -61,15 +52,53 @@ function OtherPromptsStep({ config, i18n }) {
|
||||
id="prompt-variables"
|
||||
name="extra_vars"
|
||||
label={i18n._(t`Variables`)}
|
||||
promptId="prompt-ask-variables-on-launch"
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
function JobTypeField({ i18n }) {
|
||||
const [field, meta, helpers] = useField('job_type');
|
||||
const options = [
|
||||
{
|
||||
value: '',
|
||||
key: '',
|
||||
label: i18n._(t`Choose a job type`),
|
||||
isDisabled: true,
|
||||
},
|
||||
{ value: 'run', key: 'run', label: i18n._(t`Run`), isDisabled: false },
|
||||
{
|
||||
value: 'check',
|
||||
key: 'check',
|
||||
label: i18n._(t`Check`),
|
||||
isDisabled: false,
|
||||
},
|
||||
];
|
||||
const isValid = !(meta.touched && meta.error);
|
||||
return (
|
||||
<FormGroup
|
||||
fieldId="propmt-job-type"
|
||||
label={i18n._(t`Job Type`)}
|
||||
isValid={isValid}
|
||||
>
|
||||
<FieldTooltip
|
||||
content={i18n._(t`For job templates, select run to execute the playbook.
|
||||
Select check to only check playbook syntax, test environment setup,
|
||||
and report problems without executing the playbook.`)}
|
||||
/>
|
||||
<AnsibleSelect
|
||||
id="prompt-job-type"
|
||||
data={options}
|
||||
{...field}
|
||||
onChange={(event, value) => helpers.setValue(value)}
|
||||
/>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
function VerbosityField({ i18n }) {
|
||||
const [field, meta] = useField('verbosity');
|
||||
const [field, meta, helpers] = useField('verbosity');
|
||||
const options = [
|
||||
{ value: '0', key: '0', label: i18n._(t`0 (Normal)`) },
|
||||
{ value: '1', key: '1', label: i18n._(t`1 (Verbose)`) },
|
||||
@ -89,11 +118,28 @@ function VerbosityField({ i18n }) {
|
||||
content={i18n._(t`Control the level of output ansible
|
||||
will produce as the playbook executes.`)}
|
||||
/>
|
||||
<AnsibleSelect id="prompt-verbosity" data={options} {...field} />
|
||||
<AnsibleSelect
|
||||
id="prompt-verbosity"
|
||||
data={options}
|
||||
{...field}
|
||||
onChange={(event, value) => helpers.setValue(value)}
|
||||
/>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
function ShowChangesToggle({ i18n }) {
|
||||
const [field, , helpers] = useField('diff_mode');
|
||||
return (
|
||||
<Switch
|
||||
id="prompt-show-changes"
|
||||
label={i18n._(t`Show Changes`)}
|
||||
isChecked={field.value}
|
||||
onChange={helpers.setValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TagField({ id, name, label, tooltip }) {
|
||||
const [field, , helpers] = useField(name);
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user