Skip to content

Commit

Permalink
feat:(THEEDGE-3527): Added Behavior related on Immutable tab and Conv…
Browse files Browse the repository at this point in the history
…entional

Signed-off-by: Adelia Ferreira <[email protected]>
  • Loading branch information
adeliaferreira authored Oct 4, 2023
1 parent dc06c16 commit 7e8f0a9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Utilities/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 42 additions & 3 deletions src/components/InventoryTabs/HybridInventoryTabs.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 ? (
<Tabs
className="pf-m-light pf-c-table"
activeKey={activeTab}
onSelect={handleTabClick}
defaultActiveKey={
isOstreeTabFocusPriority ? manageEdgeInventoryUrlName : 'conventional'
}
aria-label="Hybrid inventory tabs"
>
<Tab
Expand Down

0 comments on commit 7e8f0a9

Please sign in to comment.