From 78790d5e19be529d4ff0ed9d8f9b3493f65d628a Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Fri, 26 Apr 2024 17:22:09 +0000 Subject: [PATCH] Try to fix ApplicationInstanceReport component linting --- .../ApplicationInstanceReport.js | 117 +++++++++--------- .../ApplicationInstanceReportActions.js | 37 +++--- .../ApplicationInstanceReportReducer.js | 15 +-- .../ApplicationInstanceReport.test.js | 6 + ...licationInstanceReportReducer.test.js.snap | 1 - .../components/ReportViewer.js | 5 + 6 files changed, 92 insertions(+), 89 deletions(-) diff --git a/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js b/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js index 7a7868ea..24caa8ab 100644 --- a/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +++ b/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import { Icon, Spinner } from 'patternfly-react'; @@ -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: { @@ -24,7 +20,6 @@ class ApplicationInstanceReport extends React.Component { initialConfigureJobUrl, }, initApplicationInstanceReport, - setActiveHost, } = this.props; initApplicationInstanceReport( @@ -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); @@ -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); @@ -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( ); - } + }); return tabs; } + // eslint-disable-next-line class-methods-use-this lastReportStatus(host) { if (!host.id) { return ( @@ -105,7 +102,7 @@ class ApplicationInstanceReport extends React.Component { ); } - const already_deployed_msg = __( + const alreadyDeployedMsg = __( 'Already existing host which was added to the application instance' ); return ( @@ -114,7 +111,7 @@ class ApplicationInstanceReport extends React.Component { Host: {host.name}  |  - State: {host.build == true ? 'in Build' : 'Deployed'} + State: {host.build === true ? 'in Build' : 'Deployed'}  |  Power Status:{' '} @@ -132,7 +129,7 @@ class ApplicationInstanceReport extends React.Component { style={{ marginRight: 8, marginLeft: 2 }} type="pf" name="info" - title={already_deployed_msg} + title={alreadyDeployedMsg} /> ) : ( @@ -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 No host; } - 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; @@ -182,9 +171,10 @@ class ApplicationInstanceReport extends React.Component {
Host deployment state
- {deploymentState != 'new' && - deploymentState != 'finished' && - deploymentState != 'failed' ? ( + {loading || + (deploymentState !== 'new' && + deploymentState !== 'finished' && + deploymentState !== 'failed') ? (   @@ -200,25 +190,25 @@ class ApplicationInstanceReport extends React.Component { Last deployment task
- {showInitialConfigureJob == true ? ( + {showInitialConfigureJob === true ? (
Configuration job
- {initialConfigureState == 'scheduled' || - initialConfigureState == 'pending' ? ( + {initialConfigureState === 'scheduled' || + initialConfigureState === 'pending' ? (   ) : ( )} - {initialConfigureState != 'unconfigured' && - initialConfigureState != 'scheduled' ? ( + {initialConfigureState !== 'unconfigured' && + initialConfigureState !== 'scheduled' ? ( Configuration job ) : ( )} - {initialConfigureState != 'unconfigured' ? ( + {initialConfigureState !== 'unconfigured' ? (   State: {initialConfigureState} ) : ( @@ -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; diff --git a/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js b/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js index 2f52788d..a0628b44 100644 --- a/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +++ b/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js @@ -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, @@ -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; @@ -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) => { diff --git a/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js b/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js index d9da5cb7..964bb160 100644 --- a/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +++ b/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js @@ -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, @@ -24,13 +22,13 @@ 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({ @@ -38,11 +36,14 @@ const applicationInstanceReport = (state = initialState, action) => { 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; diff --git a/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js b/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js index 1f1d2214..14a70a7e 100644 --- a/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +++ b/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js @@ -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, }, }; diff --git a/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap b/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap index 9e3335f3..fb434582 100644 --- a/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +++ b/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap @@ -712,7 +712,6 @@ Object { ], }, ], - "loading": true, "name": false, } `; diff --git a/webpack/components/ApplicationInstanceReport/components/ReportViewer.js b/webpack/components/ApplicationInstanceReport/components/ReportViewer.js index 19917ca3..83efcf6a 100644 --- a/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +++ b/webpack/components/ApplicationInstanceReport/components/ReportViewer.js @@ -22,4 +22,9 @@ ReportViewer.propTypes = { report: PropTypes.array, }; +ReportViewer.defaultProps = { + hidden: false, + report: undefined, +}; + export default ReportViewer;