Skip to content

Commit

Permalink
implement edge group expostion
Browse files Browse the repository at this point in the history
  • Loading branch information
mgold1234 committed Nov 12, 2023
1 parent 59584f0 commit f3168d8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ 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';
import useEdgeGroups from './Utilities/hooks/useEdgeGroups';
import EdgeGroupsView from './components/InventoryGroups/EdgeGroups';

const InventoryTable = lazy(() => import('./routes/InventoryTable'));
const InventoryDetail = lazy(() => import('./routes/InventoryDetail'));
Expand Down Expand Up @@ -53,6 +55,7 @@ export const Routes = () => {
const edgeParityInventoryListEnabled = useFeatureFlag(
'edgeParity.inventory-list'
);
const edgeGroupsUse = useEdgeGroups(false);
useEffect(() => {
try {
(async () => {
Expand All @@ -68,6 +71,8 @@ export const Routes = () => {
}
}, []);

const GroupsComponents = edgeGroupsUse ? EdgeGroupsView : InventoryGroups;

let element = useRoutes([
{
path: '/',
Expand All @@ -77,7 +82,7 @@ export const Routes = () => {
{ path: '/:inventoryId/:modalId', element: <InventoryDetail /> },
{
path: '/groups',
element: groupsEnabled ? <InventoryGroups /> : <LostPage />,
element: groupsEnabled ? <GroupsComponents /> : <LostPage />,
},
{
path: '/groups/:groupId',
Expand Down
24 changes: 24 additions & 0 deletions src/Utilities/hooks/useEdgeGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect, useState } from 'react';
import useFeatureFlag from '../useFeatureFlag';
import { fetchEdgeEnforceGroups } from '../../api';

const useEdgeGroups = (value) => {
const [data, setData] = useState(value);
const edgeParityInventoryGroupsEnabled = useFeatureFlag(
'edgeParity.inventory-groups-enabled'
);

useEffect(() => {
if (edgeParityInventoryGroupsEnabled) {
(async () => {
const response = await fetchEdgeEnforceGroups();
const enforceEdgeGroups = response?.enforce_edge_groups;
setData(enforceEdgeGroups);
})();
}
}, []);

return data;
};

export default useEdgeGroups;
8 changes: 8 additions & 0 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,11 @@ export const fetchEdgeSystem = () => {
console.log(err);
}
};

export const fetchEdgeEnforceGroups = () => {
try {
return instance.get(`${EDGE_API_BASE}/device-groups/enforce-edge-groups`);
} catch (err) {
console.log(err);
}
};
26 changes: 26 additions & 0 deletions src/components/InventoryGroups/EdgeGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 } from 'react-router-dom';
import { useDispatch } from 'react-redux';

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

export default EdgeGroupsView;

0 comments on commit f3168d8

Please sign in to comment.