import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Grid, Row, Col, ProgressBar } from 'patternfly-react'; import { translate as __ } from 'foremanReact/common/I18n'; import EllipsisWithTooltip from 'react-ellipsis-with-tooltip'; import { timeInWords } from './TaskHelper'; class TaskInfo extends Component { isDelayed = () => { const startAt = new Date(this.props.startAt); const startedAt = new Date(this.props.startedAt); startAt.setMilliseconds(0); startedAt.setMilliseconds(0); return startAt.getTime() !== startedAt.getTime(); }; resultIcon = () => { if (this.props.state !== 'stopped') return 'task-status pficon-help'; const { result } = this.props; let icon; switch (result) { case 'success': icon = 'pficon-ok'; break; case 'error': icon = 'pficon-error-circle-o'; break; case 'warning': icon = 'pficon-ok status-warn'; break; default: icon = 'pficon-help'; break; } return `task-status ${icon}`; }; progressBarType = () => { const { result } = this.props; switch (result) { case 'error': return 'danger'; case 'success': return 'success'; case 'warning': return 'warning'; default: return null; } }; render() { const { action, endedAt, result, startAt, startBefore, startedAt, state, help, output, error, progress, username, usernamePath, } = this.props; const details = [ [ { title: 'Name', value: ( {action || __('N/A')} ), }, { title: 'Start at', value: timeInWords(startAt) }, ], [ { title: 'Result', value: ( {result} ), }, { title: 'Started at', value: timeInWords(startedAt) }, ], [ { title: 'Triggered by', value: (usernamePath || '').includes('href') ? ( {username} ) : ( username || '' ), }, { title: 'Ended at', value: timeInWords(endedAt) }, ], [ { title: 'Execution type', value: __(this.isDelayed() ? 'Delayed' : 'Immediate'), }, { title: 'Start before', value: startBefore ? timeInWords(startBefore) : '-', }, ], ]; return (
{details.map((items, key) => ( {__(items[0].title)}: {items[0].value} {__(items[1].title)}: {items[1].value} ))}
{__('State')}: {state}
{`${progress}% ${__('Complete')}`}

{help && (

{__('Troubleshooting')}

{help.split('\n').map((item, i) => ( {item}
))}

)} {output && output.length > 0 && (

{__('Output:')}

{output}
)} {error && error.length > 0 && (
{__('Errors:')}
{error}
)}
); } } TaskInfo.propTypes = { action: PropTypes.string, endedAt: PropTypes.string, result: PropTypes.string, startAt: PropTypes.string, startBefore: PropTypes.string, startedAt: PropTypes.string, state: PropTypes.string, help: PropTypes.string, error: PropTypes.array, progress: PropTypes.number, username: PropTypes.string, usernamePath: PropTypes.string, output: PropTypes.PropTypes.oneOfType([ PropTypes.string, PropTypes.shape({}), ]), }; TaskInfo.defaultProps = { action: '', endedAt: '', result: 'error', startAt: '', startBefore: '', startedAt: '', state: '', help: '', error: [], progress: 0, username: '', usernamePath: '', output: '', }; export default TaskInfo;