From b50e7229485421780df141ad41e97b7b3967aad5 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sun, 12 Jun 2022 13:33:25 -0400 Subject: [PATCH] Add account related routes to router file --- resources/scripts/components/App.tsx | 6 +-- resources/scripts/routers/DashboardRouter.tsx | 35 +++++++-------- resources/scripts/routers/routes.ts | 44 +++++++++++++++++-- 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/resources/scripts/components/App.tsx b/resources/scripts/components/App.tsx index 47dbcdbab..1e638f30c 100644 --- a/resources/scripts/components/App.tsx +++ b/resources/scripts/components/App.tsx @@ -15,9 +15,9 @@ import { ServerContext } from '@/state/server'; import '@/assets/tailwind.css'; import Spinner from '@/components/elements/Spinner'; -const DashboardRouter = lazy(() => import(/* webpackChunkName: "dash" */'@/routers/DashboardRouter')); -const ServerRouter = lazy(() => import('@/routers/ServerRouter')); -const AuthenticationRouter = lazy(() => import('@/routers/AuthenticationRouter')); +const DashboardRouter = lazy(() => import(/* webpackChunkName: "dashboard" */'@/routers/DashboardRouter')); +const ServerRouter = lazy(() => import(/* webpackChunkName: "server" */'@/routers/ServerRouter')); +const AuthenticationRouter = lazy(() => import(/* webpackChunkName: "auth" */'@/routers/AuthenticationRouter')); interface ExtendedWindow extends Window { SiteConfiguration?: SiteSettings; diff --git a/resources/scripts/routers/DashboardRouter.tsx b/resources/scripts/routers/DashboardRouter.tsx index bb760fed3..6acc33567 100644 --- a/resources/scripts/routers/DashboardRouter.tsx +++ b/resources/scripts/routers/DashboardRouter.tsx @@ -1,16 +1,13 @@ import React from 'react'; import { NavLink, Route, Switch } from 'react-router-dom'; -import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer'; import NavigationBar from '@/components/NavigationBar'; import DashboardContainer from '@/components/dashboard/DashboardContainer'; -import AccountApiContainer from '@/components/dashboard/AccountApiContainer'; import { NotFound } from '@/components/elements/ScreenBlock'; import TransitionRouter from '@/TransitionRouter'; import SubNavigation from '@/components/elements/SubNavigation'; -import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer'; import { useLocation } from 'react-router'; -import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer'; import Spinner from '@/components/elements/Spinner'; +import routes from '@/routers/routes'; export default () => { const location = useLocation(); @@ -21,10 +18,15 @@ export default () => { {location.pathname.startsWith('/account') &&
- Settings - API Credentials - SSH Keys - Activity + {routes.account.filter((route) => !!route.name).map(({ path, name, exact = false }) => ( + + {name} + + ))}
} @@ -34,18 +36,11 @@ export default () => { - - - - - - - - - - - - + {routes.account.map(({ path, component: Component }) => ( + + + + ))} diff --git a/resources/scripts/routers/routes.ts b/resources/scripts/routers/routes.ts index e840604eb..51c6997c7 100644 --- a/resources/scripts/routers/routes.ts +++ b/resources/scripts/routers/routes.ts @@ -8,27 +8,63 @@ import NetworkContainer from '@/components/server/network/NetworkContainer'; import StartupContainer from '@/components/server/startup/StartupContainer'; import FileManagerContainer from '@/components/server/files/FileManagerContainer'; import SettingsContainer from '@/components/server/settings/SettingsContainer'; +import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer'; +import AccountApiContainer from '@/components/dashboard/AccountApiContainer'; +import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer'; +import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer'; +// Each of the router files is already code split out appropriately — so +// all of the items above will only be loaded in when that router is loaded. +// +// These specific lazy loaded routes are to avoid loading in heavy screens +// for the server dashboard when they're only needed for specific instances. const FileEditContainer = lazy(() => import('@/components/server/files/FileEditContainer')); const ScheduleEditContainer = lazy(() => import('@/components/server/schedules/ScheduleEditContainer')); -interface ServerRouteDefinition { +interface RouteDefinition { path: string; - permission: string | string[] | null; // If undefined is passed this route is still rendered into the router itself // but no navigation link is displayed in the sub-navigation menu. name: string | undefined; component: React.ComponentType; - // The default for "exact" is assumed to be "true" unless you explicitly - // pass it as false. exact?: boolean; } +interface ServerRouteDefinition extends RouteDefinition { + permission: string | string[] | null; +} + interface Routes { + // All of the routes available under "/account" + account: RouteDefinition[]; + // All of the routes available under "/server/:id" server: ServerRouteDefinition[]; } export default { + account: [ + { + path: '/', + name: 'Account', + component: AccountOverviewContainer, + exact: true, + }, + { + path: '/api', + name: 'API Credentials', + component: AccountApiContainer, + }, + { + path: '/ssh', + name: 'SSH Keys', + component: AccountSSHContainer, + }, + { + path: '/activity', + name: 'Activity', + component: ActivityLogContainer, + }, + ], server: [ { path: '/',