diff --git a/webpack/ForemanRhCloudFills.js b/webpack/ForemanRhCloudFills.js
index acb78a14d..076f063fb 100644
--- a/webpack/ForemanRhCloudFills.js
+++ b/webpack/ForemanRhCloudFills.js
@@ -4,7 +4,11 @@ import { translate as __ } from 'foremanReact/common/I18n';
import InventoryAutoUploadSwitcher from './ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload';
import NewHostDetailsTab from './InsightsHostDetailsTab/NewHostDetailsTab';
import { InsightsTotalRiskChartWrapper } from './InsightsHostDetailsTab/InsightsTotalRiskChartWrapper';
-import { isNotRhelHost, vulnerabilityDisabled } from './ForemanRhCloudHelpers';
+import {
+ isNotRhelHost,
+ vulnerabilityDisabled,
+ hasNoInsightsFacet,
+} from './ForemanRhCloudHelpers';
import CVEsHostDetailsTabWrapper from './CVEsHostDetailsTab/CVEsHostDetailsTab';
const fills = [
@@ -20,7 +24,7 @@ const fills = [
component: props => ,
weight: 400,
metadata: {
- hideTab: isNotRhelHost,
+ hideTab: props => isNotRhelHost(props) || hasNoInsightsFacet(props),
title: __('Recommendations'),
},
},
diff --git a/webpack/ForemanRhCloudHelpers.js b/webpack/ForemanRhCloudHelpers.js
index 843980516..8e54bcf9b 100644
--- a/webpack/ForemanRhCloudHelpers.js
+++ b/webpack/ForemanRhCloudHelpers.js
@@ -14,3 +14,7 @@ export const isNotRhelHost = ({ hostDetails }) =>
export const vulnerabilityDisabled = ({ hostDetails }) =>
isNotRhelHost({ hostDetails }) || !hostDetails?.vulnerability?.enabled;
+
+export const hasNoInsightsFacet = ({ response, hostDetails }) =>
+ // eslint-disable-next-line camelcase
+ !(response?.insights_attributes || hostDetails?.insights_attributes);
diff --git a/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js b/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js
index 1ab55b0dc..c11e08cf1 100644
--- a/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js
+++ b/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js
@@ -131,28 +131,15 @@ const IopInsightsTabWrapped = props => (
);
const InsightsTab = props => {
- const { response } = props;
- const isLocalAdvisorEngine =
- // eslint-disable-next-line camelcase
- response?.insights_attributes?.use_iop_mode;
+ const isLocalIop = useAdvisorEngineConfig();
- return isLocalAdvisorEngine ? (
+ return isLocalIop ? (
) : (
);
};
-InsightsTab.propTypes = {
- response: PropTypes.shape({
- insights_attributes: {
- use_iop_mode: PropTypes.bool,
- },
- }),
-};
-
-InsightsTab.defaultProps = {
- response: {},
-};
+InsightsTab.defaultProps = {};
export default InsightsTab;
diff --git a/webpack/__tests__/ForemanRhCloudHelpers.test.js b/webpack/__tests__/ForemanRhCloudHelpers.test.js
index 4f4cb5b03..bb957e4dd 100644
--- a/webpack/__tests__/ForemanRhCloudHelpers.test.js
+++ b/webpack/__tests__/ForemanRhCloudHelpers.test.js
@@ -1,5 +1,5 @@
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
-import { foremanUrl, vulnerabilityDisabled } from '../ForemanRhCloudHelpers';
+import { foremanUrl, vulnerabilityDisabled, hasNoInsightsFacet } from '../ForemanRhCloudHelpers';
global.URL_PREFIX = 'MY_TEST_URL_PREFIX.example.com';
@@ -34,6 +34,21 @@ const fixtures = {
}),
'vulnerabilityDisabled returns true for missing hostDetails': () =>
vulnerabilityDisabled({}),
+ 'hasNoInsightsFacet returns false when insights_attributes is present': () =>
+ hasNoInsightsFacet({
+ response: {
+ insights_attributes: {
+ uuid: 'test-uuid',
+ insights_hits_count: 5,
+ },
+ },
+ }),
+ 'hasNoInsightsFacet returns true when insights_attributes is missing': () =>
+ hasNoInsightsFacet({
+ response: {},
+ }),
+ 'hasNoInsightsFacet returns true when response is missing': () =>
+ hasNoInsightsFacet({}),
};
describe('ForemanRhCloud helpers', () =>
diff --git a/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap b/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap
index 1fc408339..1bbd8a13c 100644
--- a/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap
+++ b/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`ForemanRhCloud helpers hasNoInsightsFacet returns false when insights_attributes is present 1`] = `false`;
+
+exports[`ForemanRhCloud helpers hasNoInsightsFacet returns true when insights_attributes is missing 1`] = `true`;
+
+exports[`ForemanRhCloud helpers hasNoInsightsFacet returns true when response is missing 1`] = `true`;
+
exports[`ForemanRhCloud helpers should return foreman Url 1`] = `"MY_TEST_URL_PREFIX.example.com/test_path"`;
exports[`ForemanRhCloud helpers vulnerabilityDisabled returns false for RHEL host with vulnerability enabled 1`] = `false`;