Skip to content

Commit

Permalink
Try to fix ApplicationInstanceReport component linting
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Apr 26, 2024
1 parent 9b91833 commit 78790d5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import { Icon, Spinner } from 'patternfly-react';
Expand All @@ -11,10 +11,6 @@ import PowerStatus from 'foremanReact/components/hosts/powerStatus';
import ReportViewer from './components/ReportViewer';

class ApplicationInstanceReport extends React.Component {
constructor(props) {
super(props);
}

componentDidMount() {
const {
data: {
Expand All @@ -24,7 +20,6 @@ class ApplicationInstanceReport extends React.Component {
initialConfigureJobUrl,
},
initApplicationInstanceReport,
setActiveHost,
} = this.props;

initApplicationInstanceReport(
Expand All @@ -45,7 +40,7 @@ class ApplicationInstanceReport extends React.Component {
} = 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') {
if (deploymentState === 'unknown' && initialConfigureState === 'unknown') {
setTimeout(() => {
this.reloadReportData();
}, 1000);
Expand All @@ -54,12 +49,12 @@ class ApplicationInstanceReport extends React.Component {
}

if (
(deploymentState != 'new' &&
deploymentState != 'finished' &&
deploymentState != 'failed') ||
initialConfigureState == 'unconfigured' ||
initialConfigureState == 'scheduled' ||
initialConfigureState == 'pending'
(deploymentState !== 'new' &&
deploymentState !== 'finished' &&
deploymentState !== 'failed') ||
initialConfigureState === 'unconfigured' ||
initialConfigureState === 'scheduled' ||
initialConfigureState === 'pending'
) {
loadReportData(reportDataUrl, appInstanceId);

Expand All @@ -77,7 +72,8 @@ class ApplicationInstanceReport extends React.Component {
const { setActiveHost } = this.props;

const tabs = [];
for (const [index, value] of hosts.entries()) {
// for (const [index, value] of hosts.entries()) {
hosts.forEach((value, index) => {
tabs.push(
<VerticalTabs.Tab
id={index}
Expand All @@ -88,11 +84,12 @@ class ApplicationInstanceReport extends React.Component {
active={this.isActive(index)}
/>
);
}
});

return tabs;
}

// eslint-disable-next-line class-methods-use-this
lastReportStatus(host) {
if (!host.id) {
return (
Expand All @@ -105,7 +102,7 @@ class ApplicationInstanceReport extends React.Component {
</div>
);
}
const already_deployed_msg = __(
const alreadyDeployedMsg = __(
'Already existing host which was added to the application instance'
);
return (
Expand All @@ -114,7 +111,7 @@ class ApplicationInstanceReport extends React.Component {
Host: <a href={host.hostUrl}>{host.name}</a>
</span>
<span>&nbsp;|&nbsp;</span>
<span>State: {host.build == true ? 'in Build' : 'Deployed'}</span>
<span>State: {host.build === true ? 'in Build' : 'Deployed'}</span>
<span>&nbsp;|&nbsp;</span>
<span>
Power Status:{' '}
Expand All @@ -132,7 +129,7 @@ class ApplicationInstanceReport extends React.Component {
style={{ marginRight: 8, marginLeft: 2 }}
type="pf"
name="info"
title={already_deployed_msg}
title={alreadyDeployedMsg}
/>
</span>
) : (
Expand All @@ -144,33 +141,25 @@ class ApplicationInstanceReport extends React.Component {

render() {
const {
data: {
appInstanceId,
appInstanceName,
deployTaskUrl,
configureJobUrl,
reportDataUrl,
},
data: { deployTaskUrl, configureJobUrl },
activeHostId,
hosts,
deploymentState,
initialConfigureState,
hosts,
initialConfigureJobUrl,
initialConfigureState,
loading,
showInitialConfigureJob,
loadReportData,
} = this.props;

let tabs = [];
let reportStatus;
let report;

// This handles the first call to render() in which the state hosts is always empty
if (hosts.length == 0) {
if (hosts.length === 0) {
return <span>No host</span>;
}

tabs = this.collectLastReportData(hosts);
reportStatus = this.lastReportStatus(hosts[activeHostId]);
const tabs = this.collectLastReportData(hosts);
const reportStatus = this.lastReportStatus(hosts[activeHostId]);

if (hosts[activeHostId].progress_report) {
report = hosts[activeHostId].progress_report;
Expand All @@ -182,9 +171,10 @@ class ApplicationInstanceReport extends React.Component {
<div>
<div className="deploy_status_head">Host deployment state</div>
<div className="deploy_status_content">
{deploymentState != 'new' &&
deploymentState != 'finished' &&
deploymentState != 'failed' ? (
{loading ||
(deploymentState !== 'new' &&
deploymentState !== 'finished' &&
deploymentState !== 'failed') ? (
<span>
<Spinner loading size="sm" /> &nbsp;
</span>
Expand All @@ -200,25 +190,25 @@ class ApplicationInstanceReport extends React.Component {
<a href={deployTaskUrl}>Last deployment task</a>
</div>
</div>
{showInitialConfigureJob == true ? (
{showInitialConfigureJob === true ? (
<div>
<div className="deploy_status_head">Configuration job</div>
<div className="deploy_status_content">
{initialConfigureState == 'scheduled' ||
initialConfigureState == 'pending' ? (
{initialConfigureState === 'scheduled' ||
initialConfigureState === 'pending' ? (
<span>
<Spinner loading size="sm" /> &nbsp;
</span>
) : (
<span />
)}
{initialConfigureState != 'unconfigured' &&
initialConfigureState != 'scheduled' ? (
{initialConfigureState !== 'unconfigured' &&
initialConfigureState !== 'scheduled' ? (
<a href={initialConfigureJobUrl}>Configuration job</a>
) : (
<span />
)}
{initialConfigureState != 'unconfigured' ? (
{initialConfigureState !== 'unconfigured' ? (
<span>&nbsp; State: {initialConfigureState}</span>
) : (
<span />
Expand Down Expand Up @@ -248,34 +238,43 @@ class ApplicationInstanceReport extends React.Component {
}

ApplicationInstanceReport.defaultProps = {
error: {},
appInstanceName: '',
deployTaskUrl: '',
configureJobUrl: '',
hosts: [],
report: [],
data: {
initialConfigureJobUrl: undefined,
},
activeHostId: 0,
configureJobUrl: '',
deploymentState: 'unknown',
initialConfigureState: 'unknown',
deployTaskUrl: '',
hosts: [],
initialConfigureJobUrl: '',
initialConfigureState: 'unknown',
loading: false,
showInitialConfigureJob: false,
};

ApplicationInstanceReport.propTypes = {
initApplicationInstanceReport: PropTypes.func,
appInstanceName: PropTypes.string,
deployTaskUrl: PropTypes.string,
data: PropTypes.shape({
hosts: PropTypes.array.isRequired,
deploymentState: PropTypes.string.isRequired,
appInstanceId: PropTypes.number.isRequired,
reportDataUrl: PropTypes.string.isRequired,
deployTaskUrl: PropTypes.string.isRequired,
configureJobUrl: PropTypes.string.isRequired,
initialConfigureState: PropTypes.string.isRequired,
initialConfigureJobUrl: PropTypes.string,
}),
activeHostId: PropTypes.number,
configureJobUrl: PropTypes.string,
deploymentState: PropTypes.string,
initialConfigureState: PropTypes.string,
deployTaskUrl: PropTypes.string,
hosts: PropTypes.array,
initialConfigureJobUrl: PropTypes.string,
initialConfigureState: PropTypes.string,
loading: PropTypes.bool,
showInitialConfigureJob: PropTypes.bool,
hosts: PropTypes.array,
deploymentState: PropTypes.string,
report: PropTypes.array,
setActiveHost: PropTypes.func,
loadReportData: PropTypes.func,
activeHostId: PropTypes.number,
initApplicationInstanceReport: PropTypes.func.isRequired,
loadReportData: PropTypes.func.isRequired,
setActiveHost: PropTypes.func.isRequired,
};

export default ApplicationInstanceReport;
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import React from 'react';
import api from 'foremanReact/API';

import { actionHeaderCellFormatter } from 'patternfly-react';

import {
propsToSnakeCase,
propsToCamelCase,
} from 'foremanReact/common/helpers';

import {
APPLICATION_INSTANCE_REPORT_INIT,
APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST,
Expand All @@ -31,7 +23,7 @@ export const initApplicationInstanceReport = (

// Decide if it should show only the initial Configure job state + URL or
// the URL to all configuration jobs
if (initialConfigureState == 'unconfigured') {
if (initialConfigureState === 'unconfigured') {
initialState.showInitialConfigureJob = true;
} else {
initialState.showInitialConfigureJob = false;
Expand All @@ -43,25 +35,26 @@ export const initApplicationInstanceReport = (
});
};

export const loadReportData = (reportDataUrl, appInstanceId) => dispatch => {
export const loadReportData = (
reportDataUrl,
appInstanceId
) => async dispatch => {
dispatch({ type: APPLICATION_INSTANCE_REPORT_LOAD_REPORT_REQUEST });

const baseUrl = reportDataUrl;
const realUrl = baseUrl.replace('__id__', appInstanceId);

return api
.get(realUrl, {}, {})
.then(({ data }) =>
dispatch({
type: APPLICATION_INSTANCE_REPORT_LOAD_REPORT_SUCCESS,
payload: { ...data },
})
)
.catch(error =>
dispatch(
errorHandler(APPLICATION_INSTANCE_REPORT_LOAD_REPORT_FAILURE, error)
)
try {
const { data } = await api.get(realUrl, {}, {});
dispatch({
type: APPLICATION_INSTANCE_REPORT_LOAD_REPORT_SUCCESS,
payload: { ...data },
});
} catch (error) {
dispatch(
errorHandler(APPLICATION_INSTANCE_REPORT_LOAD_REPORT_FAILURE, error)
);
}
};

const errorHandler = (msg, err) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Immutable from 'seamless-immutable';

import { cloneDeep, findIndex, findLastIndex } from 'lodash';

import {
APPLICATION_INSTANCE_REPORT_INIT,
APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST,
Expand All @@ -24,25 +22,28 @@ const applicationInstanceReport = (state = initialState, action) => {
}
case APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST: {
return state.merge({
loading: true,
activeHostId: payload.activeHostId,
});
}
case APPLICATION_INSTANCE_REPORT_LOAD_REPORT_REQUEST: {
// Nothing to do
return state;
return state.merge({
loading: true,
});
}
case APPLICATION_INSTANCE_REPORT_LOAD_REPORT_SUCCESS: {
return state.merge({
deploymentState: payload.deploymentState,
initialConfigureState: payload.initialConfigureState,
initialConfigureJobUrl: payload.initialConfigureJobUrl,
hosts: payload.hosts,
loading: false,
});
}
case APPLICATION_INSTANCE_REPORT_LOAD_REPORT_FAILURE: {
console.log(`Error while loading report data: ${payload.error}`);
return state.merge({ error: payload.error });
return state.merge({
error: payload.error,
loading: false,
});
}
default: {
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ const fixtures = {
deployTaskUrl: 'deploy/task/url',
configureJobUrl: 'configure/job/url',
hosts: hostData,
deploymentState: 'finished',
appInstanceId: 1,
reportDataUrl: '/acd/ui_acd_report_data/__id__',
initialConfigureState: 'unconfigured',
},
initApplicationInstanceReport: noop,
loadReportData: noop,
setActiveHost: noop,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ Object {
],
},
],
"loading": true,
"name": false,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ ReportViewer.propTypes = {
report: PropTypes.array,
};

ReportViewer.defaultProps = {
hidden: false,
report: undefined,
};

export default ReportViewer;

0 comments on commit 78790d5

Please sign in to comment.