Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #910 - Insights tab displayed for non-RHEL hosts #911

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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 }) =>
Thorben-D marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line camelcase
!new RegExp('red\\s?hat', 'i').test(hostDetails?.operatingsystem_name);
Copy link

@nadjaheitmann nadjaheitmann Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operatingsystem_name is not safe as this value can be changed by the user. As this plugin depends on Katello anyways, you can use hostDetails?.operatingsystem_family

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you will get the OS type Redhat for Alma, Rocky, etc. as well, so this is tricky... But maybe you can use it for a sanity check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no better check for this right now. I would just go with this solution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about checking at least for RHEL ? I don't know how people are naming their OSes these days.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on Redhat, these OS are created automatically from the imported Manifest.
Other areas will not work if OS name was changed, like https://github.com/theforeman/foreman/blob/develop/app/views/unattended/provisioning_templates/snippet/insights.erb#L10

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;
Thorben-D marked this conversation as resolved.
Show resolved Hide resolved
};

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

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