diff --git a/webpack/components/extensions/HostDetails/Tabs/ContentTab/actions.js b/webpack/components/extensions/HostDetails/Tabs/ContentTab/actions.js new file mode 100644 index 00000000000..5986f1277ba --- /dev/null +++ b/webpack/components/extensions/HostDetails/Tabs/ContentTab/actions.js @@ -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; diff --git a/webpack/components/extensions/HostDetails/Tabs/ContentTab/constants.js b/webpack/components/extensions/HostDetails/Tabs/ContentTab/constants.js index e6289f46736..f369b4ba37a 100644 --- a/webpack/components/extensions/HostDetails/Tabs/ContentTab/constants.js +++ b/webpack/components/extensions/HostDetails/Tabs/ContentTab/constants.js @@ -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') }, @@ -13,3 +15,4 @@ const SECONDARY_TABS = [ ]; export default SECONDARY_TABS; + diff --git a/webpack/components/extensions/HostDetails/Tabs/ContentTab/index.js b/webpack/components/extensions/HostDetails/Tabs/ContentTab/index.js index 9708d5590fb..528e09925cc 100644 --- a/webpack/components/extensions/HostDetails/Tabs/ContentTab/index.js +++ b/webpack/components/extensions/HostDetails/Tabs/ContentTab/index.js @@ -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 ( { - 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']; diff --git a/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js b/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js index d3ff74425f2..e182a165bcb 100644 --- a/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js +++ b/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js @@ -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) { diff --git a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js index 789a9e8b52b..66bac2fe62f 100644 --- a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js +++ b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js @@ -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,