From dfb7bd07f5925732fbdbbdfd95a9124b1a534144 Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Mon, 29 Apr 2024 08:38:50 +0000 Subject: [PATCH] Try to fix ApplicationInstance component linting --- .eslintrc | 2 +- .../ApplicationInstance.js | 136 ++-- .../ApplicationInstanceActions.js | 47 +- .../ApplicationInstanceHelper.js | 2 +- .../ApplicationInstanceReducer.js | 52 +- .../__tests__/ApplicationInstance.test.js | 85 ++- .../ApplicationInstance.test.js.snap | 608 +++++++++++++++++- .../components/AppDefinitionSelector.js | 9 + .../ApplicationInstance/components/Service.js | 7 +- .../components/ServiceCounter.js | 38 +- webpack/helper.js | 7 - webpack/helper.test.js | 9 - 12 files changed, 837 insertions(+), 165 deletions(-) diff --git a/.eslintrc b/.eslintrc index b804a6ea..6c79457e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,6 @@ // avoid https://github.com/prettier/eslint-config-prettier/issues/29 "standard/computed-property-even-spacing": 0, //"eqeqeq": "warn", - "max-lines": ["error", {"max": 550, "skipBlankLines": true, "skipComments": true}], + "max-lines": ["error", {"max": 650, "skipBlankLines": true, "skipComments": true}], }, } diff --git a/webpack/components/ApplicationInstance/ApplicationInstance.js b/webpack/components/ApplicationInstance/ApplicationInstance.js index 8b6ecec6..158d10c9 100644 --- a/webpack/components/ApplicationInstance/ApplicationInstance.js +++ b/webpack/components/ApplicationInstance/ApplicationInstance.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import { Icon, @@ -28,16 +28,12 @@ import { } from '../ParameterSelection/ParameterSelectionConstants'; class ApplicationInstance extends React.Component { - constructor(props) { - super(props); - } - - isEditing({ rowData }) { + static isEditing({ rowData }) { return rowData.backup !== undefined; } changeDataAllowed() { - return this.props.editMode || this.props.appDefinition.id == ''; + return this.props.editMode || this.props.appDefinition.id === ''; } validateParameters() { @@ -46,11 +42,11 @@ class ApplicationInstance extends React.Component { this.props.hosts.forEach(h => { if ( - h.foremanParameters.map(e => e.value).filter(i => i == '').length > 0 + h.foremanParameters.map(e => e.value).filter(i => i === '').length > 0 ) { result = false; - if (msg == '') { + if (msg === '') { msg += __( 'For some hosts the values for some parameters are missing. Check the values for these hosts:\n' ); @@ -60,23 +56,23 @@ class ApplicationInstance extends React.Component { }); const invalidMinServices = this.props.services.filter( - s => Number(s.minCount) != 0 && s.currentCount < s.minCount + s => Number(s.minCount) !== 0 && s.currentCount < s.minCount ); const invalidMaxServices = this.props.services.filter( - s => Number(s.maxCount) != 0 && s.currentCount > s.maxCount + s => Number(s.maxCount) !== 0 && s.currentCount > s.maxCount ); if (invalidMinServices.length > 0 || invalidMaxServices.length > 0) { result = false; - if (msg != '') { + if (msg !== '') { msg += '\n'; } msg += __('Unachieved service counts:'); msg += '\n'; - invalidMinServices.map(s => { + invalidMinServices.forEach(s => { msg += sprintf( __( `- service ${s.name} expects at ${s.minCount} least configured hosts\n` @@ -84,7 +80,7 @@ class ApplicationInstance extends React.Component { ); }); - invalidMaxServices.map(s => { + invalidMaxServices.forEach(s => { msg += sprintf( __( `- service ${s.name} expects no more than ${s.axCount} configured hosts\n` @@ -110,7 +106,6 @@ class ApplicationInstance extends React.Component { supportedPlugins, }, initApplicationInstance, - addApplicationInstanceHost, deleteApplicationInstanceHost, activateEditApplicationInstanceHost, changeEditApplicationInstanceHost, @@ -123,7 +118,7 @@ class ApplicationInstance extends React.Component { loadApplicationDefinition(appDefinition.id, { url: appDefinitionUrl }); } - const already_deployed_msg = __( + const alreadyDeployedMsg = __( 'This is an already deployed host. Changing the parameters is not possible!' ); @@ -131,12 +126,12 @@ class ApplicationInstance extends React.Component { isEditing: additionalData => this.props.editMode, renderValue: (value, additionalData) => ( - {additionalData.rowData.isExistingHost == true ? ( + {additionalData.rowData.isExistingHost === true ? ( ) : ( @@ -148,7 +143,7 @@ class ApplicationInstance extends React.Component {   - {additionalData.rowData.isExistingHost == false ? ( + {additionalData.rowData.isExistingHost === false ? (   - {additionalData.rowData.isExistingHost == false ? ( + {additionalData.rowData.isExistingHost === false ? ( @@ -248,10 +243,10 @@ class ApplicationInstance extends React.Component { }; const inlineEditFormatter = inlineEditFormatterFactory({ - isEditing: additionalData => this.isEditing(additionalData), + isEditing: additionalData => this.constructor.isEditing(additionalData), renderValue: (value, additionalData) => { let prettyValue = value; - if (additionalData.property == 'service') { + if (additionalData.property === 'service') { const serviceList = arrayToObject(this.props.services, 'id', 'name'); prettyValue = serviceList[value]; } @@ -259,10 +254,10 @@ class ApplicationInstance extends React.Component { }, renderEdit: (value, additionalData) => { let prettyValue = value; - if (additionalData.property == 'service') { + if (additionalData.property === 'service') { const availableServices = this.props.services.filter( service => - Number(service.maxCount) == 0 || + Number(service.maxCount) === 0 || service.currentCount < service.maxCount ); const serviceList = arrayToObject(availableServices, 'id', 'name'); @@ -280,7 +275,7 @@ class ApplicationInstance extends React.Component { additionalData ); } - if (additionalData.property == 'hostname') { + if (additionalData.property === 'hostname') { if (additionalData.rowData.newEntry === true) { return inlineEditFormatterImpl.renderEditText( value, @@ -344,11 +339,13 @@ class ApplicationInstance extends React.Component { const { validateResult, validateMsg } = this.validateParameters(); - if (validateResult == false) { + /* eslint-disable jquery/no-attr */ + if (validateResult === false) { $('input[type="submit"][name="commit"]').attr('disabled', true); } else { $('input[type="submit"][name="commit"]').attr('disabled', false); } + /* eslint-enable jquery/no-attr */ return ( @@ -373,16 +370,16 @@ class ApplicationInstance extends React.Component {