1import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
2import { RouteDescriptor } from 'app/core/navigation/types';
3import { isGrafanaAdmin } from './permissions';
4import { PluginAdminRoutes } from './types';
5
6const DEFAULT_ROUTES = [
7  {
8    path: '/plugins',
9    routeName: PluginAdminRoutes.Home,
10    component: SafeDynamicImport(() => import(/* webpackChunkName: "PluginListPage" */ './pages/Browse')),
11  },
12  {
13    path: '/plugins/browse',
14    routeName: PluginAdminRoutes.Browse,
15    component: SafeDynamicImport(() => import(/* webpackChunkName: "PluginListPage" */ './pages/Browse')),
16  },
17  {
18    path: '/plugins/:pluginId/',
19    routeName: PluginAdminRoutes.Details,
20    component: SafeDynamicImport(() => import(/* webpackChunkName: "PluginPage" */ './pages/PluginDetails')),
21  },
22];
23
24const ADMIN_ROUTES = [
25  {
26    path: '/admin/plugins',
27    routeName: PluginAdminRoutes.HomeAdmin,
28    component: SafeDynamicImport(() => import(/* webpackChunkName: "PluginListPage" */ './pages/Browse')),
29  },
30  {
31    path: '/admin/plugins/browse',
32    routeName: PluginAdminRoutes.BrowseAdmin,
33    component: SafeDynamicImport(() => import(/* webpackChunkName: "PluginListPage" */ './pages/Browse')),
34  },
35  {
36    path: '/admin/plugins/:pluginId/',
37    routeName: PluginAdminRoutes.DetailsAdmin,
38    component: SafeDynamicImport(() => import(/* webpackChunkName: "PluginPage" */ './pages/PluginDetails')),
39  },
40];
41
42export function getRoutes(): RouteDescriptor[] {
43  if (isGrafanaAdmin()) {
44    return [...DEFAULT_ROUTES, ...ADMIN_ROUTES];
45  }
46
47  return DEFAULT_ROUTES;
48}
49