Skip to content

Commit

Permalink
fix(RemediationsButton): RHICOMPL-1456 - Ensure supported is passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
bastilian committed Feb 25, 2021
1 parent 6ac050e commit 6a6e2f5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class ComplianceRemediationButton extends React.Component {
dataProvider = () => {
const { allSystems, selectedRules } = this.props;
const result = { systems: [], issues: [] };
allSystems.forEach(async (system) => {
system.supported === true && result.systems.push(system.id);

allSystems.filter((system) => (system.supported)).forEach(async (system) => {
result.systems.push(system.id);

if (selectedRules.length !== 0) {
result.issues.push(this.rulesWithRemediations(selectedRules, system));
Expand All @@ -58,9 +59,15 @@ class ComplianceRemediationButton extends React.Component {
});
}

notEmptyData = async () => {
const data = await this.dataProvider();
return data.issues.length > 0 && data.systems.length > 0;
}

remediationAvailable = () => {
const { allSystems, selectedRules } = this.props;
let rules = selectedRules.length ? selectedRules : allSystems.flatMap((system) => system.ruleObjectsFailed);

return rules.some((rule) => (
rule.remediationAvailable &&
(
Expand All @@ -77,10 +84,9 @@ class ComplianceRemediationButton extends React.Component {
return (
<React.Fragment>
<RemediationButton
isDisabled={ !this.remediationAvailable() }
isDisabled={ !(this.remediationAvailable() && this.notEmptyData()) }
onRemediationCreated={ result => addNotification(result.getNotification()) }
dataProvider={ this.dataProvider }
>
dataProvider={ this.dataProvider }>
<AnsibeTowerIcon size='sm' color='var(--pf-c-button--m-primary--Color)' />
&nbsp;Remediate
</RemediationButton>
Expand All @@ -94,6 +100,7 @@ ComplianceRemediationButton.propTypes = {
allSystems: propTypes.arrayOf(propTypes.shape({
id: propTypes.string,
name: propTypes.string,
supported: propTypes.bool.isRequired,
profiles: propTypes.arrayOf(propTypes.shape({
refId: propTypes.string,
name: propTypes.string,
Expand Down
1 change: 1 addition & 0 deletions packages/inventory-compliance/src/Fixtures/Fixtures.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ class SystemRulesTable extends React.Component {
{ remediationsEnabled &&
<ToolbarItem>
<ComplianceRemediationButton
allSystems={ [{ id: system.id, profiles: system.testResultProfiles, ruleObjectsFailed: [] }] }
allSystems={ [{
id: system.id,
profiles: system.testResultProfiles,
ruleObjectsFailed: [],
supported: system.supported
}] }
selectedRules={ selectedRulesWithRemediations } />
</ToolbarItem>
}
Expand Down Expand Up @@ -382,7 +387,12 @@ SystemRulesTable.propTypes = {
profileRules: propTypes.array,
loading: propTypes.bool,
hidePassed: propTypes.bool,
system: propTypes.object,
system: propTypes.shape(
{
id: propTypes.string.isRequired,
supported: propTypes.bool.isRequired
}
),
remediationsEnabled: propTypes.bool,
tailoringEnabled: propTypes.bool,
selectedRefIds: propTypes.array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ exports[`SystemRulesTable component should render 1`] = `
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -1367,6 +1368,7 @@ exports[`SystemRulesTable component should render filtered and search mixed resu
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -1739,6 +1741,7 @@ exports[`SystemRulesTable component should render search results by rule name 1`
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -2165,6 +2168,7 @@ exports[`SystemRulesTable component should render search results on any page, re
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -2582,6 +2586,7 @@ exports[`SystemRulesTable component should render sorted rows 1`] = `
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -3677,6 +3682,7 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -5805,6 +5811,7 @@ exports[`SystemRulesTable component tailoring rules should be able to filter by
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -6129,6 +6136,7 @@ exports[`SystemRulesTable component tailoring rules should be able to filter by
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down Expand Up @@ -7086,6 +7094,7 @@ exports[`SystemRulesTable component tailoring rules should be able to show all s
},
],
"ruleObjectsFailed": Array [],
"supported": true,
},
]
}
Expand Down

0 comments on commit 6a6e2f5

Please sign in to comment.