diff --git a/src/fireedge/src/client/app.js b/src/fireedge/src/client/app.js index 2060ce9246..c49385e123 100644 --- a/src/fireedge/src/client/app.js +++ b/src/fireedge/src/client/app.js @@ -13,7 +13,7 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -import React, { useMemo } from 'react' +import React from 'react' import PropTypes from 'prop-types' import { StaticRouter, BrowserRouter } from 'react-router-dom' @@ -44,8 +44,6 @@ const App = ({ location, context, store, app }) => { appName = window.location.pathname.split('/')[1] } - const basename = `/${appName}` - return ( @@ -58,7 +56,7 @@ const App = ({ location, context, store, app }) => { ) : ( // browser build - + )} diff --git a/src/fireedge/src/client/components/HOC/MainLayout.js b/src/fireedge/src/client/components/HOC/MainLayout.js index 838acaa579..7510e26789 100644 --- a/src/fireedge/src/client/components/HOC/MainLayout.js +++ b/src/fireedge/src/client/components/HOC/MainLayout.js @@ -15,15 +15,27 @@ import React, { useEffect } from 'react' import PropTypes from 'prop-types' -import { useLocation, Redirect } from 'react-router-dom' +import { useLocation, Redirect, matchPath } from 'react-router-dom' import useAuth from 'client/hooks/useAuth' import useOpennebula from 'client/hooks/useOpennebula' import LoadingScreen from 'client/components/LoadingScreen' +const findRouteByPathname = (endpoints, pathname) => { + const routes = endpoints.flatMap( + ({ endpoint, ...item }) => endpoint ?? item + ) + + const route = routes?.find(({ path }) => + matchPath(pathname, { path, exact: true }) + ) + + return route ?? {} +} + const MainLayout = ({ endpoints, children }) => { - const { PATH, findRouteByPathname } = endpoints + const { PATH, ENDPOINTS } = endpoints const { pathname } = useLocation() const { groups } = useOpennebula() const { @@ -40,7 +52,7 @@ const MainLayout = ({ endpoints, children }) => { } }, [isLogged, isLoginInProcess]) - const { authenticated } = findRouteByPathname(pathname) + const { authenticated } = findRouteByPathname(ENDPOINTS, pathname) const authRoute = Boolean(authenticated) // PENDING TO AUTHENTICATING OR FIRST RENDERING @@ -64,7 +76,7 @@ const MainLayout = ({ endpoints, children }) => { MainLayout.propTypes = { endpoints: PropTypes.shape({ PATH: PropTypes.object, - findRouteByPathname: PropTypes.func + ENDPOINTS: PropTypes.array }), children: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), @@ -76,7 +88,7 @@ MainLayout.propTypes = { MainLayout.defaultProps = { endpoints: { PATH: {}, - findRouteByPathname: () => {} + ENDPOINTS: [] }, children: '' } diff --git a/src/fireedge/src/client/router/fireedge.js b/src/fireedge/src/client/router/fireedge.js index 768a05e384..2e14b25728 100644 --- a/src/fireedge/src/client/router/fireedge.js +++ b/src/fireedge/src/client/router/fireedge.js @@ -1,6 +1,5 @@ import { Dashboard as DashboardIcon, - Ballot as BallotIcon, FormatListBulleted as TemplatesIcons, Apps as InstancesIcons } from '@material-ui/icons' @@ -9,8 +8,6 @@ import { matchPath } from 'react-router-dom' import Login from 'client/containers/Login' import Dashboard from 'client/containers/Dashboard' import Settings from 'client/containers/Settings' -import TestApi from 'client/containers/TestApi' -import Webconsole from 'client/containers/Webconsole' import ApplicationsTemplates from 'client/containers/ApplicationsTemplates' import ApplicationsTemplatesCreateForm from 'client/containers/ApplicationsTemplates/Form/Create' @@ -82,15 +79,3 @@ export const ENDPOINTS = [ component: ApplicationsInstances } ] - -export const findRouteByPathname = pathname => { - const routes = ENDPOINTS.flatMap( - ({ endpoints, ...item }) => endpoints ?? item - ) - - const route = routes?.find(({ path }) => - matchPath(pathname, { path, exact: true }) - ) - - return route ?? {} -} diff --git a/src/fireedge/src/client/router/index.js b/src/fireedge/src/client/router/index.js index 15436a7ccd..4e4c594451 100644 --- a/src/fireedge/src/client/router/index.js +++ b/src/fireedge/src/client/router/index.js @@ -53,10 +53,10 @@ const Router = ({ app }) => { )} {...route} /> - ), [endpoints]) + ), [ENDPOINTS]) return ( - + {ENDPOINTS?.map(({ routes, ...endpoint }) => diff --git a/src/fireedge/src/client/router/provision.js b/src/fireedge/src/client/router/provision.js index 3971f864b0..e03c3a5288 100644 --- a/src/fireedge/src/client/router/provision.js +++ b/src/fireedge/src/client/router/provision.js @@ -13,7 +13,7 @@ import Providers from 'client/containers/Providers' import Provisions from 'client/containers/Provisions' export const PATH = { - LOGIN: '/provision', + LOGIN: '/', DASHBOARD: '/dashboard', PROVIDERS: { LIST: '/providers', @@ -68,15 +68,3 @@ export const ENDPOINTS = [ component: Provisions } ] - -export const findRouteByPathname = pathname => { - const routes = ENDPOINTS.flatMap( - ({ endpoints, ...item }) => endpoints ?? item - ) - - const route = routes?.find(({ path }) => - matchPath(pathname, { path, exact: true }) - ) - - return route ?? {} -} diff --git a/src/fireedge/src/client/utils/helpers.js b/src/fireedge/src/client/utils/helpers.js index 9e4a58f274..fbd2521dad 100644 --- a/src/fireedge/src/client/utils/helpers.js +++ b/src/fireedge/src/client/utils/helpers.js @@ -1,9 +1,9 @@ export const fakeDelay = ms => new Promise(resolve => setTimeout(resolve, ms)) -export const getValidationFromFields = schema => - schema.reduce( - (validation, field) => ({ - ...validation, +export const getValidationFromFields = fields => + fields.reduce( + (schema, field) => ({ + ...schema, [field?.name]: field?.validation }), {}