import React, { useState } from 'react' import PropTypes from 'prop-types'; import { Icon, Spinner, } from 'patternfly-react'; import { VerticalTabs, } from 'patternfly-react-extensions'; import { translate as __ } from 'foremanReact/common/I18n'; import PowerStatus from 'foremanReact/components/hosts/powerStatus'; import ReportViewer from './components/ReportViewer'; class ApplicationInstanceReport extends React.Component { constructor(props) { super(props); } componentDidMount() { const { data: { hosts, deploymentState, initialConfigureState, initialConfigureJobUrl }, initApplicationInstanceReport, setActiveHost, } = this.props; initApplicationInstanceReport(hosts, deploymentState, initialConfigureState, initialConfigureJobUrl); this.reloadReportData(); }; reloadReportData() { const { data: { appInstanceId, reportDataUrl }, deploymentState, initialConfigureState, loadReportData, } = this.props; // if both states are unknown, it means, that the component was just loaded. try again after a short timeout. if (deploymentState == 'unknown' && initialConfigureState == 'unknown') { setTimeout(() => { this.reloadReportData(); }, 1000); return; } if ((deploymentState != 'new' && deploymentState != 'finished' && deploymentState != 'failed') || (initialConfigureState == 'unconfigured' || initialConfigureState == 'scheduled' || initialConfigureState == 'pending')) { loadReportData(reportDataUrl, appInstanceId); setTimeout(() => { this.reloadReportData(); }, 5000); } } isActive(id) { return (this.props.activeHostId === id); } collectLastReportData(hosts) { const { setActiveHost, } = this.props; const tabs = [] for (const [index, value] of hosts.entries()) { tabs.push( setActiveHost(index)} active={this.isActive(index)} /> ); } return tabs; } lastReportStatus(host) { if (!host['id']) { return (
Host: { host['name'] }  |  State: { __('not build') }  |  Power Status: { __('unknown') }
) } else { const already_deployed_msg = __("Already existing host which was added to the application instance"); return (
Host: { host['name'] }  |  State: { host['build'] == true ? "in Build" : "Deployed" }  |  Power Status: {host['isExistingHost'] ? (  |  Existing host   ) : ()}
) } } render() { const { data: { appInstanceId, appInstanceName, deployTaskUrl, configureJobUrl, reportDataUrl }, activeHostId, hosts, deploymentState, initialConfigureState, initialConfigureJobUrl, showInitialConfigureJob, loadReportData, } = this.props; let tabs = []; let reportStatus = undefined; let report = undefined; // This handles the first call to render() in which the state hosts is always empty if (hosts.length == 0) { return (No host); } tabs = this.collectLastReportData(hosts); reportStatus = this.lastReportStatus(hosts[activeHostId]); if (hosts[activeHostId]['progress_report']) { report = hosts[activeHostId]['progress_report']; } return (
Host deployment state
{ (deploymentState != 'new' && deploymentState != 'finished' && deploymentState != 'failed') ? (  ) : () } { deploymentState }
Deployment task
Last deployment task
{ (showInitialConfigureJob == true) ? (
Configuration job
{ (initialConfigureState == 'scheduled' || initialConfigureState == 'pending') ? (  ) : () } { (initialConfigureState != 'unconfigured' && initialConfigureState != 'scheduled') ? (Configuration job) : () } { (initialConfigureState != 'unconfigured') ? (  State: { initialConfigureState }) : () }
) : (
Configuration job
Configuration jobs
) }
Hosts {tabs}
{reportStatus}
)}; } ApplicationInstanceReport.defaultProps = { error: {}, appInstanceName: '', deployTaskUrl: '', configureJobUrl: '', hosts: [], report: [], activeHostId: 0, deploymentState: 'unknown', initialConfigureState: 'unknown', initialConfigureJobUrl: '', showInitialConfigureJob: false, } ApplicationInstanceReport.propTypes = { initApplicationInstanceReport: PropTypes.func, appInstanceName: PropTypes.string, deployTaskUrl: PropTypes.string, configureJobUrl: PropTypes.string, deploymentState: PropTypes.string, initialConfigureState: PropTypes.string, initialConfigureJobUrl: PropTypes.string, showInitialConfigureJob: PropTypes.bool, hosts: PropTypes.array, deploymentState: PropTypes.string, report: PropTypes.array, setActiveHost: PropTypes.func, loadReportData: PropTypes.func, activeHostId: PropTypes.number, }; export default ApplicationInstanceReport;