set default values on prompts

This commit is contained in:
Keith Grant 2020-03-27 16:34:16 -07:00
parent 7f4bbbe5c5
commit 55356ebb51
5 changed files with 12 additions and 13 deletions

View File

@ -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 (
<Fragment>
{children({
@ -166,6 +166,7 @@ class LaunchButton extends React.Component {
{showLaunchPrompt && (
<LaunchPrompt
config={launchConfig}
resource={resource}
onCancel={() => this.setState({ showLaunchPrompt: false })}
/>
)}

View File

@ -1,7 +1,7 @@
import React from 'react';
function InventoryStep() {
function CredentialsStep() {
return <div />;
}
export default InventoryStep;
export default CredentialsStep;

View File

@ -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,

View File

@ -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: <InventoryStep />,
@ -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: <CredentialsStep />,

View File

@ -1,7 +1,7 @@
import React from 'react';
function InventoryStep() {
return <div />;
function PreviewStep() {
return <div>Preview of selected values will appear here</div>;
}
export default InventoryStep;
export default PreviewStep;