Skip to content

Commit

Permalink
Try to fix ApplicationInstance component linting
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Apr 29, 2024
1 parent da39a02 commit dfb7bd0
Show file tree
Hide file tree
Showing 12 changed files with 837 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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}],
},
}
136 changes: 75 additions & 61 deletions webpack/components/ApplicationInstance/ApplicationInstance.js
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,
Expand Down Expand Up @@ -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() {
Expand All @@ -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'
);
Expand All @@ -60,31 +56,31 @@ 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`
)
);
});

invalidMaxServices.map(s => {
invalidMaxServices.forEach(s => {
msg += sprintf(
__(
`- service ${s.name} expects no more than ${s.axCount} configured hosts\n`
Expand All @@ -110,7 +106,6 @@ class ApplicationInstance extends React.Component {
supportedPlugins,
},
initApplicationInstance,
addApplicationInstanceHost,
deleteApplicationInstanceHost,
activateEditApplicationInstanceHost,
changeEditApplicationInstanceHost,
Expand All @@ -123,20 +118,20 @@ 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!'
);

const inlineEditButtonsFormatter = inlineEditFormatterFactory({
isEditing: additionalData => this.props.editMode,
renderValue: (value, additionalData) => (
<td style={{ padding: '2px' }}>
{additionalData.rowData.isExistingHost == true ? (
{additionalData.rowData.isExistingHost === true ? (
<Icon
style={{ marginRight: 8, marginLeft: 2 }}
type="pf"
name="info"
title={already_deployed_msg}
title={alreadyDeployedMsg}
/>
) : (
<span />
Expand All @@ -148,7 +143,7 @@ class ApplicationInstance extends React.Component {
<Icon type="pf" name="edit" title={__('Edit entry')} />
</Button>
&nbsp;
{additionalData.rowData.isExistingHost == false ? (
{additionalData.rowData.isExistingHost === false ? (
<Button
bsStyle="default"
onClick={() => openForemanParameterSelectionModal(additionalData)}
Expand Down Expand Up @@ -176,12 +171,12 @@ class ApplicationInstance extends React.Component {
),
renderEdit: (value, additionalData) => (
<td style={{ padding: '2px' }}>
{additionalData.rowData.isExistingHost == true ? (
{additionalData.rowData.isExistingHost === true ? (
<Icon
style={{ marginRight: 8, marginLeft: 2 }}
type="pf"
name="info"
title={already_deployed_msg}
title={alreadyDeployedMsg}
/>
) : (
<span />
Expand All @@ -190,7 +185,7 @@ class ApplicationInstance extends React.Component {
<Icon type="pf" name={__('edit')} />
</Button>
&nbsp;
{additionalData.rowData.isExistingHost == false ? (
{additionalData.rowData.isExistingHost === false ? (
<Button bsStyle="default" disabled>
<Icon type="pf" name={__('settings')} />
</Button>
Expand Down Expand Up @@ -248,21 +243,21 @@ 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];
}
return inlineEditFormatterImpl.renderValue(prettyValue, additionalData);
},
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');
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<span>
Expand All @@ -373,16 +370,16 @@ class ApplicationInstance extends React.Component {
<AppDefinitionSelector
label="Application Definition"
hidden={false}
editable={mode == 'newInstance'}
editable={mode === 'newInstance'}
viewText={appDefinition.name}
options={applications}
onChange={loadApplicationDefinition}
selectValue={appDefinition.id.toString()}
additionalData={{ url: appDefinitionUrl }}
/>
{appDefinition.id == '' ? (
{appDefinition.id === '' ? (
<div style={{ paddingTop: 25 }}>
<pre>App Definition can't be blank</pre>
<pre>App Definition can&apos;t be blank</pre>
</div>
) : (
<div />
Expand All @@ -409,7 +406,7 @@ class ApplicationInstance extends React.Component {
rowKey="id"
onRow={(rowData, { rowIndex }) => ({
role: 'row',
isEditing: () => this.isEditing({ rowData }),
isEditing: () => this.constructor.isEditing({ rowData }),
onCancel: () =>
cancelEditApplicationInstanceHost({ rowData, rowIndex }),
onConfirm: () =>
Expand Down Expand Up @@ -441,7 +438,7 @@ class ApplicationInstance extends React.Component {
</Button>
</span>
<span style={{ marginLeft: 30 }}>
Ansible group vars 'all':
Ansible group vars &lsquo;all&rsquo;:
<Button
style={{ marginLeft: 10 }}
bsStyle="default"
Expand Down Expand Up @@ -587,7 +584,7 @@ class ApplicationInstance extends React.Component {
</ForemanModal.Footer>
</ForemanModal>
</div>
{validateResult == false ? (
{validateResult === false ? (
<div style={{ paddingTop: 25 }}>
<pre>{validateMsg}</pre>
</div>
Expand All @@ -612,51 +609,68 @@ class ApplicationInstance extends React.Component {
}

ApplicationInstance.defaultProps = {
error: {},
showAlertModal: false,
alertModalText: '',
alertModalTitle: '',
ansibleVarsAll: [],
appDefinition: { id: '', name: '' },
columns: [],
data: {
appDefinitionUrl: '',
appDefinition: undefined,
applications: undefined,
foremanDataUrl: '',
supportedPlugins: {},
},
editMode: false,
services: [],
hiddenForemanParameterTypes: [],
hosts: [],
ansibleVarsAll: [],
parametersData: {},
columns: [],
hiddenForemanParameterTypes: [],
editParamsOfRowId: null,
paramEditMode: false,
services: [],
showAlertModal: false,
};

ApplicationInstance.propTypes = {
initApplicationInstance: PropTypes.func,
showAlertModal: PropTypes.bool,
alertModalText: PropTypes.string,
alertModalTitle: PropTypes.string,
editMode: PropTypes.bool.isRequired,
services: PropTypes.array,
ansibleVarsAll: PropTypes.array,
appDefinition: PropTypes.object,
columns: PropTypes.array,
data: PropTypes.shape({
appDefinitionUrl: PropTypes.string,
ansibleVarsAll: PropTypes.array.isRequired,
appDefinition: PropTypes.object,
applications: PropTypes.object,
foremanDataUrl: PropTypes.string,
hosts: PropTypes.array.isRequired,
location: PropTypes.string.isRequired,
mode: PropTypes.string.isRequired,
organization: PropTypes.string.isRequired,
supportedPlugins: PropTypes.object,
}),
editMode: PropTypes.bool,
hiddenForemanParameterTypes: PropTypes.array,
hosts: PropTypes.array,
ansibleVarsAll: PropTypes.array,
closeAlertModal: PropTypes.func,
loadApplicationDefinition: PropTypes.func,
addApplicationInstanceHost: PropTypes.func,
deleteApplicationInstanceHost: PropTypes.func,
activateEditApplicationInstanceHost: PropTypes.func,
confirmEditApplicationInstanceHost: PropTypes.func,
cancelEditApplicationInstanceHost: PropTypes.func,
changeEditApplicationInstanceHost: PropTypes.func,
openForemanParameterSelectionModal: PropTypes.func,
closeForemanParameterSelectionModal: PropTypes.func,
openAnsibleParameterSelectionModal: PropTypes.func,
closeAnsibleParameterSelectionModal: PropTypes.func,
openAddExistingHostsModal: PropTypes.func,
closeAddExistingHostsModal: PropTypes.func,
changeParameterSelectionMode: PropTypes.func,
parametersData: PropTypes.object,
paramEditMode: PropTypes.bool,
services: PropTypes.array,
showAlertModal: PropTypes.bool,
activateEditApplicationInstanceHost: PropTypes.func.isRequired,
addApplicationInstanceHost: PropTypes.func.isRequired,
cancelEditApplicationInstanceHost: PropTypes.func.isRequired,
changeEditApplicationInstanceHost: PropTypes.func.isRequired,
changeParameterSelectionMode: PropTypes.func.isRequired,
closeAddExistingHostsModal: PropTypes.func.isRequired,
closeAlertModal: PropTypes.func.isRequired,
closeAnsibleParameterSelectionModal: PropTypes.func.isRequired,
closeForemanParameterSelectionModal: PropTypes.func.isRequired,
confirmEditApplicationInstanceHost: PropTypes.func.isRequired,
deleteApplicationInstanceHost: PropTypes.func.isRequired,
initApplicationInstance: PropTypes.func.isRequired,
loadApplicationDefinition: PropTypes.func.isRequired,
openForemanParameterSelectionModal: PropTypes.func.isRequired,
openAnsibleParameterSelectionModal: PropTypes.func.isRequired,
openAddExistingHostsModal: PropTypes.func.isRequired,
};

export default ApplicationInstance;
Loading

0 comments on commit dfb7bd0

Please sign in to comment.