import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import { Tab, Tabs } from 'patternfly-react'; import { translate as __, sprintf } from 'foremanReact/common/I18n'; import { STATUS } from 'foremanReact/constants'; import MessageBox from 'foremanReact/components/common/MessageBox'; import Task from './Components/Task'; import RunningSteps from './Components/RunningSteps'; import Errors from './Components/Errors'; import Locks from './Components/Locks'; import Raw from './Components/Raw'; import { getTaskID } from './TasksDetailsHelper'; import { TaskSkeleton } from './Components/TaskSkeleton'; import './TaskDetails.scss'; const TaskDetails = ({ executionPlan, failedSteps, runningSteps, locks, links, cancelStep, taskReloadStart, taskReloadStop, APIerror, ...props }) => { const id = getTaskID(); const { taskReload, status, isLoading } = props; useEffect(() => { taskReloadStart(id); return () => { taskReloadStop(); }; }, [id, taskReloadStart, taskReloadStop]); const taskProgressToggle = () => { if (taskReload) { taskReloadStop(); } else { taskReloadStart(id); } }; if (status === STATUS.ERROR) { return ( ); } const resumable = executionPlan ? executionPlan.state === 'paused' : false; const cancellable = executionPlan ? executionPlan.cancellable : false; return (
{isLoading ? ( ) : ( )}
); }; TaskDetails.propTypes = { label: PropTypes.string, runningSteps: PropTypes.array, cancelStep: PropTypes.func.isRequired, taskReload: PropTypes.bool.isRequired, status: PropTypes.oneOf(Object.keys(STATUS)), APIerror: PropTypes.object, taskReloadStop: PropTypes.func.isRequired, taskReloadStart: PropTypes.func.isRequired, links: PropTypes.array, ...Task.propTypes, ...Errors.propTypes, ...Locks.propTypes, ...Raw.propTypes, }; TaskDetails.defaultProps = { label: '', runningSteps: [], APIerror: null, status: STATUS.PENDING, links: [], ...Task.defaultProps, ...RunningSteps.defaultProps, ...Errors.defaultProps, ...Locks.defaultProps, ...Raw.defaultProps, }; export default TaskDetails;