Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inventroyGroup): THEEDGE-3693- implement edge group expostion #2086

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ 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 InventoryOrEdgeView = lazy(() =>
import('./routes/InventoryOrEdgeComponent')
);
const InventoryTable = lazy(() => import('./routes/InventoryTable'));
const InventoryDetail = lazy(() => import('./routes/InventoryDetail'));
const InventoryGroups = lazy(() => import('./routes/InventoryGroups'));
const InventoryHostStaleness = lazy(() =>
import('./routes/InventoryHostStaleness')
);
Expand Down Expand Up @@ -77,7 +78,7 @@ export const Routes = () => {
{ path: '/:inventoryId/:modalId', element: <InventoryDetail /> },
{
path: '/groups',
element: groupsEnabled ? <InventoryGroups /> : <LostPage />,
element: groupsEnabled ? <InventoryOrEdgeView /> : <LostPage />,
},
{
path: '/groups/:groupId',
Expand Down
34 changes: 34 additions & 0 deletions src/Utilities/hooks/useEdgeGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useEffect, useState } from 'react';
import useFeatureFlag from '../useFeatureFlag';
import { fetchEdgeEnforceGroups } from '../../api';

const useEdgeGroups = () => {
const [data, setData] = useState(false);
const [isLoading, setIsLoading] = useState(false);

const edgeParityInventoryGroupsEnabled = useFeatureFlag(
'edgeParity.inventory-groups-enabled'
);

useEffect(() => {
const fetchData = async () => {
setIsLoading(true);
try {
if (edgeParityInventoryGroupsEnabled) {
const response = await fetchEdgeEnforceGroups();
const enforceEdgeGroups = response?.enforce_edge_groups;
setData(enforceEdgeGroups);
}
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
};

fetchData();
}, []);
return [data, isLoading];
};

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.error(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;
56 changes: 56 additions & 0 deletions src/routes/InventoryOrEdgeComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useEffect, useState } from 'react';
import EdgeGroupsView from '../components/InventoryGroups/EdgeGroups';
import InventoryGroups from '../components/InventoryGroups/InventoryGroups';
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 { Bullseye, Spinner } from '@patternfly/react-core';

const InventoryOrEdgeView = () => {
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.error(e);
}
}, []);

const ViewComponent = enforceEdgeGroups ? EdgeGroupsView : InventoryGroups;
if (!isLoading) {
return (
<ViewComponent
hasConventionalSystems={hasConventionalSystems}
hasEdgeDevices={hasEdgeDevices}
Comment on lines +38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these props here? Neither EdgeGroupsView nor InventoryGroups component accepts these two props. I tried to trace EdgeGroupsView federated module interface and found this https://github.com/RedHatInsights/edge-frontend/blob/master/src/Routes/Groups/Groups.js#L21: it only accepts locationProp, navigateProp props.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesnt work without that

/>
);
} else {
return (
<Bullseye>
<Spinner />
</Bullseye>
);
}
};

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

export default InventoryOrEdgeView;