Skip to content

Commit

Permalink
Fixes #910 - Insights tab displayed for non-RHEL hosts
Browse files Browse the repository at this point in the history
- Add helper-function isNotRhelHost
- Hide insights tab based on host-OS
- Hide TotalRisk card based on host-OS
  • Loading branch information
Thorben-D authored and chris1984 committed Oct 22, 2024
1 parent f8f2f49 commit 4b34441
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
24 changes: 15 additions & 9 deletions webpack/ForemanRhCloudFills.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { addGlobalFill } from 'foremanReact/components/common/Fill/GlobalFill';
import InventoryAutoUploadSwitcher from './ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload';
import NewHostDetailsTab from './InsightsHostDetailsTab/NewHostDetailsTab';
import InsightsTotalRiskCard from './InsightsHostDetailsTab/InsightsTotalRiskChart';
import { InsightsTotalRiskChartWrapper } from './InsightsHostDetailsTab/InsightsTotalRiskChartWrapper';
import { isNotRhelHost } from './ForemanRhCloudHelpers';

const fills = [
{
Expand All @@ -16,22 +17,27 @@ const fills = [
name: 'Insights',
component: props => <NewHostDetailsTab {...props} />,
weight: 400,
metadata: {
hideTab: isNotRhelHost,
},
},
{
slot: 'host-overview-cards',
name: 'insights-total-risk-chart',
component: props => <InsightsTotalRiskCard {...props} />,
component: props => <InsightsTotalRiskChartWrapper {...props} />,
weight: 2800,
},
];

export const registerFills = () => {
fills.forEach(({ slot, name, component: Component, weight }, index) =>
addGlobalFill(
slot,
name,
<Component key={`rh-cloud-fill-${index}`} />,
weight
)
fills.forEach(
({ slot, name, component: Component, weight, metadata }, index) =>
addGlobalFill(
slot,
name,
<Component key={`rh-cloud-fill-${index}`} />,
weight,
metadata
)
);
};
4 changes: 4 additions & 0 deletions webpack/ForemanRhCloudHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
* should be imported once core moves it to the ReactApp folder.
*/
export const foremanUrl = path => `${window.URL_PREFIX}${path}`;

export const isNotRhelHost = ({ hostDetails }) =>
// eslint-disable-next-line camelcase
!new RegExp('red\\s?hat', 'i').test(hostDetails?.operatingsystem_name);
23 changes: 23 additions & 0 deletions webpack/InsightsHostDetailsTab/InsightsTotalRiskChartWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import InsightsTotalRiskChart from './InsightsTotalRiskChart';
import { isNotRhelHost } from '../ForemanRhCloudHelpers';

export const InsightsTotalRiskChartWrapper = props => {
if (props.status === 'RESOLVED') {
return (
!isNotRhelHost(props.hostDetails) && <InsightsTotalRiskChart {...props} /> // check for RHEL hosts
);
}
return null;
};

InsightsTotalRiskChartWrapper.propTypes = {
status: PropTypes.string,
hostDetails: PropTypes.object,
};

InsightsTotalRiskChartWrapper.defaultProps = {
status: 'PENDING',
hostDetails: {},
};

0 comments on commit 4b34441

Please sign in to comment.