pass prompted params through to launch API request

This commit is contained in:
Keith Grant
2020-03-30 13:20:49 -07:00
parent 55356ebb51
commit e60e6c7d08
3 changed files with 38 additions and 51 deletions

View File

@@ -46,6 +46,7 @@ class LaunchButton extends React.Component {
}; };
this.handleLaunch = this.handleLaunch.bind(this); this.handleLaunch = this.handleLaunch.bind(this);
this.launchWithParams = this.launchWithParams.bind(this);
this.handleRelaunch = this.handleRelaunch.bind(this); this.handleRelaunch = this.handleRelaunch.bind(this);
this.handleLaunchErrorClose = this.handleLaunchErrorClose.bind(this); this.handleLaunchErrorClose = this.handleLaunchErrorClose.bind(this);
this.handlePromptErrorClose = this.handlePromptErrorClose.bind(this); this.handlePromptErrorClose = this.handlePromptErrorClose.bind(this);
@@ -60,31 +61,17 @@ class LaunchButton extends React.Component {
} }
async handleLaunch() { async handleLaunch() {
const { history, resource } = this.props; const { resource } = this.props;
const readLaunch = const readLaunch =
resource.type === 'workflow_job_template' resource.type === 'workflow_job_template'
? WorkflowJobTemplatesAPI.readLaunch(resource.id) ? WorkflowJobTemplatesAPI.readLaunch(resource.id)
: JobTemplatesAPI.readLaunch(resource.id); : JobTemplatesAPI.readLaunch(resource.id);
const launchJob =
resource.type === 'workflow_job_template'
? WorkflowJobTemplatesAPI.launch(resource.id)
: JobTemplatesAPI.launch(resource.id);
try { try {
const { data: launchConfig } = await readLaunch; const { data: launchConfig } = await readLaunch;
if (canLaunchWithoutPrompt(launchConfig)) { if (canLaunchWithoutPrompt(launchConfig)) {
const { data: job } = await launchJob; this.launchWithParams(null);
history.push(
`/${
resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs'
}/${job.id}/output`
);
} else { } else {
// TODO: restructure (async?) to send launch command after prompts
this.setState({ this.setState({
showLaunchPrompt: true, showLaunchPrompt: true,
launchConfig, 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() { async handleRelaunch() {
const { history, resource } = this.props; const { history, resource } = this.props;
@@ -167,6 +169,7 @@ class LaunchButton extends React.Component {
<LaunchPrompt <LaunchPrompt
config={launchConfig} config={launchConfig}
resource={resource} resource={resource}
onLaunch={this.launchWithParams}
onCancel={() => this.setState({ showLaunchPrompt: false })} onCancel={() => this.setState({ showLaunchPrompt: false })}
/> />
)} )}

View File

@@ -22,7 +22,7 @@ function InventoryStep({ i18n }) {
const { const {
isLoading, isLoading,
error, // error,
result: { inventories, count }, result: { inventories, count },
request: fetchInventories, request: fetchInventories,
} = useRequest( } = useRequest(

View File

@@ -9,27 +9,7 @@ import OtherPromptsStep from './OtherPromptsStep';
import SurveyStep from './SurveyStep'; import SurveyStep from './SurveyStep';
import PreviewStep from './PreviewStep'; import PreviewStep from './PreviewStep';
function LaunchPrompt({ config, resource, onCancel, i18n }) { function LaunchPrompt({ config, resource, onLaunch, 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: {} ??
const steps = []; const steps = [];
const initialValues = {}; const initialValues = {};
if (config.ask_inventory_on_launch) { if (config.ask_inventory_on_launch) {
@@ -78,24 +58,28 @@ function LaunchPrompt({ config, resource, onCancel, i18n }) {
steps.push({ steps.push({
name: i18n._(t`Preview`), name: i18n._(t`Preview`),
component: <PreviewStep />, component: <PreviewStep />,
nextButtonText: i18n._(t`Launch`),
}); });
const handleSubmit = x => { const submit = values => {
console.log('SUBMIT', x); const postValues = {};
if (values.inventory) {
postValues.inventory_id = values.inventory.id;
}
onLaunch(postValues);
}; };
return ( return (
<Formik <Formik initialValues={initialValues} onSubmit={submit}>
initialValues={initialValues} {({ handleSubmit }) => (
onSubmit={() => console.log('FORMIK SUBMIT ?!')} <Wizard
> isOpen
<Wizard onClose={onCancel}
isOpen onSave={handleSubmit}
onClose={onCancel} title={i18n._(t`Prompts`)}
onSave={handleSubmit} steps={steps}
title={i18n._(t`Prompts`)} />
steps={steps} )}
/>
</Formik> </Formik>
); );
} }