Skip to content

Commit b50e722

Browse files
committed
Add account related routes to router file
1 parent 7197d28 commit b50e722

File tree

3 files changed

+58
-27
lines changed

3 files changed

+58
-27
lines changed

resources/scripts/components/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { ServerContext } from '@/state/server';
1515
import '@/assets/tailwind.css';
1616
import Spinner from '@/components/elements/Spinner';
1717

18-
const DashboardRouter = lazy(() => import(/* webpackChunkName: "dash" */'@/routers/DashboardRouter'));
19-
const ServerRouter = lazy(() => import('@/routers/ServerRouter'));
20-
const AuthenticationRouter = lazy(() => import('@/routers/AuthenticationRouter'));
18+
const DashboardRouter = lazy(() => import(/* webpackChunkName: "dashboard" */'@/routers/DashboardRouter'));
19+
const ServerRouter = lazy(() => import(/* webpackChunkName: "server" */'@/routers/ServerRouter'));
20+
const AuthenticationRouter = lazy(() => import(/* webpackChunkName: "auth" */'@/routers/AuthenticationRouter'));
2121

2222
interface ExtendedWindow extends Window {
2323
SiteConfiguration?: SiteSettings;

resources/scripts/routers/DashboardRouter.tsx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import React from 'react';
22
import { NavLink, Route, Switch } from 'react-router-dom';
3-
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
43
import NavigationBar from '@/components/NavigationBar';
54
import DashboardContainer from '@/components/dashboard/DashboardContainer';
6-
import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
75
import { NotFound } from '@/components/elements/ScreenBlock';
86
import TransitionRouter from '@/TransitionRouter';
97
import SubNavigation from '@/components/elements/SubNavigation';
10-
import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer';
118
import { useLocation } from 'react-router';
12-
import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer';
139
import Spinner from '@/components/elements/Spinner';
10+
import routes from '@/routers/routes';
1411

1512
export default () => {
1613
const location = useLocation();
@@ -21,10 +18,15 @@ export default () => {
2118
{location.pathname.startsWith('/account') &&
2219
<SubNavigation>
2320
<div>
24-
<NavLink to={'/account'} exact>Settings</NavLink>
25-
<NavLink to={'/account/api'}>API Credentials</NavLink>
26-
<NavLink to={'/account/ssh'}>SSH Keys</NavLink>
27-
<NavLink to={'/account/activity'}>Activity</NavLink>
21+
{routes.account.filter((route) => !!route.name).map(({ path, name, exact = false }) => (
22+
<NavLink
23+
key={path}
24+
to={`/account/${path}`.replace('//', '/')}
25+
exact={exact}
26+
>
27+
{name}
28+
</NavLink>
29+
))}
2830
</div>
2931
</SubNavigation>
3032
}
@@ -34,18 +36,11 @@ export default () => {
3436
<Route path={'/'} exact>
3537
<DashboardContainer/>
3638
</Route>
37-
<Route path={'/account'} exact>
38-
<AccountOverviewContainer/>
39-
</Route>
40-
<Route path={'/account/api'} exact>
41-
<AccountApiContainer/>
42-
</Route>
43-
<Route path={'/account/ssh'} exact>
44-
<AccountSSHContainer/>
45-
</Route>
46-
<Route path={'/account/activity'} exact>
47-
<ActivityLogContainer/>
48-
</Route>
39+
{routes.account.map(({ path, component: Component }) => (
40+
<Route key={path} path={`/account/${path}`.replace('//', '/')} exact>
41+
<Component/>
42+
</Route>
43+
))}
4944
<Route path={'*'}>
5045
<NotFound/>
5146
</Route>

resources/scripts/routers/routes.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,63 @@ import NetworkContainer from '@/components/server/network/NetworkContainer';
88
import StartupContainer from '@/components/server/startup/StartupContainer';
99
import FileManagerContainer from '@/components/server/files/FileManagerContainer';
1010
import SettingsContainer from '@/components/server/settings/SettingsContainer';
11+
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
12+
import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
13+
import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer';
14+
import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer';
1115

16+
// Each of the router files is already code split out appropriately — so
17+
// all of the items above will only be loaded in when that router is loaded.
18+
//
19+
// These specific lazy loaded routes are to avoid loading in heavy screens
20+
// for the server dashboard when they're only needed for specific instances.
1221
const FileEditContainer = lazy(() => import('@/components/server/files/FileEditContainer'));
1322
const ScheduleEditContainer = lazy(() => import('@/components/server/schedules/ScheduleEditContainer'));
1423

15-
interface ServerRouteDefinition {
24+
interface RouteDefinition {
1625
path: string;
17-
permission: string | string[] | null;
1826
// If undefined is passed this route is still rendered into the router itself
1927
// but no navigation link is displayed in the sub-navigation menu.
2028
name: string | undefined;
2129
component: React.ComponentType;
22-
// The default for "exact" is assumed to be "true" unless you explicitly
23-
// pass it as false.
2430
exact?: boolean;
2531
}
2632

33+
interface ServerRouteDefinition extends RouteDefinition {
34+
permission: string | string[] | null;
35+
}
36+
2737
interface Routes {
38+
// All of the routes available under "/account"
39+
account: RouteDefinition[];
40+
// All of the routes available under "/server/:id"
2841
server: ServerRouteDefinition[];
2942
}
3043

3144
export default {
45+
account: [
46+
{
47+
path: '/',
48+
name: 'Account',
49+
component: AccountOverviewContainer,
50+
exact: true,
51+
},
52+
{
53+
path: '/api',
54+
name: 'API Credentials',
55+
component: AccountApiContainer,
56+
},
57+
{
58+
path: '/ssh',
59+
name: 'SSH Keys',
60+
component: AccountSSHContainer,
61+
},
62+
{
63+
path: '/activity',
64+
name: 'Activity',
65+
component: ActivityLogContainer,
66+
},
67+
],
3268
server: [
3369
{
3470
path: '/',

0 commit comments

Comments
 (0)