From e60e6c7d080f8f1556c00da1ed0c7b9181050b09 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Mon, 30 Mar 2020 13:20:49 -0700 Subject: [PATCH] pass prompted params through to launch API request --- .../components/LaunchButton/LaunchButton.jsx | 35 +++++++------ .../components/LaunchPrompt/InventoryStep.jsx | 2 +- .../components/LaunchPrompt/LaunchPrompt.jsx | 52 +++++++------------ 3 files changed, 38 insertions(+), 51 deletions(-) diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx index b66bde1ad9..e8c75c5057 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx @@ -46,6 +46,7 @@ class LaunchButton extends React.Component { }; this.handleLaunch = this.handleLaunch.bind(this); + this.launchWithParams = this.launchWithParams.bind(this); this.handleRelaunch = this.handleRelaunch.bind(this); this.handleLaunchErrorClose = this.handleLaunchErrorClose.bind(this); this.handlePromptErrorClose = this.handlePromptErrorClose.bind(this); @@ -60,31 +61,17 @@ class LaunchButton extends React.Component { } async handleLaunch() { - const { history, resource } = this.props; - + const { resource } = this.props; const readLaunch = resource.type === 'workflow_job_template' ? WorkflowJobTemplatesAPI.readLaunch(resource.id) : JobTemplatesAPI.readLaunch(resource.id); - - const launchJob = - resource.type === 'workflow_job_template' - ? WorkflowJobTemplatesAPI.launch(resource.id) - : JobTemplatesAPI.launch(resource.id); - try { const { data: launchConfig } = await readLaunch; if (canLaunchWithoutPrompt(launchConfig)) { - const { data: job } = await launchJob; - - history.push( - `/${ - resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs' - }/${job.id}/output` - ); + this.launchWithParams(null); } else { - // TODO: restructure (async?) to send launch command after prompts this.setState({ showLaunchPrompt: true, launchConfig, @@ -95,6 +82,21 @@ class LaunchButton extends React.Component { } } + async launchWithParams(params) { + const { history, resource } = this.props; + const launchJob = + resource.type === 'workflow_job_template' + ? WorkflowJobTemplatesAPI.launch(resource.id, params) + : JobTemplatesAPI.launch(resource.id, params); + + const { data: job } = await launchJob; + history.push( + `/${ + resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs' + }/${job.id}/output` + ); + } + async handleRelaunch() { const { history, resource } = this.props; @@ -167,6 +169,7 @@ class LaunchButton extends React.Component { this.setState({ showLaunchPrompt: false })} /> )} diff --git a/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx b/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx index 6c9a0a596d..03878b63a5 100644 --- a/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx @@ -22,7 +22,7 @@ function InventoryStep({ i18n }) { const { isLoading, - error, + // error, result: { inventories, count }, request: fetchInventories, } = useRequest( diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx index 7d6bb27cf4..b51e7945ca 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx @@ -9,27 +9,7 @@ import OtherPromptsStep from './OtherPromptsStep'; import SurveyStep from './SurveyStep'; import PreviewStep from './PreviewStep'; -function LaunchPrompt({ config, resource, onCancel, i18n }) { - // CONFIG - // can_start_without_user_input: false - // passwords_needed_to_start: [] - // ask_scm_branch_on_launch: false - // ask_variables_on_launch: true - // ask_tags_on_launch: false - // ask_diff_mode_on_launch: false - // ask_skip_tags_on_launch: false - // ask_job_type_on_launch: false - // ask_limit_on_launch: false - // ask_verbosity_on_launch: false - // ask_inventory_on_launch: false - // ask_credential_on_launch: true - // survey_enabled: false - // variables_needed_to_start: [] - // credential_needed_to_start: false - // inventory_needed_to_start: false - // job_template_data: {name: "JT with prompts", id: 25, description: "" - // defaults: {} ?? - +function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) { const steps = []; const initialValues = {}; if (config.ask_inventory_on_launch) { @@ -78,24 +58,28 @@ function LaunchPrompt({ config, resource, onCancel, i18n }) { steps.push({ name: i18n._(t`Preview`), component: , + nextButtonText: i18n._(t`Launch`), }); - const handleSubmit = x => { - console.log('SUBMIT', x); + const submit = values => { + const postValues = {}; + if (values.inventory) { + postValues.inventory_id = values.inventory.id; + } + onLaunch(postValues); }; return ( - console.log('FORMIK SUBMIT ?!')} - > - + + {({ handleSubmit }) => ( + + )} ); }