@@ -2,63 +2,24 @@ import TransferListener from '@/components/server/TransferListener';
22import React , { useEffect , useState } from 'react' ;
33import { NavLink , Route , Switch , useRouteMatch } from 'react-router-dom' ;
44import NavigationBar from '@/components/NavigationBar' ;
5- import ServerConsole from '@/components/server/ServerConsole' ;
65import TransitionRouter from '@/TransitionRouter' ;
76import WebsocketHandler from '@/components/server/WebsocketHandler' ;
87import { ServerContext } from '@/state/server' ;
9- import DatabasesContainer from '@/components/server/databases/DatabasesContainer' ;
10- import FileManagerContainer from '@/components/server/files/FileManagerContainer' ;
118import { CSSTransition } from 'react-transition-group' ;
12- import FileEditContainer from '@/components/server/files/FileEditContainer' ;
13- import SettingsContainer from '@/components/server/settings/SettingsContainer' ;
14- import ScheduleContainer from '@/components/server/schedules/ScheduleContainer' ;
15- import ScheduleEditContainer from '@/components/server/schedules/ScheduleEditContainer' ;
16- import UsersContainer from '@/components/server/users/UsersContainer' ;
179import Can from '@/components/elements/Can' ;
18- import BackupContainer from '@/components/server/backups/BackupContainer' ;
1910import Spinner from '@/components/elements/Spinner' ;
20- import ScreenBlock , { NotFound , ServerError } from '@/components/elements/ScreenBlock' ;
11+ import { NotFound , ServerError } from '@/components/elements/ScreenBlock' ;
2112import { httpErrorToHuman } from '@/api/http' ;
2213import { useStoreState } from 'easy-peasy' ;
2314import SubNavigation from '@/components/elements/SubNavigation' ;
24- import NetworkContainer from '@/components/server/network/NetworkContainer' ;
2515import InstallListener from '@/components/server/InstallListener' ;
26- import StartupContainer from '@/components/server/startup/StartupContainer' ;
2716import ErrorBoundary from '@/components/elements/ErrorBoundary' ;
2817import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
2918import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons' ;
30- import RequireServerPermission from '@/hoc/RequireServerPermission' ;
31- import ServerInstallSvg from '@/assets/images/server_installing.svg' ;
32- import ServerRestoreSvg from '@/assets/images/server_restore.svg' ;
33- import ServerErrorSvg from '@/assets/images/server_error.svg' ;
3419import { useLocation } from 'react-router' ;
35-
36- const ConflictStateRenderer = ( ) => {
37- const status = ServerContext . useStoreState ( state => state . server . data ?. status || null ) ;
38- const isTransferring = ServerContext . useStoreState ( state => state . server . data ?. isTransferring || false ) ;
39-
40- return (
41- status === 'installing' || status === 'install_failed' ?
42- < ScreenBlock
43- title = { 'Running Installer' }
44- image = { ServerInstallSvg }
45- message = { 'Your server should be ready soon, please try again in a few minutes.' }
46- />
47- :
48- status === 'suspended' ?
49- < ScreenBlock
50- title = { 'Server Suspended' }
51- image = { ServerErrorSvg }
52- message = { 'This server is suspended and cannot be accessed.' }
53- />
54- :
55- < ScreenBlock
56- title = { isTransferring ? 'Transferring' : 'Restoring from Backup' }
57- image = { ServerRestoreSvg }
58- message = { isTransferring ? 'Your server is being transfered to a new node, please check back later.' : 'Your server is currently being restored from a backup, please check back in a few minutes.' }
59- />
60- ) ;
61- } ;
20+ import ConflictStateRenderer from '@/components/server/ConflictStateRenderer' ;
21+ import PermissionRoute from '@/components/elements/PermissionRoute' ;
22+ import routes from '@/routers/routes' ;
6223
6324export default ( ) => {
6425 const match = useRouteMatch < { id : string } > ( ) ;
@@ -74,6 +35,10 @@ export default () => {
7435 const getServer = ServerContext . useStoreActions ( actions => actions . server . getServer ) ;
7536 const clearServerState = ServerContext . useStoreActions ( actions => actions . clearServerState ) ;
7637
38+ const to = ( value : string , url = false ) => {
39+ return `${ ( url ? match . url : match . path ) . replace ( / \/ * $ / , '' ) } /${ value . replace ( / ^ \/ + / , '' ) } ` ;
40+ } ;
41+
7742 useEffect ( ( ) => ( ) => {
7843 clearServerState ( ) ;
7944 } , [ ] ) ;
@@ -105,35 +70,23 @@ export default () => {
10570 < CSSTransition timeout = { 150 } classNames = { 'fade' } appear in >
10671 < SubNavigation >
10772 < div >
108- < NavLink to = { `${ match . url } ` } exact > Console</ NavLink >
109- < Can action = { 'file.*' } >
110- < NavLink to = { `${ match . url } /files` } > File Manager</ NavLink >
111- </ Can >
112- < Can action = { 'database.*' } >
113- < NavLink to = { `${ match . url } /databases` } > Databases</ NavLink >
114- </ Can >
115- < Can action = { 'schedule.*' } >
116- < NavLink to = { `${ match . url } /schedules` } > Schedules</ NavLink >
117- </ Can >
118- < Can action = { 'user.*' } >
119- < NavLink to = { `${ match . url } /users` } > Users</ NavLink >
120- </ Can >
121- < Can action = { 'backup.*' } >
122- < NavLink to = { `${ match . url } /backups` } > Backups</ NavLink >
123- </ Can >
124- < Can action = { 'allocation.*' } >
125- < NavLink to = { `${ match . url } /network` } > Network</ NavLink >
126- </ Can >
127- < Can action = { 'startup.*' } >
128- < NavLink to = { `${ match . url } /startup` } > Startup</ NavLink >
129- </ Can >
130- < Can action = { [ 'settings.*' , 'file.sftp' ] } matchAny >
131- < NavLink to = { `${ match . url } /settings` } > Settings</ NavLink >
132- </ Can >
73+ { routes . server . filter ( route => ! ! route . name ) . map ( ( route ) => (
74+ route . permission ?
75+ < Can key = { route . path } action = { route . permission } matchAny >
76+ < NavLink to = { to ( route . path , true ) } exact = { route . exact } >
77+ { route . name }
78+ </ NavLink >
79+ </ Can >
80+ :
81+ < NavLink key = { route . path } to = { to ( route . path , true ) } exact = { route . exact } >
82+ { route . name }
83+ </ NavLink >
84+ ) ) }
13385 { rootAdmin &&
134- < a href = { '/admin/servers/view/' + serverId } rel = "noreferrer" target = { '_blank' } >
135- < FontAwesomeIcon icon = { faExternalLinkAlt } />
136- </ a >
86+ // eslint-disable-next-line react/jsx-no-target-blank
87+ < a href = { `/admin/servers/view/${ serverId } ` } target = { '_blank' } >
88+ < FontAwesomeIcon icon = { faExternalLinkAlt } />
89+ </ a >
13790 }
13891 </ div >
13992 </ SubNavigation >
@@ -147,47 +100,13 @@ export default () => {
147100 < ErrorBoundary >
148101 < TransitionRouter >
149102 < Switch location = { location } >
150- < Route path = { `${ match . path } ` } component = { ServerConsole } exact />
151- < Route path = { `${ match . path } /files` } exact >
152- < RequireServerPermission permissions = { 'file.*' } >
153- < FileManagerContainer />
154- </ RequireServerPermission >
155- </ Route >
156- < Route path = { `${ match . path } /files/:action(edit|new)` } exact >
157- < Spinner . Suspense >
158- < FileEditContainer />
159- </ Spinner . Suspense >
160- </ Route >
161- < Route path = { `${ match . path } /databases` } exact >
162- < RequireServerPermission permissions = { 'database.*' } >
163- < DatabasesContainer />
164- </ RequireServerPermission >
165- </ Route >
166- < Route path = { `${ match . path } /schedules` } exact >
167- < RequireServerPermission permissions = { 'schedule.*' } >
168- < ScheduleContainer />
169- </ RequireServerPermission >
170- </ Route >
171- < Route path = { `${ match . path } /schedules/:id` } exact >
172- < ScheduleEditContainer />
173- </ Route >
174- < Route path = { `${ match . path } /users` } exact >
175- < RequireServerPermission permissions = { 'user.*' } >
176- < UsersContainer />
177- </ RequireServerPermission >
178- </ Route >
179- < Route path = { `${ match . path } /backups` } exact >
180- < RequireServerPermission permissions = { 'backup.*' } >
181- < BackupContainer />
182- </ RequireServerPermission >
183- </ Route >
184- < Route path = { `${ match . path } /network` } exact >
185- < RequireServerPermission permissions = { 'allocation.*' } >
186- < NetworkContainer />
187- </ RequireServerPermission >
188- </ Route >
189- < Route path = { `${ match . path } /startup` } component = { StartupContainer } exact />
190- < Route path = { `${ match . path } /settings` } component = { SettingsContainer } exact />
103+ { routes . server . map ( ( { path, permission, component : Component } ) => (
104+ < PermissionRoute key = { path } permission = { permission } path = { to ( path ) } exact >
105+ < Spinner . Suspense >
106+ < Component />
107+ </ Spinner . Suspense >
108+ </ PermissionRoute >
109+ ) ) }
191110 < Route path = { '*' } component = { NotFound } />
192111 </ Switch >
193112 </ TransitionRouter >
0 commit comments