From 55356ebb517844f28a3a1e9a75f12c65549fddca Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Fri, 27 Mar 2020 16:34:16 -0700 Subject: [PATCH] set default values on prompts --- awx/ui_next/src/components/LaunchButton/LaunchButton.jsx | 3 ++- .../src/components/LaunchPrompt/CredentialsStep.jsx | 4 ++-- awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx | 5 +---- awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx | 7 ++++--- awx/ui_next/src/components/LaunchPrompt/PreviewStep.jsx | 6 +++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx index 9f24a04a66..b66bde1ad9 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx @@ -145,7 +145,7 @@ class LaunchButton extends React.Component { render() { const { launchError, showLaunchPrompt, launchConfig } = this.state; - const { i18n, children } = this.props; + const { resource, i18n, children } = this.props; return ( {children({ @@ -166,6 +166,7 @@ class LaunchButton extends React.Component { {showLaunchPrompt && ( this.setState({ showLaunchPrompt: false })} /> )} diff --git a/awx/ui_next/src/components/LaunchPrompt/CredentialsStep.jsx b/awx/ui_next/src/components/LaunchPrompt/CredentialsStep.jsx index c0b8e6ec14..10872e311c 100644 --- a/awx/ui_next/src/components/LaunchPrompt/CredentialsStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/CredentialsStep.jsx @@ -1,7 +1,7 @@ import React from 'react'; -function InventoryStep() { +function CredentialsStep() { return
; } -export default InventoryStep; +export default CredentialsStep; diff --git a/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx b/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx index a1fcd96a2c..6c9a0a596d 100644 --- a/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/InventoryStep.jsx @@ -18,7 +18,7 @@ const QS_CONFIG = getQSConfig('inventory', { function InventoryStep({ i18n }) { const history = useHistory(); - const [field, meta, helpers] = useField('inventory'); + const [field, , helpers] = useField('inventory'); const { isLoading, @@ -29,9 +29,6 @@ function InventoryStep({ i18n }) { useCallback(async () => { const params = parseQueryString(QS_CONFIG, history.location.search); const { data } = await InventoriesAPI.read(params); - if (!field.value && data.results.length) { - helpers.setValue(data.results[0]); - } return { inventories: data.results, count: data.count, diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx index 862dca5eff..7d6bb27cf4 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx @@ -9,7 +9,7 @@ import OtherPromptsStep from './OtherPromptsStep'; import SurveyStep from './SurveyStep'; import PreviewStep from './PreviewStep'; -function LaunchPrompt({ config, onCancel, i18n }) { +function LaunchPrompt({ config, resource, onCancel, i18n }) { // CONFIG // can_start_without_user_input: false // passwords_needed_to_start: [] @@ -28,11 +28,12 @@ function LaunchPrompt({ config, onCancel, i18n }) { // credential_needed_to_start: false // inventory_needed_to_start: false // job_template_data: {name: "JT with prompts", id: 25, description: "" + // defaults: {} ?? const steps = []; const initialValues = {}; if (config.ask_inventory_on_launch) { - initialValues.inventory = null; + initialValues.inventory = resource?.summary_fields?.inventory || null; steps.push({ name: i18n._(t`Inventory`), component: , @@ -47,7 +48,7 @@ function LaunchPrompt({ config, onCancel, i18n }) { // _.has(vm, 'promptDataClone.prompts.credentials.passwords.ssh_password') // ) { if (config.ask_credential_on_launch) { - initialValues.credentials = []; + initialValues.credentials = resource?.summary_fields?.credentials || []; steps.push({ name: i18n._(t`Credential`), component: , diff --git a/awx/ui_next/src/components/LaunchPrompt/PreviewStep.jsx b/awx/ui_next/src/components/LaunchPrompt/PreviewStep.jsx index c0b8e6ec14..b681a402bf 100644 --- a/awx/ui_next/src/components/LaunchPrompt/PreviewStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/PreviewStep.jsx @@ -1,7 +1,7 @@ import React from 'react'; -function InventoryStep() { - return
; +function PreviewStep() { + return
Preview of selected values will appear here
; } -export default InventoryStep; +export default PreviewStep;