forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it easier for plugins to extend the navigation and add routes
- Loading branch information
1 parent
88a7bd7
commit 04e97cc
Showing
5 changed files
with
198 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { Route } from 'react-router-dom'; | ||
import { RouteProps } from 'react-router'; | ||
import Can from '@/components/elements/Can'; | ||
import { ServerError } from '@/components/elements/ScreenBlock'; | ||
|
||
interface Props extends Omit<RouteProps, 'path'> { | ||
path: string; | ||
permission: string | string[] | null; | ||
} | ||
|
||
export default ({ permission, children, ...props }: Props) => ( | ||
<Route {...props}> | ||
{!permission ? | ||
children | ||
: | ||
<Can | ||
action={permission} | ||
renderOnError={ | ||
<ServerError | ||
title={'Access Denied'} | ||
message={'You do not have permission to access this page.'} | ||
/> | ||
} | ||
> | ||
{children} | ||
</Can> | ||
} | ||
</Route> | ||
); |
33 changes: 33 additions & 0 deletions
33
resources/scripts/components/server/ConflictStateRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { ServerContext } from '@/state/server'; | ||
import ScreenBlock from '@/components/elements/ScreenBlock'; | ||
import ServerInstallSvg from '@/assets/images/server_installing.svg'; | ||
import ServerErrorSvg from '@/assets/images/server_error.svg'; | ||
import ServerRestoreSvg from '@/assets/images/server_restore.svg'; | ||
|
||
export default () => { | ||
const status = ServerContext.useStoreState(state => state.server.data?.status || null); | ||
const isTransferring = ServerContext.useStoreState(state => state.server.data?.isTransferring || false); | ||
|
||
return ( | ||
status === 'installing' || status === 'install_failed' ? | ||
<ScreenBlock | ||
title={'Running Installer'} | ||
image={ServerInstallSvg} | ||
message={'Your server should be ready soon, please try again in a few minutes.'} | ||
/> | ||
: | ||
status === 'suspended' ? | ||
<ScreenBlock | ||
title={'Server Suspended'} | ||
image={ServerErrorSvg} | ||
message={'This server is suspended and cannot be accessed.'} | ||
/> | ||
: | ||
<ScreenBlock | ||
title={isTransferring ? 'Transferring' : 'Restoring from Backup'} | ||
image={ServerRestoreSvg} | ||
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.'} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { lazy } from 'react'; | ||
import ServerConsole from '@/components/server/ServerConsole'; | ||
import DatabasesContainer from '@/components/server/databases/DatabasesContainer'; | ||
import ScheduleContainer from '@/components/server/schedules/ScheduleContainer'; | ||
import UsersContainer from '@/components/server/users/UsersContainer'; | ||
import BackupContainer from '@/components/server/backups/BackupContainer'; | ||
import NetworkContainer from '@/components/server/network/NetworkContainer'; | ||
import StartupContainer from '@/components/server/startup/StartupContainer'; | ||
|
||
const FileManagerContainer = lazy(() => import('@/components/server/files/FileManagerContainer')); | ||
const FileEditContainer = lazy(() => import('@/components/server/files/FileEditContainer')); | ||
const ScheduleEditContainer = lazy(() => import('@/components/server/schedules/ScheduleEditContainer')); | ||
const SettingsContainer = lazy(() => import('@/components/server/settings/SettingsContainer')); | ||
|
||
interface ServerRouteDefinition { | ||
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 Routes { | ||
server: ServerRouteDefinition[]; | ||
} | ||
|
||
export default { | ||
server: [ | ||
{ | ||
path: '/', | ||
permission: null, | ||
name: 'Console', | ||
component: ServerConsole, | ||
exact: true, | ||
}, | ||
{ | ||
path: '/files', | ||
permission: 'file.*', | ||
name: 'Files', | ||
component: FileManagerContainer, | ||
}, | ||
{ | ||
path: '/files/:action(edit|new)', | ||
permission: 'file.*', | ||
name: undefined, | ||
component: FileEditContainer, | ||
}, | ||
{ | ||
path: '/databases', | ||
permission: 'database.*', | ||
name: 'Databases', | ||
component: DatabasesContainer, | ||
}, | ||
{ | ||
path: '/schedules', | ||
permission: 'schedule.*', | ||
name: 'Schedules', | ||
component: ScheduleContainer, | ||
}, | ||
{ | ||
path: '/schedules/:id', | ||
permission: 'schedule.*', | ||
name: undefined, | ||
component: ScheduleEditContainer, | ||
}, | ||
{ | ||
path: '/users', | ||
permission: 'user.*', | ||
name: 'Users', | ||
component: UsersContainer, | ||
}, | ||
{ | ||
path: '/backups', | ||
permission: 'backup.*', | ||
name: 'Backups', | ||
component: BackupContainer, | ||
}, | ||
{ | ||
path: '/network', | ||
permission: 'allocation.*', | ||
name: 'Network', | ||
component: NetworkContainer, | ||
}, | ||
{ | ||
path: '/startup', | ||
permission: 'startup.*', | ||
name: 'Startup', | ||
component: StartupContainer, | ||
}, | ||
{ | ||
path: '/settings', | ||
permission: [ 'settings.*', 'file.sftp' ], | ||
name: 'Settings', | ||
component: SettingsContainer, | ||
}, | ||
], | ||
} as Routes; |