Skip to content

Commit

Permalink
fix(InventoryGroupDetails): THEEDGE-3707 implement edge group details…
Browse files Browse the repository at this point in the history
… expostion
  • Loading branch information
mgold1234 committed Nov 22, 2023
1 parent 0e93b5c commit a354c2c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import AsynComponent from '@redhat-cloud-services/frontend-components/AsyncCompo
import ErrorState from '@redhat-cloud-services/frontend-components/ErrorState';
import { inventoryHasEdgeSystems } from './Utilities/edge';
import { inventoryHasConventionalSystems } from './Utilities/conventional';
const InventoryOrEdgeGroupDetailsView = lazy(() =>
import('./routes/InventoryOrEdgeGroupDetailsComponent')
);
const InventoryOrEdgeView = lazy(() =>
import('./routes/InventoryOrEdgeComponent')
);
Expand All @@ -25,9 +28,6 @@ const InventoryHostStaleness = lazy(() =>
import('./routes/InventoryHostStaleness')
);

const InventoryGroupDetail = lazy(() =>
import('./routes/InventoryGroupDetail')
);
const EdgeInventoryUpdate = lazy(() => import('./routes/SystemUpdate'));

export const routes = {
Expand Down Expand Up @@ -82,7 +82,11 @@ export const Routes = () => {
},
{
path: '/groups/:groupId',
element: groupsEnabled ? <InventoryGroupDetail /> : <LostPage />,
element: groupsEnabled ? (
<InventoryOrEdgeGroupDetailsView />
) : (
<LostPage />
),
},
{
path: '/:inventoryId/update',
Expand Down
27 changes: 27 additions & 0 deletions src/components/InventoryGroupDetail/EdgeGroupDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent';
import ErrorState from '@redhat-cloud-services/frontend-components/ErrorState';
import { resolveRelPath } from '../../Utilities/path';
import { getNotificationProp } from '../../Utilities/edge';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { useDispatch } from 'react-redux';

const EdgeGroupsDetailsView = (props) => {
const dispatch = useDispatch();
const notificationProp = getNotificationProp(dispatch);
return (
<AsyncComponent
appName="edge"
module="./GroupsDetails"
ErrorComponent={<ErrorState />}
navigateProp={useNavigate}
locationProp={useLocation}
paramsProp={useParams}
notificationProp={notificationProp}
pathPrefix={resolveRelPath('')}
{...props}
/>
);
};

export default EdgeGroupsDetailsView;
3 changes: 2 additions & 1 deletion src/components/InventoryGroups/EdgeGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComp
import ErrorState from '@redhat-cloud-services/frontend-components/ErrorState';
import { resolveRelPath } from '../../Utilities/path';
import { getNotificationProp } from '../../Utilities/edge';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { useDispatch } from 'react-redux';

const EdgeGroupsView = (props) => {
Expand All @@ -16,6 +16,7 @@ const EdgeGroupsView = (props) => {
ErrorComponent={<ErrorState />}
navigateProp={useNavigate}
locationProp={useLocation}
useParams={useParams}
notificationProp={notificationProp}
pathPrefix={resolveRelPath('')}
{...props}
Expand Down
54 changes: 54 additions & 0 deletions src/routes/InventoryOrEdgeGroupDetailsComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useEffect, useState } from 'react';
import { inventoryHasConventionalSystems } from '../Utilities/conventional';
import { inventoryHasEdgeSystems } from '../Utilities/edge';
import useEdgeGroups from '../Utilities/hooks/useEdgeGroups';
import useFeatureFlag from '../Utilities/useFeatureFlag';
import PropTypes from 'prop-types';
import { Spinner } from '@patternfly/react-core';
import EdgeGroupsDetailsView from '../components/InventoryGroupDetail/EdgeGroupDetails';
import InventoryGroupDetail from './InventoryGroupDetail';

const InventoryOrEdgeGroupDetailsView = () => {
const [enforceEdgeGroups, isLoading] = useEdgeGroups();
const [hasConventionalSystems, setHasConventionalSystems] = useState(true);
const [hasEdgeDevices, setHasEdgeDevices] = useState(true);
const edgeParityInventoryListEnabled = useFeatureFlag(
'edgeParity.inventory-list'
);

useEffect(() => {
try {
(async () => {
const hasConventionalSystems = await inventoryHasConventionalSystems();
if (edgeParityInventoryListEnabled) {
const hasEdgeSystems = await inventoryHasEdgeSystems();
setHasConventionalSystems(hasConventionalSystems);
setHasEdgeDevices(hasEdgeSystems);
}
})();
} catch (e) {
console.log(e);
}
}, []);

const GroupsDetailComponents = enforceEdgeGroups
? EdgeGroupsDetailsView
: InventoryGroupDetail;
if (!isLoading) {
return (
<GroupsDetailComponents
hasConventionalSystems={hasConventionalSystems}
hasEdgeDevices={hasEdgeDevices}
/>
);
} else {
return <Spinner />;
}
};

InventoryOrEdgeGroupDetailsView.prototype = {
enforceEdgeGroups: PropTypes.bool,
isLoading: PropTypes.bool,
};

export default InventoryOrEdgeGroupDetailsView;

0 comments on commit a354c2c

Please sign in to comment.