@ -1,10 +1,9 @@
import { Action , KBarProvider } from 'kbar' ;
import { Component , ComponentType } from 'react' ;
import { Provider } from 'react-redux' ;
import { Switch , RouteComponentProps } from 'react-router-dom' ;
import { CompatRoute , Navigate } from 'react-router-dom-v5-compat' ;
import { Route , Routes } from 'react-router-dom-v5-compat' ;
import { config , locationService , navigationLogger , reportInteraction } from '@grafana/runtime' ;
import { config , navigationLogger , reportInteraction } from '@grafana/runtime' ;
import { ErrorBoundaryAlert , GlobalStyles , PortalContainer } from '@grafana/ui' ;
import { getAppRoutes } from 'app/routes/routes' ;
import { store } from 'app/store/store' ;
@ -13,10 +12,9 @@ import { loadAndInitAngularIfEnabled } from './angular/loadAndInitAngularIfEnabl
import { GrafanaApp } from './app' ;
import { GrafanaContext } from './core/context/GrafanaContext' ;
import { SidecarContext } from './core/context/SidecarContext' ;
import { GrafanaRoute } from './core/navigation/GrafanaRoute' ;
import { GrafanaRouteWrapper } from './core/navigation/GrafanaRoute' ;
import { RouteDescriptor } from './core/navigation/types' ;
import { sidecarService } from './core/services/SidecarService' ;
import { contextSrv } from './core/services/context_srv' ;
import { ThemeProvider } from './core/utils/ConfigProvider' ;
import { LiveConnectionWarning } from './features/live/LiveConnectionWarning' ;
import { ExtensionRegistriesProvider } from './features/plugins/extensions/ExtensionRegistriesContext' ;
@ -55,30 +53,18 @@ export class AppWrapper extends Component<AppWrapperProps, AppWrapperState> {
}
renderRoute = ( route : RouteDescriptor ) = > {
const roles = route . roles ? route . roles ( ) : [ ] ;
return (
< CompatRoute
exact = { route . exact === undefined ? true : route . exact }
sensitive = { route . sensitive === undefined ? false : route . sensitive }
< Route
caseSensitive = { route . sensitive === undefined ? false : route . sensitive }
path = { route . path }
key = { route . path }
render = { ( props : RouteComponentProps ) = > {
const location = locationService . getLocation ( ) ;
// TODO[Router]: test this logic
if ( roles ? . length ) {
if ( ! roles . some ( ( r : string ) = > contextSrv . hasRole ( r ) ) ) {
return < Navigate replace to = "/" / > ;
}
}
return < GrafanaRoute { ...props } route = { route } location = { location } / > ;
} }
element = { < GrafanaRouteWrapper route = { route } / > }
/ >
) ;
} ;
renderRoutes() {
return < Switch > { getAppRoutes ( ) . map ( ( r ) = > this . renderRoute ( r ) ) } < / Switch > ;
return < Routes > { getAppRoutes ( ) . map ( ( r ) = > this . renderRoute ( r ) ) } < / Routes > ;
}
render() {