Skip to content

Commit

Permalink
Fixes #37144 - Use OS family for host details page packages tab
Browse files Browse the repository at this point in the history
  • Loading branch information
nadjaheitmann committed Feb 6, 2024
1 parent 383e45a commit b04e8b0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { API_OPERATIONS, get } from 'foremanReact/redux/API';
import { foremanApi } from '../../../../../services/api';
import { HOST_DETAILS_CONTENT_HOST_OS_KEY } from './constants';

export const getHostOs = osId => get({
type: API_OPERATIONS.GET,
key: HOST_DETAILS_CONTENT_HOST_OS_KEY,
url: foremanApi.getApiUrl(`/operatingsystems/${osId}`),
});
export default getHostOs;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { hideModuleStreamsTab } from '../ModuleStreamsTab/ModuleStreamsTab';
import { hideDebsTab } from '../DebsTab/DebsTab';
import { hidePackagesTab } from '../PackagesTab/PackagesTab';

export const HOST_DETAILS_CONTENT_HOST_OS_KEY = 'HOST_DETAILS_CONTENT_HOST_OS';

const SECONDARY_TABS = [
{ key: 'debs', hideTab: hideDebsTab, title: __('Packages') },
{ key: 'packages', hideTab: hidePackagesTab, title: __('Packages') },
Expand All @@ -13,3 +15,4 @@ const SECONDARY_TABS = [
];

export default SECONDARY_TABS;

23 changes: 19 additions & 4 deletions webpack/components/extensions/HostDetails/Tabs/ContentTab/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import React from 'react';
import React, { useCallback, useEffect } from 'react';
import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
import { Tabs, Tab, TabTitleText, PageSection } from '@patternfly/react-core';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { selectAPIResponse } from 'foremanReact/redux/API/APISelectors';
import SecondaryTabRoutes from './SecondaryTabsRoutes';
import { getHostOs } from './actions';
import { activeTab } from './helpers';
import SECONDARY_TABS from './constants';
import SECONDARY_TABS, { HOST_DETAILS_CONTENT_HOST_OS_KEY } from './constants';

const ContentTab = ({ location: { pathname } }) => {
const dispatch = useDispatch();
const hashHistory = useHistory();
const hostDetails = useSelector(state => selectAPIResponse(state, 'HOST_DETAILS'));

// we need OS family to safely distinguish between Debian and RH based systems
const getOs = useCallback(() => {
if (hostDetails?.operatingsystem_id) { dispatch(getHostOs(hostDetails.operatingsystem_id)); }
}, [dispatch, hostDetails]);

useEffect(() => {
getOs();
}, [hostDetails, getOs]);

const operatingsystem =
useSelector(state => selectAPIResponse(state, HOST_DETAILS_CONTENT_HOST_OS_KEY));

const filteredTabs =
SECONDARY_TABS?.filter(tab => !tab.hideTab?.({ hostDetails })) ?? [];
SECONDARY_TABS?.filter(tab => !tab.hideTab?.(tab.key === 'Repository sets' ? { hostDetails } : operatingsystem)) ?? [];
return (
<PageSection
variant="light"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ import { hasRequiredPermissions as can,
import SortableColumnHeaders from '../../../../Table/components/SortableColumnHeaders';
import { useRexJobPolling } from '../RemoteExecutionHooks';

export const hideDebsTab = ({ hostDetails }) => {
const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+|\D+)/);
if (!osMatch) return false;
const [, os] = osMatch;
return !(osMatch && os.match(/Debian|Ubuntu/i));
};
export const hideDebsTab = operatingsystem => !(operatingsystem?.family === 'Debian');

const invokeRexJobs = ['create_job_invocations'];
const createBookmarks = ['create_bookmarks'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ import {
userPermissionsFromHostDetails,
} from '../../hostDetailsHelpers';

const moduleStreamSupported = ({ os, version }) =>
os.match(/RedHat|RHEL|CentOS|Rocky|AlmaLinux|Oracle Linux/i) && Number(version) > 7;
export const hideModuleStreamsTab = ({ hostDetails }) => {
const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+)/);
if (!osMatch) return false;
const [, os, version] = osMatch;
return !(osMatch && moduleStreamSupported({ os, version }));
};
export const hideModuleStreamsTab = operatingsystem => !(operatingsystem?.family === 'Redhat' && Number(operatingsystem?.major > 7));

const EnabledIcon = ({ streamText, streamInstallStatus, upgradable }) => {
switch (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ import { runSubmanRepos } from '../../Cards/ContentViewDetailsCard/HostContentVi
const invokeRexJobs = ['create_job_invocations'];
const createBookmarks = ['create_bookmarks'];

export const hidePackagesTab = ({ hostDetails }) => {
const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+|\D+)/);
if (!osMatch) return false;
const [, os] = osMatch;
return !(osMatch && os.match(/RedHat|RHEL|CentOS|Rocky|AlmaLinux|Alma|Oracle Linux|Oracle|Suse Linux Enterprise Server|SLES/i));
};
export const hidePackagesTab = operatingsystem => !(operatingsystem?.family?.match(/RedHat|SUSE/i));

const UpdateVersionsSelect = ({
packageName,
Expand Down

0 comments on commit b04e8b0

Please sign in to comment.