Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions webpack/ForemanRhCloudFills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -20,7 +24,7 @@ const fills = [
component: props => <NewHostDetailsTab {...props} />,
weight: 400,
metadata: {
hideTab: isNotRhelHost,
hideTab: props => isNotRhelHost(props) || hasNoInsightsFacet(props),
title: __('Recommendations'),
},
},
Expand Down
4 changes: 4 additions & 0 deletions webpack/ForemanRhCloudHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
19 changes: 3 additions & 16 deletions webpack/InsightsHostDetailsTab/NewHostDetailsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<IopInsightsTabWrapped {...props} />
) : (
<NewHostDetailsTab {...props} />
);
};

InsightsTab.propTypes = {
response: PropTypes.shape({
insights_attributes: {
use_iop_mode: PropTypes.bool,
},
}),
};

InsightsTab.defaultProps = {
response: {},
};
InsightsTab.defaultProps = {};

export default InsightsTab;
17 changes: 16 additions & 1 deletion webpack/__tests__/ForemanRhCloudHelpers.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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', () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down