F #3951: Fix endpoints in dev mode (#363)

This commit is contained in:
Sergio Betanzos authored and GitHub committed 2020-10-26 11:28:46 +01:00
1 parent e39644629a
commit aa0f091da0
6 files changed
+26 -43

No files matched your search

+2 -4
View File
@@ -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 (
<MuiProvider app={appName} location={location}>
<ReduxProvider store={store}>
@@ -58,7 +56,7 @@ const App = ({ location, context, store, app }) => {
</StaticRouter>
) : (
// browser build
<BrowserRouter basename={basename}>
<BrowserRouter basename={`/${appName}`}>
<Router app={appName} />
</BrowserRouter>
)}
@@ -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: ''
}
@@ -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 ?? {}
}
+2 -2
View File
@@ -53,10 +53,10 @@ const Router = ({ app }) => {
)}
{...route}
/>
), [endpoints])
), [ENDPOINTS])
return (
<MainLayout endpoints={endpoints[app]}>
<MainLayout endpoints={{ ENDPOINTS, PATH }}>
<TransitionGroup>
<Switch>
{ENDPOINTS?.map(({ routes, ...endpoint }) =>
+1 -13
View File
@@ -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 ?? {}
}
+4 -4
View File
@@ -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
}),
{}