Skip to content

Commit f89919a

Browse files
committed
SAT-37817 - Show correct Recommendations for iop non registered hosts
1 parent 76d6f60 commit f89919a

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

webpack/ForemanRhCloudFills.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
44
import InventoryAutoUploadSwitcher from './ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload';
55
import NewHostDetailsTab from './InsightsHostDetailsTab/NewHostDetailsTab';
66
import { InsightsTotalRiskChartWrapper } from './InsightsHostDetailsTab/InsightsTotalRiskChartWrapper';
7-
import { isNotRhelHost, vulnerabilityDisabled } from './ForemanRhCloudHelpers';
7+
import { isNotRhelHost, vulnerabilityDisabled, hasNoInsightsFacet } from './ForemanRhCloudHelpers';
88
import CVEsHostDetailsTabWrapper from './CVEsHostDetailsTab/CVEsHostDetailsTab';
99

1010
const fills = [
@@ -20,7 +20,7 @@ const fills = [
2020
component: props => <NewHostDetailsTab {...props} />,
2121
weight: 400,
2222
metadata: {
23-
hideTab: isNotRhelHost,
23+
hideTab: props => isNotRhelHost(props) || hasNoInsightsFacet(props),
2424
title: __('Recommendations'),
2525
},
2626
},

webpack/ForemanRhCloudHelpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ export const isNotRhelHost = ({ hostDetails }) =>
1414

1515
export const vulnerabilityDisabled = ({ hostDetails }) =>
1616
isNotRhelHost({ hostDetails }) || !hostDetails?.vulnerability?.enabled;
17+
18+
export const hasNoInsightsFacet = ({ response }) =>
19+
// Check if the host has insights_attributes, which indicates presence of insights_facet
20+
!response?.insights_attributes;

webpack/InsightsHostDetailsTab/NewHostDetailsTab.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,15 @@ const IopInsightsTabWrapped = props => (
131131
);
132132

133133
const InsightsTab = props => {
134-
const { response } = props;
135-
const isLocalAdvisorEngine =
136-
// eslint-disable-next-line camelcase
137-
response?.insights_attributes?.use_iop_mode;
134+
const isLocalIop = useAdvisorEngineConfig();
138135

139-
return isLocalAdvisorEngine ? (
136+
return isLocalIop ? (
140137
<IopInsightsTabWrapped {...props} />
141138
) : (
142139
<NewHostDetailsTab {...props} />
143140
);
144141
};
145142

146-
InsightsTab.propTypes = {
147-
response: PropTypes.shape({
148-
insights_attributes: {
149-
use_iop_mode: PropTypes.bool,
150-
},
151-
}),
152-
};
153-
154-
InsightsTab.defaultProps = {
155-
response: {},
156-
};
143+
InsightsTab.defaultProps = {};
157144

158145
export default InsightsTab;

webpack/__tests__/ForemanRhCloudHelpers.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
2-
import { foremanUrl, vulnerabilityDisabled } from '../ForemanRhCloudHelpers';
2+
import { foremanUrl, vulnerabilityDisabled, hasNoInsightsFacet } from '../ForemanRhCloudHelpers';
33

44
global.URL_PREFIX = 'MY_TEST_URL_PREFIX.example.com';
55

@@ -34,6 +34,21 @@ const fixtures = {
3434
}),
3535
'vulnerabilityDisabled returns true for missing hostDetails': () =>
3636
vulnerabilityDisabled({}),
37+
'hasNoInsightsFacet returns false when insights_attributes is present': () =>
38+
hasNoInsightsFacet({
39+
response: {
40+
insights_attributes: {
41+
uuid: 'test-uuid',
42+
insights_hits_count: 5,
43+
},
44+
},
45+
}),
46+
'hasNoInsightsFacet returns true when insights_attributes is missing': () =>
47+
hasNoInsightsFacet({
48+
response: {},
49+
}),
50+
'hasNoInsightsFacet returns true when response is missing': () =>
51+
hasNoInsightsFacet({}),
3752
};
3853

3954
describe('ForemanRhCloud helpers', () =>

webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`ForemanRhCloud helpers hasNoInsightsFacet returns false when insights_attributes is present 1`] = `false`;
4+
5+
exports[`ForemanRhCloud helpers hasNoInsightsFacet returns true when insights_attributes is missing 1`] = `true`;
6+
7+
exports[`ForemanRhCloud helpers hasNoInsightsFacet returns true when response is missing 1`] = `true`;
8+
39
exports[`ForemanRhCloud helpers should return foreman Url 1`] = `"MY_TEST_URL_PREFIX.example.com/test_path"`;
410

511
exports[`ForemanRhCloud helpers vulnerabilityDisabled returns false for RHEL host with vulnerability enabled 1`] = `false`;

0 commit comments

Comments
 (0)