From 7e8f0a936be11a1c09fbc60ad2ec99a1c636a537 Mon Sep 17 00:00:00 2001 From: Adelia Ferreira Date: Wed, 4 Oct 2023 12:51:22 +0100 Subject: [PATCH] feat:(THEEDGE-3527): Added Behavior related on Immutable tab and Conventional Signed-off-by: Adelia Ferreira --- src/Utilities/constants.js | 5 +++ .../InventoryTabs/HybridInventoryTabs.js | 45 +++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Utilities/constants.js b/src/Utilities/constants.js index a65eaed73..fff836df2 100644 --- a/src/Utilities/constants.js +++ b/src/Utilities/constants.js @@ -19,6 +19,11 @@ export const APP_NAME_VULNERABILITY = 'vulnerabilities'; export const APP_NAME_ADVISOR = 'advisor'; export const APP_NAME_PATCH = 'patch'; +export const INVENTORY_TOTAL_FETCH_URL_SERVER = '/api/inventory/v1/hosts'; +export const INVENTORY_TOTAL_FETCH_EDGE_PARAMS = + '?filter[system_profile][host_type]=edge&page=1&per_page=1'; +export const INVENTORY_TOTAL_FETCH_CONVENTIONAL_PARAMS = '?page=1&per_page=1'; + export function subtractDate(days) { const date = new Date(); date.setDate(date.getDate() - days); diff --git a/src/components/InventoryTabs/HybridInventoryTabs.js b/src/components/InventoryTabs/HybridInventoryTabs.js index f32a5ee9b..2b9ef76bb 100644 --- a/src/components/InventoryTabs/HybridInventoryTabs.js +++ b/src/components/InventoryTabs/HybridInventoryTabs.js @@ -1,9 +1,16 @@ -import React from 'react'; +import React, { useState } from 'react'; +import axios from 'axios'; import PropTypes from 'prop-types'; import { Tab, TabTitleText, Tabs } from '@patternfly/react-core'; import useFeatureFlag from '../../Utilities/useFeatureFlag'; import useInsightsNavigate from '@redhat-cloud-services/frontend-components-utilities/useInsightsNavigate/useInsightsNavigate'; -import { hybridInventoryTabKeys } from '../../Utilities/constants'; +import { + INVENTORY_TOTAL_FETCH_CONVENTIONAL_PARAMS, + INVENTORY_TOTAL_FETCH_EDGE_PARAMS, + INVENTORY_TOTAL_FETCH_URL_SERVER, + hybridInventoryTabKeys, +} from '../../Utilities/constants'; +import { manageEdgeInventoryUrlName } from '../../Utilities/edge'; const HybridInventoryTabs = ({ ConventionalSystemsTab, @@ -19,13 +26,45 @@ const HybridInventoryTabs = ({ navigate(hybridInventoryTabKeys[tabIndex].url); }; + const [hasEdgeImages, setHasEdgeImages] = useState(false); + const [isOstreeTabFocusPriority, setIsOstreeTabFocusPriority] = + useState(false); const EdgeParityEnabled = useFeatureFlag('edgeParity.inventory-list'); + if (EdgeParityEnabled) { + try { + axios + .get( + `${INVENTORY_TOTAL_FETCH_URL_SERVER}${INVENTORY_TOTAL_FETCH_EDGE_PARAMS}` + ) + .then((result) => { + const accountHasEdgeImages = result?.data?.total > 0; + setHasEdgeImages(accountHasEdgeImages); + axios + .get( + `${INVENTORY_TOTAL_FETCH_URL_SERVER}${INVENTORY_TOTAL_FETCH_CONVENTIONAL_PARAMS}` + ) + .then((conventionalImages) => { + const accountHasConventionalImages = + conventionalImages?.data?.total > 0; + if (accountHasEdgeImages && !accountHasConventionalImages) { + handleTabClick(undefined, manageEdgeInventoryUrlName); + setIsOstreeTabFocusPriority(true); + } + }); + }); + } catch (e) { + console.log(e); + } + } - return EdgeParityEnabled ? ( + return EdgeParityEnabled && hasEdgeImages ? (