import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Grid, Row, Col, Button } from 'patternfly-react';
import { translate as __ } from 'foremanReact/common/I18n';
import TaskInfo from './TaskInfo';
import { ClickConfirmation } from '../../common/ClickConfirmation';
import { ResumeButton } from '../../common/ActionButtons/ResumeButton';
import { CancelButton } from '../../common/ActionButtons/CancelButton';
class Task extends Component {
taskProgressToggle = () => {
const {
timeoutId,
refetchTaskDetails,
id,
loading,
taskReloadStop,
taskReloadStart,
} = this.props;
if (timeoutId) {
taskReloadStop(timeoutId);
} else {
taskReloadStart(timeoutId, refetchTaskDetails, id, loading);
}
};
render() {
const {
taskReload,
externalId,
id,
state,
allowDangerousActions,
resumable,
cancellable,
hasSubTasks,
parentTask,
showUnlockModal,
showForceUnlockModal,
toggleUnlockModal,
toggleForceUnlockModal,
cancelTaskRequest,
resumeTaskRequest,
action,
dynflowEnableConsole,
} = this.props;
const modalUnlock = (
);
const modalForceUnlock = (
);
return (
{modalUnlock}
{modalForceUnlock}
{
if (!taskReload) {
this.taskProgressToggle();
}
resumeTaskRequest(id, action);
}}
name={action}
disabled={!resumable}
/>
{
if (!taskReload) {
this.taskProgressToggle();
}
cancelTaskRequest(id, action);
}}
/>
{parentTask && (
)}
{hasSubTasks && (
)}
{allowDangerousActions && (
)}
{allowDangerousActions && (
)}
);
}
}
Task.propTypes = {
...TaskInfo.PropTypes,
state: PropTypes.string,
allowDangerousActions: PropTypes.bool,
resumable: PropTypes.bool,
cancellable: PropTypes.bool,
refetchTaskDetails: PropTypes.func,
hasSubTasks: PropTypes.bool,
parentTask: PropTypes.string,
taskReload: PropTypes.bool,
taskReloadStop: PropTypes.func,
taskReloadStart: PropTypes.func,
timeoutId: PropTypes.number,
externalId: PropTypes.string,
id: PropTypes.string.isRequired,
showUnlockModal: PropTypes.bool,
showForceUnlockModal: PropTypes.bool,
toggleUnlockModal: PropTypes.func,
toggleForceUnlockModal: PropTypes.func,
cancelTaskRequest: PropTypes.func,
resumeTaskRequest: PropTypes.func,
dynflowEnableConsole: PropTypes.bool,
};
Task.defaultProps = {
...TaskInfo.defaultProps,
state: '',
allowDangerousActions: false,
resumable: false,
cancellable: false,
refetchTaskDetails: () => null,
hasSubTasks: false,
parentTask: '',
taskReload: false,
taskReloadStop: () => null,
taskReloadStart: () => null,
timeoutId: null,
externalId: '',
showUnlockModal: false,
showForceUnlockModal: false,
toggleUnlockModal: () => null,
toggleForceUnlockModal: () => null,
cancelTaskRequest: () => null,
resumeTaskRequest: () => null,
dynflowEnableConsole: false,
};
export default Task;