Skip to content

Commit df4799c

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

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

webpack/ForemanRhCloudFills.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ 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 {
8+
isNotRhelHost,
9+
vulnerabilityDisabled,
10+
hasNoInsightsFacet,
11+
} from './ForemanRhCloudHelpers';
812
import CVEsHostDetailsTabWrapper from './CVEsHostDetailsTab/CVEsHostDetailsTab';
913

1014
const fills = [
@@ -20,7 +24,7 @@ const fills = [
2024
component: props => <NewHostDetailsTab {...props} />,
2125
weight: 400,
2226
metadata: {
23-
hideTab: isNotRhelHost,
27+
hideTab: props => isNotRhelHost(props) || hasNoInsightsFacet(props),
2428
title: __('Recommendations'),
2529
},
2630
},

webpack/ForemanRhCloudHelpers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ export const isNotRhelHost = ({ hostDetails }) =>
1212
hostDetails?.operatingsystem_name
1313
);
1414

15-
export const vulnerabilityDisabled = ({ hostDetails }) =>
16-
isNotRhelHost({ hostDetails }) || !hostDetails?.vulnerability?.enabled;
15+
export const vulnerabilityDisabled = ({ hostDetails, response }) =>
16+
isNotRhelHost({ hostDetails, response }) || !(hostDetails?.vulnerability?.enabled || response?.vulnerability?.enabled);
17+
18+
export const hasNoInsightsFacet = ({ response, hostDetails }) =>
19+
// eslint-disable-next-line camelcase
20+
!(response?.insights_attributes || hostDetails?.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)