mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-20 06:51:48 -05:00
Extends LaunchButton component to include support for relaunching. Adds relaunch button to jobs list and job detail view(s).
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
import React, { Fragment } from 'react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { number } from 'prop-types';
|
||||
import { number, shape } from 'prop-types';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import { t } from '@lingui/macro';
|
||||
|
||||
import AlertModal from '@components/AlertModal';
|
||||
import ErrorDetail from '@components/ErrorDetail';
|
||||
import { JobTemplatesAPI } from '@api';
|
||||
import {
|
||||
AdHocCommandsAPI,
|
||||
InventorySourcesAPI,
|
||||
JobsAPI,
|
||||
JobTemplatesAPI,
|
||||
ProjectsAPI,
|
||||
WorkflowJobsAPI,
|
||||
} from '@api';
|
||||
|
||||
class LaunchButton extends React.Component {
|
||||
static propTypes = {
|
||||
templateId: number.isRequired,
|
||||
resource: shape({
|
||||
id: number.isRequired,
|
||||
}).isRequired,
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
@@ -22,6 +31,7 @@ class LaunchButton extends React.Component {
|
||||
};
|
||||
|
||||
this.handleLaunch = this.handleLaunch.bind(this);
|
||||
this.handleRelaunch = this.handleRelaunch.bind(this);
|
||||
this.handleLaunchErrorClose = this.handleLaunchErrorClose.bind(this);
|
||||
this.handlePromptErrorClose = this.handlePromptErrorClose.bind(this);
|
||||
}
|
||||
@@ -35,13 +45,56 @@ class LaunchButton extends React.Component {
|
||||
}
|
||||
|
||||
async handleLaunch() {
|
||||
const { history, templateId } = this.props;
|
||||
const { history, resource } = this.props;
|
||||
try {
|
||||
const { data: launchConfig } = await JobTemplatesAPI.readLaunch(
|
||||
templateId
|
||||
resource.id
|
||||
);
|
||||
if (launchConfig.can_start_without_user_input) {
|
||||
const { data: job } = await JobTemplatesAPI.launch(templateId);
|
||||
const { data: job } = await JobTemplatesAPI.launch(resource.id);
|
||||
history.push(`/jobs/${job.id}/details`);
|
||||
} else {
|
||||
this.setState({ promptError: true });
|
||||
}
|
||||
} catch (err) {
|
||||
this.setState({ launchError: err });
|
||||
}
|
||||
}
|
||||
|
||||
async handleRelaunch() {
|
||||
const { history, resource } = this.props;
|
||||
|
||||
let readRelaunch;
|
||||
let relaunch;
|
||||
|
||||
if (resource.type === 'inventory_update') {
|
||||
// We'll need to handle the scenario where the src no longer exists
|
||||
readRelaunch = InventorySourcesAPI.readLaunchUpdate(
|
||||
resource.inventory_source
|
||||
);
|
||||
relaunch = InventorySourcesAPI.launchUpdate(resource.inventory_source);
|
||||
} else if (resource.type === 'project_update') {
|
||||
// We'll need to handle the scenario where the project no longer exists
|
||||
readRelaunch = ProjectsAPI.readLaunchUpdate(resource.project);
|
||||
relaunch = ProjectsAPI.launchUpdate(resource.project);
|
||||
} else if (resource.type === 'workflow_job') {
|
||||
readRelaunch = WorkflowJobsAPI.readRelaunch(resource.id);
|
||||
relaunch = WorkflowJobsAPI.relaunch(resource.id);
|
||||
} else if (resource.type === 'ad_hoc_command') {
|
||||
readRelaunch = AdHocCommandsAPI.readRelaunch(resource.id);
|
||||
relaunch = AdHocCommandsAPI.relaunch(resource.id);
|
||||
} else if (resource.type === 'job') {
|
||||
readRelaunch = JobsAPI.readRelaunch(resource.id);
|
||||
relaunch = JobsAPI.relaunch(resource.id);
|
||||
}
|
||||
|
||||
try {
|
||||
const { data: relaunchConfig } = await readRelaunch;
|
||||
if (
|
||||
!relaunchConfig.passwords_needed_to_start ||
|
||||
relaunchConfig.passwords_needed_to_start.length === 0
|
||||
) {
|
||||
const { data: job } = await relaunch;
|
||||
history.push(`/jobs/${job.id}/details`);
|
||||
} else {
|
||||
this.setState({ promptError: true });
|
||||
@@ -56,7 +109,10 @@ class LaunchButton extends React.Component {
|
||||
const { i18n, children } = this.props;
|
||||
return (
|
||||
<Fragment>
|
||||
{children(this.handleLaunch)}
|
||||
{children({
|
||||
handleLaunch: this.handleLaunch,
|
||||
handleRelaunch: this.handleRelaunch,
|
||||
})}
|
||||
<AlertModal
|
||||
isOpen={launchError}
|
||||
variant="danger"
|
||||
|
||||
Reference in New Issue
Block a user