mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 13:11:19 -03:30
pass prompted params through to launch API request
This commit is contained in:
parent
55356ebb51
commit
e60e6c7d08
@ -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 {
|
||||
<LaunchPrompt
|
||||
config={launchConfig}
|
||||
resource={resource}
|
||||
onLaunch={this.launchWithParams}
|
||||
onCancel={() => this.setState({ showLaunchPrompt: false })}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -22,7 +22,7 @@ function InventoryStep({ i18n }) {
|
||||
|
||||
const {
|
||||
isLoading,
|
||||
error,
|
||||
// error,
|
||||
result: { inventories, count },
|
||||
request: fetchInventories,
|
||||
} = useRequest(
|
||||
|
||||
@ -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: <PreviewStep />,
|
||||
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 (
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
onSubmit={() => console.log('FORMIK SUBMIT ?!')}
|
||||
>
|
||||
<Wizard
|
||||
isOpen
|
||||
onClose={onCancel}
|
||||
onSave={handleSubmit}
|
||||
title={i18n._(t`Prompts`)}
|
||||
steps={steps}
|
||||
/>
|
||||
<Formik initialValues={initialValues} onSubmit={submit}>
|
||||
{({ handleSubmit }) => (
|
||||
<Wizard
|
||||
isOpen
|
||||
onClose={onCancel}
|
||||
onSave={handleSubmit}
|
||||
title={i18n._(t`Prompts`)}
|
||||
steps={steps}
|
||||
/>
|
||||
)}
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user