diff --git a/package-lock.json b/package-lock.json index 748f45fd7..5a31d4edb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "insights-inventory-frontend", "version": "0.0.1", "dependencies": { "@patternfly/react-core": "4.168.8", diff --git a/src/components/InventoryDetail/ApplicationDetails.js b/src/components/InventoryDetail/ApplicationDetails.js index 5199f1ab2..3464c250c 100644 --- a/src/components/InventoryDetail/ApplicationDetails.js +++ b/src/components/InventoryDetail/ApplicationDetails.js @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { useSelector, useDispatch } from 'react-redux'; import { useLocation, useHistory } from 'react-router-dom'; @@ -14,11 +14,15 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { const history = useHistory(); const dispatch = useDispatch(); const searchParams = new URLSearchParams(search); - const items = useSelector(({ entityDetails }) => entityDetails?.activeApps); + const items = useSelector(({ entityDetails }) => entityDetails?.activeApps || []) + .filter(({ isVisible }) => isVisible !== false); const activeApp = useSelector(({ entityDetails }) => entityDetails?.activeApp); + const disabledApps = useSelector(({ systemProfileStore }) => systemProfileStore?.disabledApps); const defaultApp = activeApp?.appName || appList?.find(({ pageId, name }) => items?.[0]?.name === ( pageId || name))?.name || items?.[0]?.name; - const applications = appList || items; + let applications = appList || items; + const [activeTabs, setActiveTabs] = useState(applications); + useEffect(() => { /** * Initialize first inventory detail type @@ -29,6 +33,16 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { } }, []); + useEffect(() => { + const filteredResult = applications.filter(app => !disabledApps?.includes(app.name)); + if (filteredResult !== 0 && typeof filteredResult !== undefined) { + setActiveTabs(filteredResult); + } + else { + setActiveTabs(applications); + } + }, [disabledApps]); + return ( { @@ -37,7 +51,7 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { {...props} activeKey={ defaultApp } onSelect={ (event, item) => { - const activeItem = applications.find(oneApp => oneApp.name === item); + const activeItem = activeTabs.find(oneApp => oneApp.name === item); if (onTabSelect) { onTabSelect(event, item, activeItem); } else { @@ -50,7 +64,7 @@ const ApplicationDetails = ({ onTabSelect, appList, ...props }) => { isFilled className="ins-c-inventory-detail__app-tabs" > - { applications.map((item, key) => ( + { activeTabs?.map((item, key) => ( )) } diff --git a/src/components/InventoryTable/InventoryTable.js b/src/components/InventoryTable/InventoryTable.js index 5c4d44b7e..4c70f2868 100644 --- a/src/components/InventoryTable/InventoryTable.js +++ b/src/components/InventoryTable/InventoryTable.js @@ -129,8 +129,6 @@ const InventoryTable = forwardRef(({ // eslint-disable-line react/display-name const onRefreshData = (options = {}, disableOnRefresh) => { const { activeFilters } = store.getState().entities; const cachedProps = cache.current?.getProps() || {}; - - // eslint-disable-next-line camelcase const currPerPage = options?.per_page || options?.perPage || cachedProps.perPage; const params = { diff --git a/src/store/reducers.js b/src/store/reducers.js index 74655bfc9..fa3b4d82e 100644 --- a/src/store/reducers.js +++ b/src/store/reducers.js @@ -1,4 +1,10 @@ -import { INVENTORY_ACTION_TYPES, ACTION_TYPES, SELECT_ENTITY, SET_INVENTORY_FILTER, SET_PAGINATION } from './action-types'; +import { + INVENTORY_ACTION_TYPES, + ACTION_TYPES, + SELECT_ENTITY, + SET_INVENTORY_FILTER, + SET_PAGINATION +} from './action-types'; import systemProfileStore from './systemProfileStore'; import { ComplianceTab, @@ -64,6 +70,7 @@ function entityLoaded(state) { (!insights.chrome.isProd || (insights.chrome.isProd && insights?.chrome?.isBeta())) && { title: 'Resource Optimization', name: 'ros', + isVisible: false, component: RosTab } ].filter(Boolean) @@ -95,6 +102,17 @@ function entitySelected(state, { payload }) { }; } +function resourceOptTabVisibility(state, { payload }) { + return { + ...state, + activeApps: state.activeApps?.map((entity) => entity.name === 'ros' ? ({ + ...entity, + isVisible: payload + }) : entity + ) + }; +} + function entityDeleted(state, { meta }) { const selected = state.selected || (new Map()); meta.systems.forEach(id => selected.delete(id)); @@ -160,7 +178,8 @@ export const tableReducer = applyReducerHash( export const entitesDetailReducer = () => applyReducerHash( { - [INVENTORY_ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityLoaded + [INVENTORY_ACTION_TYPES.LOAD_ENTITY_FULFILLED]: entityLoaded, + [INVENTORY_ACTION_TYPES.LOAD_SYSTEM_PROFILE_FULFILLED]: resourceOptTabVisibility }, defaultState ); diff --git a/src/store/systemProfileStore.js b/src/store/systemProfileStore.js index 7f8309c3f..9684aa6a1 100644 --- a/src/store/systemProfileStore.js +++ b/src/store/systemProfileStore.js @@ -45,8 +45,13 @@ export function calculateInterfaces(interfaces) { export function onSystemProfile(state, { payload: { results } }) { const systemProfile = (results && results[0] && results[0].system_profile) || {}; + const cloudProviderObj = (results && results[0] && (typeof results[0].system_profile.cloud_provider !== 'undefined')) + && results[0].system_profile.cloud_provider; return { ...state, + disabledApps: [ + ...(cloudProviderObj === 'aws' || cloudProviderObj === 'azure') ? [] : ['ros'] + ], systemProfile: { loaded: true, ...systemProfile, diff --git a/src/store/systemProfileStore.test.js b/src/store/systemProfileStore.test.js index fd8c60425..8d61e217e 100644 --- a/src/store/systemProfileStore.test.js +++ b/src/store/systemProfileStore.test.js @@ -71,6 +71,7 @@ describe('systemProfilePending', () => { describe('onSystemProfile', () => { it('empty results', () => { expect(onSystemProfile(undefined, { payload: {} })).toEqual({ + disabledApps: ['ros'], systemProfile: { loaded: true, network: undefined,