From 9cab5a50467f5cd5a0976e457599e964942a1531 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Wed, 8 Apr 2020 08:58:14 -0700 Subject: [PATCH] add 'other prompt' fields to launch API call --- .../components/LaunchButton/LaunchButton.jsx | 4 +- .../components/LaunchPrompt/LaunchPrompt.jsx | 42 ++++++++-- .../LaunchPrompt/OtherPromptsStep.jsx | 80 +++++++++++++++---- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx index 878945f8d8..e93c53a181 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx @@ -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( diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx index a932aee367..4a5a256ad7 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx @@ -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: , @@ -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); }; diff --git a/awx/ui_next/src/components/LaunchPrompt/OtherPromptsStep.jsx b/awx/ui_next/src/components/LaunchPrompt/OtherPromptsStep.jsx index 826f90c86f..09445e63e9 100644 --- a/awx/ui_next/src/components/LaunchPrompt/OtherPromptsStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/OtherPromptsStep.jsx @@ -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 && ( - - )} +
+ {config.ask_job_type_on_launch && } {config.ask_limit_on_launch && ( )} {config.ask_verbosity_on_launch && } - {/* TODO: Show Changes toggle? */} + {config.ask_diff_mode_on_launch && } {config.ask_tags_on_launch && ( )} - + + ); +} + +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 ( + + + helpers.setValue(value)} + /> + ); } 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.`)} /> - + helpers.setValue(value)} + /> ); } +function ShowChangesToggle({ i18n }) { + const [field, , helpers] = useField('diff_mode'); + return ( + + ); +} + function TagField({ id, name, label, tooltip }) { const [field, , helpers] = useField(name); return (