mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-02 05:06:14 +09:00
F OpenNebula/one#5422: Refactor router logic
This commit is contained in:
11 files changed
+398
-344
No files matched your search
@@ -16,14 +16,18 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import Router from 'client/router'
|
||||
import routes from 'client/apps/provision/routes'
|
||||
import { ENDPOINTS, PATH } from 'client/apps/provision/routes'
|
||||
import { ENDPOINTS as DEV_ENDPOINTS } from 'client/router/dev'
|
||||
|
||||
import { useGeneralApi } from 'client/features/General'
|
||||
import { useAuth, useAuthApi } from 'client/features/Auth'
|
||||
import { useProvisionTemplate, useProvisionApi } from 'client/features/One'
|
||||
|
||||
import Sidebar from 'client/components/Sidebar'
|
||||
import Notifier from 'client/components/Notifier'
|
||||
import LoadingScreen from 'client/components/LoadingScreen'
|
||||
import { _APPS } from 'client/constants'
|
||||
import { isDevelopment } from 'client/utils'
|
||||
|
||||
const APP_NAME = _APPS.provision.name
|
||||
|
||||
@@ -49,11 +53,26 @@ const ProvisionApp = () => {
|
||||
})()
|
||||
}, [jwt])
|
||||
|
||||
const endpoints = React.useMemo(() => [
|
||||
...ENDPOINTS,
|
||||
...(isDevelopment() ? DEV_ENDPOINTS : [])
|
||||
], [])
|
||||
|
||||
if (jwt && firstRender) {
|
||||
return <LoadingScreen />
|
||||
}
|
||||
|
||||
return <Router isLogged={isLogged} routes={routes} />
|
||||
return (
|
||||
<>
|
||||
{isLogged && (
|
||||
<>
|
||||
<Sidebar endpoints={endpoints} />
|
||||
<Notifier />
|
||||
</>
|
||||
)}
|
||||
<Router redirectWhenAuth={PATH.DASHBOARD} endpoints={endpoints} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
ProvisionApp.displayName = '_ProvisionApp'
|
||||
|
||||
@@ -16,18 +16,23 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import Router from 'client/router'
|
||||
import routes from 'client/apps/sunstone/routes'
|
||||
import { ENDPOINTS, PATH, getEndpointsByView } from 'client/apps/sunstone/routes'
|
||||
import { ENDPOINTS as ONE_ENDPOINTS } from 'client/apps/sunstone/routesOne'
|
||||
import { ENDPOINTS as DEV_ENDPOINTS } from 'client/router/dev'
|
||||
|
||||
import { useGeneralApi } from 'client/features/General'
|
||||
import { useAuth, useAuthApi } from 'client/features/Auth'
|
||||
|
||||
import Sidebar from 'client/components/Sidebar'
|
||||
import Notifier from 'client/components/Notifier'
|
||||
import LoadingScreen from 'client/components/LoadingScreen'
|
||||
import { _APPS } from 'client/constants'
|
||||
import { isDevelopment } from 'client/utils'
|
||||
|
||||
const APP_NAME = _APPS.sunstone.name
|
||||
|
||||
const SunstoneApp = () => {
|
||||
const { isLogged, jwt, firstRender } = useAuth()
|
||||
const { isLogged, jwt, firstRender, view, views } = useAuth()
|
||||
const { getAuthUser, logout, getSunstoneViews } = useAuthApi()
|
||||
const { changeTitle } = useGeneralApi()
|
||||
|
||||
@@ -37,7 +42,7 @@ const SunstoneApp = () => {
|
||||
if (jwt) {
|
||||
changeTitle(APP_NAME)
|
||||
getAuthUser()
|
||||
getSunstoneViews()
|
||||
await getSunstoneViews()
|
||||
}
|
||||
} catch {
|
||||
logout()
|
||||
@@ -45,11 +50,27 @@ const SunstoneApp = () => {
|
||||
})()
|
||||
}, [jwt])
|
||||
|
||||
const endpoints = React.useMemo(() => [
|
||||
...ENDPOINTS,
|
||||
...(view ? getEndpointsByView(views?.[view], ONE_ENDPOINTS) : []),
|
||||
...(isDevelopment() ? DEV_ENDPOINTS : [])
|
||||
], [view])
|
||||
|
||||
if (jwt && firstRender) {
|
||||
return <LoadingScreen />
|
||||
}
|
||||
|
||||
return <Router isLogged={isLogged} routes={routes} />
|
||||
return (
|
||||
<>
|
||||
{isLogged && (
|
||||
<>
|
||||
<Sidebar endpoints={endpoints} />
|
||||
<Notifier />
|
||||
</>
|
||||
)}
|
||||
<Router redirectWhenAuth={PATH.DASHBOARD} endpoints={endpoints} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
SunstoneApp.displayName = '_SunstoneApp'
|
||||
|
||||
@@ -1,33 +1,6 @@
|
||||
import {
|
||||
ReportColumns as DashboardIcon,
|
||||
Settings as SettingsIcon,
|
||||
|
||||
Cell4x4 as InstancesIcons,
|
||||
ModernTv as VmsIcons,
|
||||
Shuffle as VRoutersIcons,
|
||||
|
||||
Archive as TemplatesIcon,
|
||||
GoogleDocs as TemplateIcon,
|
||||
|
||||
Box as StorageIcon,
|
||||
Db as DatastoreIcon,
|
||||
BoxIso as ImageIcon,
|
||||
SimpleCart as MarketplaceIcon,
|
||||
CloudDownload as MarketplaceAppIcon,
|
||||
|
||||
ServerConnection as NetworksIcon,
|
||||
NetworkAlt as NetworkIcon,
|
||||
KeyframesCouple as NetworkTemplateIcon,
|
||||
|
||||
CloudSync as InfrastructureIcon,
|
||||
Server as ClusterIcon,
|
||||
HardDrive as HostIcon,
|
||||
MinusPinAlt as ZoneIcon,
|
||||
|
||||
Home as SystemIcon,
|
||||
User as UserIcon,
|
||||
Group as GroupIcon
|
||||
|
||||
Settings as SettingsIcon
|
||||
} from 'iconoir-react'
|
||||
|
||||
import loadable from '@loadable/component'
|
||||
@@ -35,95 +8,8 @@ import loadable from '@loadable/component'
|
||||
const Dashboard = loadable(() => import('client/containers/Dashboard/Sunstone'), { ssr: false })
|
||||
const Settings = loadable(() => import('client/containers/Settings'), { ssr: false })
|
||||
|
||||
const VirtualMachines = loadable(() => import('client/containers/VirtualMachines'), { ssr: false })
|
||||
const VirtualRouters = loadable(() => import('client/containers/VirtualRouters'), { ssr: false })
|
||||
|
||||
const VmTemplates = loadable(() => import('client/containers/VmTemplates'), { ssr: false })
|
||||
// const VrTemplates = loadable(() => import('client/containers/VrTemplates'), { ssr: false })
|
||||
// const VmGroups = loadable(() => import('client/containers/VmGroups'), { ssr: false })
|
||||
|
||||
const Datastores = loadable(() => import('client/containers/Datastores'), { ssr: false })
|
||||
const Images = loadable(() => import('client/containers/Images'), { ssr: false })
|
||||
// const Files = loadable(() => import('client/containers/Files'), { ssr: false })
|
||||
const Marketplaces = loadable(() => import('client/containers/Marketplaces'), { ssr: false })
|
||||
const MarketplaceApps = loadable(() => import('client/containers/MarketplaceApps'), { ssr: false })
|
||||
|
||||
const VirtualNetworks = loadable(() => import('client/containers/VirtualNetworks'), { ssr: false })
|
||||
const VNetworkTemplates = loadable(() => import('client/containers/VNetworkTemplates'), { ssr: false })
|
||||
// const NetworkTopologies = loadable(() => import('client/containers/NetworkTopologies'), { ssr: false })
|
||||
// const SecurityGroups = loadable(() => import('client/containers/SecurityGroups'), { ssr: false })
|
||||
|
||||
const Clusters = loadable(() => import('client/containers/Clusters'), { ssr: false })
|
||||
const Hosts = loadable(() => import('client/containers/Hosts'), { ssr: false })
|
||||
const Zones = loadable(() => import('client/containers/Zones'), { ssr: false })
|
||||
|
||||
const Users = loadable(() => import('client/containers/Users'), { ssr: false })
|
||||
const Groups = loadable(() => import('client/containers/Groups'), { ssr: false })
|
||||
// const VDCs = loadable(() => import('client/containers/VDCs'), { ssr: false })
|
||||
// const ACLs = loadable(() => import('client/containers/ACLs'), { ssr: false })
|
||||
|
||||
export const PATH = {
|
||||
DASHBOARD: '/dashboard',
|
||||
INSTANCE: {
|
||||
VMS: {
|
||||
LIST: '/vms'
|
||||
},
|
||||
VROUTERS: {
|
||||
LIST: '/virtual-routers'
|
||||
}
|
||||
},
|
||||
TEMPLATE: {
|
||||
VMS: {
|
||||
LIST: '/vm-templates'
|
||||
}
|
||||
},
|
||||
STORAGE: {
|
||||
DATASTORES: {
|
||||
LIST: '/datastores'
|
||||
},
|
||||
IMAGES: {
|
||||
LIST: '/images'
|
||||
},
|
||||
FILES: {
|
||||
LIST: '/files'
|
||||
},
|
||||
MARKETPLACES: {
|
||||
LIST: '/marketplaces'
|
||||
},
|
||||
MARKETPLACE_APPS: {
|
||||
LIST: '/marketplaces-apps'
|
||||
}
|
||||
},
|
||||
NETWORK: {
|
||||
VNETS: {
|
||||
LIST: '/virtual-networks'
|
||||
},
|
||||
VN_TEMPLATES: {
|
||||
LIST: '/network-templates'
|
||||
},
|
||||
SEC_GROUPS: {
|
||||
LIST: '/security-groups'
|
||||
}
|
||||
},
|
||||
INFRASTRUCTURE: {
|
||||
CLUSTERS: {
|
||||
LIST: '/clusters'
|
||||
},
|
||||
HOSTS: {
|
||||
LIST: '/hosts'
|
||||
},
|
||||
ZONES: {
|
||||
LIST: '/zones'
|
||||
}
|
||||
},
|
||||
SYSTEM: {
|
||||
USERS: {
|
||||
LIST: '/users'
|
||||
},
|
||||
GROUPS: {
|
||||
LIST: '/groups'
|
||||
}
|
||||
},
|
||||
SETTINGS: '/settings'
|
||||
}
|
||||
|
||||
@@ -135,146 +21,6 @@ export const ENDPOINTS = [
|
||||
icon: DashboardIcon,
|
||||
Component: Dashboard
|
||||
},
|
||||
{
|
||||
label: 'Instances',
|
||||
sidebar: true,
|
||||
icon: InstancesIcons,
|
||||
routes: [
|
||||
{
|
||||
label: 'VMs',
|
||||
path: PATH.INSTANCE.VMS.LIST,
|
||||
sidebar: true,
|
||||
icon: VmsIcons,
|
||||
Component: VirtualMachines
|
||||
},
|
||||
{
|
||||
label: 'Virtual Routers',
|
||||
path: PATH.INSTANCE.VROUTERS.LIST,
|
||||
sidebar: true,
|
||||
icon: VRoutersIcons,
|
||||
Component: VirtualRouters
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Templates',
|
||||
sidebar: true,
|
||||
icon: TemplatesIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'VMs',
|
||||
path: PATH.TEMPLATE.VMS.LIST,
|
||||
sidebar: true,
|
||||
icon: TemplateIcon,
|
||||
Component: VmTemplates
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Storage',
|
||||
sidebar: true,
|
||||
icon: StorageIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Datastores',
|
||||
path: PATH.STORAGE.DATASTORES.LIST,
|
||||
sidebar: true,
|
||||
icon: DatastoreIcon,
|
||||
Component: Datastores
|
||||
},
|
||||
{
|
||||
label: 'Images',
|
||||
path: PATH.STORAGE.IMAGES.LIST,
|
||||
sidebar: true,
|
||||
icon: ImageIcon,
|
||||
Component: Images
|
||||
},
|
||||
{
|
||||
label: 'Marketplaces',
|
||||
path: PATH.STORAGE.MARKETPLACES.LIST,
|
||||
sidebar: true,
|
||||
icon: MarketplaceIcon,
|
||||
Component: Marketplaces
|
||||
},
|
||||
{
|
||||
label: 'Apps',
|
||||
path: PATH.STORAGE.MARKETPLACE_APPS.LIST,
|
||||
sidebar: true,
|
||||
icon: MarketplaceAppIcon,
|
||||
Component: MarketplaceApps
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Networks',
|
||||
sidebar: true,
|
||||
icon: NetworksIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Virtual Networks',
|
||||
path: PATH.NETWORK.VNETS.LIST,
|
||||
sidebar: true,
|
||||
icon: NetworkIcon,
|
||||
Component: VirtualNetworks
|
||||
},
|
||||
{
|
||||
label: 'Network Templates',
|
||||
path: PATH.NETWORK.VN_TEMPLATES.LIST,
|
||||
sidebar: true,
|
||||
icon: NetworkTemplateIcon,
|
||||
Component: VNetworkTemplates
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Infrastructure',
|
||||
sidebar: true,
|
||||
icon: InfrastructureIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Clusters',
|
||||
path: PATH.INFRASTRUCTURE.CLUSTERS.LIST,
|
||||
sidebar: true,
|
||||
icon: ClusterIcon,
|
||||
Component: Clusters
|
||||
},
|
||||
{
|
||||
label: 'Hosts',
|
||||
path: PATH.INFRASTRUCTURE.HOSTS.LIST,
|
||||
sidebar: true,
|
||||
icon: HostIcon,
|
||||
Component: Hosts
|
||||
},
|
||||
{
|
||||
label: 'Zones',
|
||||
path: PATH.INFRASTRUCTURE.ZONES.LIST,
|
||||
sidebar: true,
|
||||
icon: ZoneIcon,
|
||||
Component: Zones
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'System',
|
||||
sidebar: true,
|
||||
icon: SystemIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Users',
|
||||
path: PATH.SYSTEM.USERS.LIST,
|
||||
sidebar: true,
|
||||
icon: UserIcon,
|
||||
Component: Users
|
||||
},
|
||||
{
|
||||
label: 'Groups',
|
||||
path: PATH.SYSTEM.GROUPS.LIST,
|
||||
sidebar: true,
|
||||
icon: GroupIcon,
|
||||
Component: Groups
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Settings',
|
||||
path: PATH.SETTINGS,
|
||||
@@ -284,4 +30,26 @@ export const ENDPOINTS = [
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* @param {String} view Current view selected in redux (auth-reducer)
|
||||
* @param {Array} endpoints All endpoints of app
|
||||
* @returns {Array} Returns all endpoints available
|
||||
*/
|
||||
export const getEndpointsByView = (view, endpoints = []) => {
|
||||
const hasRoutePermission = route =>
|
||||
view?.some(({ resource_name: name }) =>
|
||||
route?.path.toLowerCase().endsWith(name.toLowerCase())
|
||||
) && route
|
||||
|
||||
return endpoints.map(({ routes: subRoutes, ...rest }) => {
|
||||
if (Array.isArray(subRoutes)) {
|
||||
const routes = subRoutes.map(hasRoutePermission).filter(Boolean)
|
||||
|
||||
return !!routes.length && { ...rest, routes }
|
||||
}
|
||||
|
||||
return hasRoutePermission(rest)
|
||||
}).filter(Boolean)
|
||||
}
|
||||
|
||||
export default { PATH, ENDPOINTS }
|
||||
File renamed without changes.
@@ -0,0 +1,265 @@
|
||||
import {
|
||||
Cell4x4 as InstancesIcons,
|
||||
ModernTv as VmsIcons,
|
||||
Shuffle as VRoutersIcons,
|
||||
|
||||
Archive as TemplatesIcon,
|
||||
GoogleDocs as TemplateIcon,
|
||||
|
||||
Box as StorageIcon,
|
||||
Db as DatastoreIcon,
|
||||
BoxIso as ImageIcon,
|
||||
SimpleCart as MarketplaceIcon,
|
||||
CloudDownload as MarketplaceAppIcon,
|
||||
|
||||
ServerConnection as NetworksIcon,
|
||||
NetworkAlt as NetworkIcon,
|
||||
KeyframesCouple as NetworkTemplateIcon,
|
||||
|
||||
CloudSync as InfrastructureIcon,
|
||||
Server as ClusterIcon,
|
||||
HardDrive as HostIcon,
|
||||
MinusPinAlt as ZoneIcon,
|
||||
|
||||
Home as SystemIcon,
|
||||
User as UserIcon,
|
||||
Group as GroupIcon
|
||||
|
||||
} from 'iconoir-react'
|
||||
|
||||
import loadable from '@loadable/component'
|
||||
|
||||
const VirtualMachines = loadable(() => import('client/containers/VirtualMachines'), { ssr: false })
|
||||
const VirtualRouters = loadable(() => import('client/containers/VirtualRouters'), { ssr: false })
|
||||
|
||||
const VmTemplates = loadable(() => import('client/containers/VmTemplates'), { ssr: false })
|
||||
// const VrTemplates = loadable(() => import('client/containers/VrTemplates'), { ssr: false })
|
||||
// const VmGroups = loadable(() => import('client/containers/VmGroups'), { ssr: false })
|
||||
|
||||
const Datastores = loadable(() => import('client/containers/Datastores'), { ssr: false })
|
||||
const Images = loadable(() => import('client/containers/Images'), { ssr: false })
|
||||
// const Files = loadable(() => import('client/containers/Files'), { ssr: false })
|
||||
const Marketplaces = loadable(() => import('client/containers/Marketplaces'), { ssr: false })
|
||||
const MarketplaceApps = loadable(() => import('client/containers/MarketplaceApps'), { ssr: false })
|
||||
|
||||
const VirtualNetworks = loadable(() => import('client/containers/VirtualNetworks'), { ssr: false })
|
||||
const VNetworkTemplates = loadable(() => import('client/containers/VNetworkTemplates'), { ssr: false })
|
||||
// const NetworkTopologies = loadable(() => import('client/containers/NetworkTopologies'), { ssr: false })
|
||||
// const SecurityGroups = loadable(() => import('client/containers/SecurityGroups'), { ssr: false })
|
||||
|
||||
const Clusters = loadable(() => import('client/containers/Clusters'), { ssr: false })
|
||||
const Hosts = loadable(() => import('client/containers/Hosts'), { ssr: false })
|
||||
const Zones = loadable(() => import('client/containers/Zones'), { ssr: false })
|
||||
|
||||
const Users = loadable(() => import('client/containers/Users'), { ssr: false })
|
||||
const Groups = loadable(() => import('client/containers/Groups'), { ssr: false })
|
||||
// const VDCs = loadable(() => import('client/containers/VDCs'), { ssr: false })
|
||||
// const ACLs = loadable(() => import('client/containers/ACLs'), { ssr: false })
|
||||
|
||||
export const PATH = {
|
||||
INSTANCE: {
|
||||
VMS: {
|
||||
LIST: '/vm'
|
||||
},
|
||||
VROUTERS: {
|
||||
LIST: '/virtual-router'
|
||||
}
|
||||
},
|
||||
TEMPLATE: {
|
||||
VMS: {
|
||||
LIST: '/vm-template'
|
||||
}
|
||||
},
|
||||
STORAGE: {
|
||||
DATASTORES: {
|
||||
LIST: '/datastore'
|
||||
},
|
||||
IMAGES: {
|
||||
LIST: '/image'
|
||||
},
|
||||
FILES: {
|
||||
LIST: '/file'
|
||||
},
|
||||
MARKETPLACES: {
|
||||
LIST: '/marketplace'
|
||||
},
|
||||
MARKETPLACE_APPS: {
|
||||
LIST: '/marketplaces-app'
|
||||
}
|
||||
},
|
||||
NETWORK: {
|
||||
VNETS: {
|
||||
LIST: '/virtual-network'
|
||||
},
|
||||
VN_TEMPLATES: {
|
||||
LIST: '/network-template'
|
||||
},
|
||||
SEC_GROUPS: {
|
||||
LIST: '/security-group'
|
||||
}
|
||||
},
|
||||
INFRASTRUCTURE: {
|
||||
CLUSTERS: {
|
||||
LIST: '/cluster'
|
||||
},
|
||||
HOSTS: {
|
||||
LIST: '/host'
|
||||
},
|
||||
ZONES: {
|
||||
LIST: '/zone'
|
||||
}
|
||||
},
|
||||
SYSTEM: {
|
||||
USERS: {
|
||||
LIST: '/user'
|
||||
},
|
||||
GROUPS: {
|
||||
LIST: '/group'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const ENDPOINTS = [
|
||||
{
|
||||
label: 'Instances',
|
||||
sidebar: true,
|
||||
icon: InstancesIcons,
|
||||
routes: [
|
||||
{
|
||||
label: 'VMs',
|
||||
path: PATH.INSTANCE.VMS.LIST,
|
||||
sidebar: true,
|
||||
icon: VmsIcons,
|
||||
Component: VirtualMachines
|
||||
},
|
||||
{
|
||||
label: 'Virtual Routers',
|
||||
path: PATH.INSTANCE.VROUTERS.LIST,
|
||||
sidebar: true,
|
||||
icon: VRoutersIcons,
|
||||
Component: VirtualRouters
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Templates',
|
||||
sidebar: true,
|
||||
icon: TemplatesIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'VMs',
|
||||
path: PATH.TEMPLATE.VMS.LIST,
|
||||
sidebar: true,
|
||||
icon: TemplateIcon,
|
||||
Component: VmTemplates
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Storage',
|
||||
sidebar: true,
|
||||
icon: StorageIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Datastores',
|
||||
path: PATH.STORAGE.DATASTORES.LIST,
|
||||
sidebar: true,
|
||||
icon: DatastoreIcon,
|
||||
Component: Datastores
|
||||
},
|
||||
{
|
||||
label: 'Images',
|
||||
path: PATH.STORAGE.IMAGES.LIST,
|
||||
sidebar: true,
|
||||
icon: ImageIcon,
|
||||
Component: Images
|
||||
},
|
||||
{
|
||||
label: 'Marketplaces',
|
||||
path: PATH.STORAGE.MARKETPLACES.LIST,
|
||||
sidebar: true,
|
||||
icon: MarketplaceIcon,
|
||||
Component: Marketplaces
|
||||
},
|
||||
{
|
||||
label: 'Apps',
|
||||
path: PATH.STORAGE.MARKETPLACE_APPS.LIST,
|
||||
sidebar: true,
|
||||
icon: MarketplaceAppIcon,
|
||||
Component: MarketplaceApps
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Networks',
|
||||
sidebar: true,
|
||||
icon: NetworksIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Virtual Networks',
|
||||
path: PATH.NETWORK.VNETS.LIST,
|
||||
sidebar: true,
|
||||
icon: NetworkIcon,
|
||||
Component: VirtualNetworks
|
||||
},
|
||||
{
|
||||
label: 'Network Templates',
|
||||
path: PATH.NETWORK.VN_TEMPLATES.LIST,
|
||||
sidebar: true,
|
||||
icon: NetworkTemplateIcon,
|
||||
Component: VNetworkTemplates
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Infrastructure',
|
||||
sidebar: true,
|
||||
icon: InfrastructureIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Clusters',
|
||||
path: PATH.INFRASTRUCTURE.CLUSTERS.LIST,
|
||||
sidebar: true,
|
||||
icon: ClusterIcon,
|
||||
Component: Clusters
|
||||
},
|
||||
{
|
||||
label: 'Hosts',
|
||||
path: PATH.INFRASTRUCTURE.HOSTS.LIST,
|
||||
sidebar: true,
|
||||
icon: HostIcon,
|
||||
Component: Hosts
|
||||
},
|
||||
{
|
||||
label: 'Zones',
|
||||
path: PATH.INFRASTRUCTURE.ZONES.LIST,
|
||||
sidebar: true,
|
||||
icon: ZoneIcon,
|
||||
Component: Zones
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'System',
|
||||
sidebar: true,
|
||||
icon: SystemIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Users',
|
||||
path: PATH.SYSTEM.USERS.LIST,
|
||||
sidebar: true,
|
||||
icon: UserIcon,
|
||||
Component: Users
|
||||
},
|
||||
{
|
||||
label: 'Groups',
|
||||
path: PATH.SYSTEM.GROUPS.LIST,
|
||||
sidebar: true,
|
||||
icon: GroupIcon,
|
||||
Component: Groups
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
export default { PATH, ENDPOINTS }
|
||||
@@ -11,7 +11,7 @@ import headerStyles from 'client/components/Header/styles'
|
||||
|
||||
const View = () => {
|
||||
const classes = headerStyles()
|
||||
const { view, views } = useAuth()
|
||||
const { view, views = {} } = useAuth()
|
||||
const { changeView } = useAuthApi()
|
||||
|
||||
const handleChangeView = newView => {
|
||||
|
||||
@@ -14,15 +14,20 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { Redirect, Route } from 'react-router-dom'
|
||||
import { useAuth } from 'client/features/Auth'
|
||||
|
||||
const NoAuthRoute = props => {
|
||||
const NoAuthRoute = ({ redirectWhenAuth, ...props }) => {
|
||||
const { isLogged, isLoginInProgress, isLoading } = useAuth()
|
||||
const isAuthenticated = isLogged && !isLoginInProgress && !isLoading
|
||||
|
||||
return isAuthenticated ? <Redirect to='/dashboard' /> : <Route exact {...props}/>
|
||||
return isAuthenticated ? <Redirect to={redirectWhenAuth} /> : <Route exact {...props}/>
|
||||
}
|
||||
|
||||
NoAuthRoute.propTypes = {
|
||||
redirectWhenAuth: PropTypes.string
|
||||
}
|
||||
|
||||
export default NoAuthRoute
|
||||
@@ -13,7 +13,7 @@
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useMemo, memo } from 'react'
|
||||
import React, { useMemo } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import clsx from 'clsx'
|
||||
@@ -33,7 +33,7 @@ import SidebarLink from 'client/components/Sidebar/SidebarLink'
|
||||
import SidebarCollapseItem from 'client/components/Sidebar/SidebarCollapseItem'
|
||||
import Logo from 'client/icons/logo'
|
||||
|
||||
const Sidebar = memo(({ endpoints }) => {
|
||||
const Sidebar = ({ endpoints }) => {
|
||||
const classes = sidebarStyles()
|
||||
const isUpLg = useMediaQuery(theme => theme.breakpoints.up('lg'), { noSsr: true })
|
||||
|
||||
@@ -43,17 +43,16 @@ const Sidebar = memo(({ endpoints }) => {
|
||||
const handleSwapMenu = () => fixMenu(!isFixMenu)
|
||||
|
||||
const SidebarEndpoints = useMemo(
|
||||
() =>
|
||||
endpoints
|
||||
?.filter(({ sidebar = false }) => sidebar)
|
||||
?.map((endpoint, index) =>
|
||||
endpoint.routes ? (
|
||||
<SidebarCollapseItem key={`item-${index}`} {...endpoint} />
|
||||
) : (
|
||||
<SidebarLink key={`item-${index}`} {...endpoint} />
|
||||
)
|
||||
),
|
||||
[]
|
||||
() => endpoints
|
||||
?.filter(({ sidebar = false }) => sidebar)
|
||||
?.map((endpoint, index) =>
|
||||
endpoint.routes ? (
|
||||
<SidebarCollapseItem key={`item-${index}`} {...endpoint} />
|
||||
) : (
|
||||
<SidebarLink key={`item-${index}`} {...endpoint} />
|
||||
)
|
||||
),
|
||||
[endpoints]
|
||||
)
|
||||
|
||||
return (
|
||||
@@ -87,7 +86,7 @@ const Sidebar = memo(({ endpoints }) => {
|
||||
</Box>
|
||||
</Drawer>
|
||||
)
|
||||
}, (prev, next) => prev.endpoints.length === next.endpoints.length)
|
||||
}
|
||||
|
||||
Sidebar.propTypes = {
|
||||
endpoints: PropTypes.array
|
||||
|
||||
@@ -8,7 +8,7 @@ import { yupResolver } from '@hookform/resolvers'
|
||||
import FormStepper from 'client/components/FormStepper'
|
||||
import Steps from 'client/containers/ApplicationsTemplates/Form/Create/Steps'
|
||||
|
||||
import { PATH } from 'client/apps/sunstone/routes-flow'
|
||||
import { PATH } from 'client/apps/sunstone/routesFlow'
|
||||
import { useFetch } from 'client/hooks'
|
||||
import { useApplicationTemplateApi } from 'client/features/One'
|
||||
import { parseApplicationToForm, parseFormToApplication } from 'client/utils'
|
||||
|
||||
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
import { Container, Box } from '@material-ui/core'
|
||||
|
||||
import { PATH } from 'client/apps/sunstone/routes-flow'
|
||||
import { PATH } from 'client/apps/sunstone/routesFlow'
|
||||
import { useFetch } from 'client/hooks'
|
||||
import { useApplicationTemplate, useApplicationTemplateApi } from 'client/features/One'
|
||||
|
||||
|
||||
@@ -20,80 +20,57 @@ import { Redirect, Route, Switch } from 'react-router-dom'
|
||||
import { TransitionGroup } from 'react-transition-group'
|
||||
import { LinearProgress } from '@material-ui/core'
|
||||
|
||||
import devRoutes from 'client/router/dev'
|
||||
import commonRoutes from 'client/router/common'
|
||||
import {
|
||||
PATH as COMMON_PATH,
|
||||
ENDPOINTS as COMMON_ENDPOINTS
|
||||
} from 'client/router/common'
|
||||
|
||||
import { ProtectedRoute, NoAuthRoute } from 'client/components/Route'
|
||||
import { InternalLayout } from 'client/components/HOC'
|
||||
import Sidebar from 'client/components/Sidebar'
|
||||
import Notifier from 'client/components/Notifier'
|
||||
import { isDevelopment } from 'client/utils'
|
||||
|
||||
const Router = ({ isLogged, routes }) => {
|
||||
const ENDPOINTS = React.useMemo(() => [
|
||||
...routes.ENDPOINTS,
|
||||
...(isDevelopment() ? devRoutes.ENDPOINTS : [])
|
||||
], [])
|
||||
const renderRoute = ({ Component, ...rest }, index) => (
|
||||
<ProtectedRoute key={index} exact {...rest}>
|
||||
<InternalLayout>
|
||||
<Component fallback={<LinearProgress color='secondary' />} />
|
||||
</InternalLayout>
|
||||
</ProtectedRoute>
|
||||
)
|
||||
|
||||
const renderRoute = React.useCallback(
|
||||
({ Component, ...rest }, index) => (
|
||||
<ProtectedRoute key={index} exact {...rest}>
|
||||
<InternalLayout>
|
||||
<Component fallback={<LinearProgress color='secondary' />} />
|
||||
</InternalLayout>
|
||||
</ProtectedRoute>
|
||||
), [])
|
||||
|
||||
return (
|
||||
<>
|
||||
{isLogged && (
|
||||
<>
|
||||
<Sidebar endpoints={ENDPOINTS} />
|
||||
<Notifier />
|
||||
</>
|
||||
const Router = ({ redirectWhenAuth, endpoints }) => (
|
||||
<TransitionGroup>
|
||||
<Switch>
|
||||
{endpoints?.map(({ routes: subRoutes, ...rest }, index) =>
|
||||
Array.isArray(subRoutes)
|
||||
? subRoutes?.map(renderRoute)
|
||||
: renderRoute(rest, index)
|
||||
)}
|
||||
<TransitionGroup>
|
||||
<Switch>
|
||||
{ENDPOINTS?.map(({ routes: subRoutes, ...rest }, index) =>
|
||||
Array.isArray(subRoutes)
|
||||
? subRoutes?.map(renderRoute)
|
||||
: renderRoute(rest, index)
|
||||
)}
|
||||
{commonRoutes.ENDPOINTS?.map(({ Component, ...rest }, index) =>
|
||||
<NoAuthRoute key={index} exact {...rest}>
|
||||
<Component />
|
||||
</NoAuthRoute>
|
||||
)}
|
||||
<Route component={() => <Redirect to={commonRoutes.PATH.LOGIN} />} />
|
||||
</Switch>
|
||||
</TransitionGroup>
|
||||
</>
|
||||
{COMMON_ENDPOINTS?.map(({ Component, ...rest }, index) =>
|
||||
<NoAuthRoute key={index} exact redirectWhenAuth={redirectWhenAuth} {...rest}>
|
||||
<Component />
|
||||
</NoAuthRoute>
|
||||
)}
|
||||
<Route component={() => <Redirect to={COMMON_PATH.LOGIN} />} />
|
||||
</Switch>
|
||||
</TransitionGroup>
|
||||
)
|
||||
|
||||
Router.propTypes = {
|
||||
redirectWhenAuth: PropTypes.string,
|
||||
endpoints: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
Component: PropTypes.object,
|
||||
icon: PropTypes.object,
|
||||
label: PropTypes.string.isRequired,
|
||||
path: PropTypes.string,
|
||||
sidebar: PropTypes.bool,
|
||||
routes: PropTypes.array
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
Router.propTypes = {
|
||||
isLogged: PropTypes.bool,
|
||||
routes: PropTypes.shape({
|
||||
PATH: PropTypes.object,
|
||||
ENDPOINTS: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
Component: PropTypes.object,
|
||||
icon: PropTypes.object,
|
||||
label: PropTypes.string.isRequired,
|
||||
path: PropTypes.string,
|
||||
sidebar: PropTypes.bool,
|
||||
routes: PropTypes.array
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Router.defaultProps = {
|
||||
isLogged: false,
|
||||
routes: {
|
||||
PATH: {},
|
||||
ENDPOINTS: []
|
||||
}
|
||||
redirectWhenAuth: '/dashboard',
|
||||
endpoints: []
|
||||
}
|
||||
|
||||
Router.displayName = 'Router'
|
||||
|
||||
Reference in new issue
Block a user