diff --git a/src/AccessWrapper.js b/src/AccessWrapper.js new file mode 100644 index 00000000..3ad549f3 --- /dev/null +++ b/src/AccessWrapper.js @@ -0,0 +1,28 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Bullseye, Spinner } from '@patternfly/react-core'; +import { NotAuthorized } from '@redhat-cloud-services/frontend-components'; +import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook'; + +const AccessWrapper = ({ children }) => { + const { hasAccess, isLoading } = usePermissionsWithContext([ + 'patch:*:*', + 'patch:*:read' + ]); + + return isLoading ? ( + + + + ) : hasAccess ? ( + children + ) : ( + + ); +}; + +AccessWrapper.propTypes = { + children: PropTypes.any +}; + +export default AccessWrapper; diff --git a/src/App.js b/src/App.js index ed5489b3..2a7bafec 100644 --- a/src/App.js +++ b/src/App.js @@ -8,6 +8,7 @@ import { changeGlobalTags, changeProfile, globalFilter } from './store/Actions/A import { mapGlobalFilters } from './Utilities/Helpers'; import './App.scss'; import Routes from './Routes'; +import AccessWrapper from './AccessWrapper'; const App = () => { const dispatch = useDispatch(); @@ -46,7 +47,9 @@ const App = () => { - + + + ); diff --git a/src/Routes.js b/src/Routes.js index 0323df4c..942e4668 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -1,29 +1,10 @@ import { Bullseye, Spinner } from '@patternfly/react-core'; -import { NotAuthorized } from '@redhat-cloud-services/frontend-components/NotAuthorized'; -import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook'; import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent'; import axios from 'axios'; -import PropTypes from 'prop-types'; import React, { lazy, Suspense, useEffect, useState } from 'react'; -import { Navigate, Outlet, Route, Routes } from 'react-router-dom'; +import { Navigate, Route, Routes } from 'react-router-dom'; import { NavigateToSystem } from './Utilities/NavigateToSystem'; -const PermissionRoute = ({ requiredPermissions = [] }) => { - const { hasAccess, isLoading } = usePermissionsWithContext(requiredPermissions); - if (!isLoading) { - return hasAccess ? : ; - } else { - return ''; - } -}; - -PermissionRoute.propTypes = { - requiredPermissions: PropTypes.oneOfType([ - PropTypes.arrayOf(PropTypes.string), - PropTypes.string - ]) -}; - const Advisories = lazy(() => import( /* webpackChunkName: "Advisories" */ './SmartComponents/Advisories/Advisories' @@ -73,8 +54,8 @@ const TemplateDetail = lazy(() => ); const PatchRoutes = () => { - const generalPermissions = ['patch:*:*', 'patch:*:read']; - const [hasSystems, setHasSystems] = useState(true); + const [hasSystems, setHasSystems] = useState(null); + const INVENTORY_TOTAL_FETCH_URL = '/api/inventory/v1/hosts'; const RHEL_ONLY_FILTER = '?filter[system_profile][operating_system][RHEL][version][gte]=0'; @@ -90,7 +71,7 @@ const PatchRoutes = () => { } }, [hasSystems]); - return ( + return !hasSystems ? ( @@ -98,40 +79,47 @@ const PatchRoutes = () => { } > - - Error state} - app="Content_management" - customFetchResults={ hasSystems } - > - - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - - } /> - - + + ) : ( + + } /> + } + /> + } + /> + } /> + } + /> + } /> + } + /> + } + /> + } /> + } + /> + } /> + ); };